Getting value from configfile

Discussion in 'Plugin Development' started by se1by, Nov 2, 2011.

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

    se1by

    I need a value of my configfile in my listener, but I can't make a new method in the main and call it (static - non static).
    How else can I get the value?
     
  2. Offline

    Windwaker

    Me personally, I like to create getters and setters for each property and just keep my config in my main class

    Ex.
    Code:java
    1. public FileConfiguration config; // declare config
    Code:java
    1. public void loadConfig(){
    2. config = getConfig(); // get config
    3. config.addDefault("example", true); // create our defaults
    4. config.options().copyDefaults(true); // copy 'em
    5. }
    Code:java
    1. public boolean getExample(){ // method for getting config value
    2. boolean ex = config.getBoolean("example"); // get the boolean of this path, in this case, it is true
    3. return ex; // return the example value
    Then if I want to access it externally in a different class:
    Code:java
    1. public static MyPlugin plugin; // declare your plugin as a static field
    Code:java
    1. plugin.getExample(); // returns true in this case

    Just how I do it, just ask if you have any questions :)
     
Thread Status:
Not open for further replies.

Share This Page