How make a default config ?

Discussion in 'Plugin Development' started by 4z3rty, Jul 8, 2012.

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

    4z3rty

    Hi,
    I can't create a default config !
    How make it ?

    Escuse me for my spelling, I'm french !
     
  2. Offline

    one4me

    Place this in onEnable
    Code:
    if(!(new File(this.getDataFolder(), "config.yml")).exists()) {
      saveDefaultConfig();
    }
    
    And make sure the config.yml is in the root of your jar when you export.
     
    4z3rty likes this.
  3. Offline

    4z3rty

    Thank
     
  4. Offline

    sayaad

    I never do that xD
    I do
    Code:java
    1. config.set(path, config.get(path, default value));
    2. config.save(configFile);
     
  5. 4z3rty
    saveDefaultConfig() will copy the config.yml from inside the jar as it is... if you don't have it and/or don't want that, you can use:
    Code:
    getConfig().addDefault("node.stuff", "default value");
    getConfig().addDefault("node.anothernode", "default value");
    //...etc
    getConfig().options().saveDefaults(true);
    saveConfig();
    That will create a config.yml with the default values and it will add new values to an existing config if you add them afterwards.
    But will overwrite any custom file format (comments and stuff)... you can only define a header comment if you want, see in the options() method, it's around there :p
    I suggest you read: http://wiki.bukkit.org/Introduction_to_the_New_Configuration


    sayaad
    Well, that'll overwrite stuff if not checked properly, so you could use addDefault()... but then you can't add comments before each node :}

    one4me
    saveDefaultConfig() already checks for the file, you don't have to :p
     
  6. Offline

    one4me

    I threw that part in there so it won't print a warning if it already exists.
     
  7. Offline

    one4me

  8. Ah yes it does for the latest recommended, but as the link shows, it won't in the next RB :}
     
Thread Status:
Not open for further replies.

Share This Page