Loading config through multiple classes

Discussion in 'Plugin Development' started by Garnet638, Apr 21, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Garnet638

    How would I go about making a config file that could be read throughout multiple classes (Each command has it's on .class)
    This was the code I used to load the config (Thats in the onEnable in the main class)
    Code:
            File configFile = new File(this.getDataFolder() + "/config.yml");
            if(!configFile.exists()){
              this.saveDefaultConfig();
            }
    How would I make it to reach the other classes?
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Garnet638 You make it a private field, make a getter method for it in the main plugin, pass the plugin instance in the constructors of the other classes.
     
    CodePlaysMinecraft likes this.
  3. Offline

    Garnet638

    How do I do that?
    (Sorry, I'm a bit new to Java)
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    Protophite

    Bukkit has it's own config getter. To get the config in another class pass in your main class and use getConfig()
    @Garnet638
     
Thread Status:
Not open for further replies.

Share This Page