Solved Dynamic Plugin Configuration - Setting defaults in code

Discussion in 'Plugin Development' started by RROD, Mar 22, 2013.

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

    RROD

    Hi,

    This feels like a bit of a nooby question, but anyway...
    I'm writing a plugin which depends on other settings from another plugin. What I'm trying to do is get values from the other plugin's config (done this fine) and use them in my plugin's config.yml.

    The problem I'm having is getting it to generate the defaults dynamically using code, not those set out inside the config.yml. Using the API for addDefault() and saveDefaultConfig() doesn't seem to put this configuration information into a newly generated file (inside the plugin's folder on a server) - it just takes what is in the config.yml and doesn't attach these. The way I used to do it worked, now it doesn't? :/

    Any ideas?
    Here's a copy of the method which manages this.
    Code:java
    1. protected static FileConfiguration CONFIG;
    2.  
    3. public void onEnable() {
    4. CONFIG = this.getConfig();
    5. }
    6.  
    7.  
    8. private void addDefaults() {
    9. for (Group g : MANAGER.getGroups()) { //getGroups() returns an array of Group instances
    10. CONFIG.addDefault("rank-settings." + g.getName() + ".time-to-next-rank", 1L); //getName() returns a String
    11. // 1L - Testing config generation
    12. }
    13. CONFIG.options().copyDefaults(true);
    14. saveDefaultConfig();
    15. }
     
  2. Offline

    stuntguy3000

    Personally i have never used the addDefault,

    Try .set
    and then saveConfig();
     
  3. Offline

    RROD

    Well short answer, no. This will set them every time I load the plugin. The purpose of defaults is that it sets them if the config.yml doesn't exist in the plugin's folder.

    Edit: Solved it by using only saveConfig(), no set().
     
Thread Status:
Not open for further replies.

Share This Page