New configurations help...

Discussion in 'Plugin Development' started by stelar7, Oct 12, 2011.

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

    stelar7

    so I want to change my plugin to use the new configurations, but it does not work how i want it...

    here is the code:
    Code:java
    1. public class ClosedDoors extends JavaPlugin {
    2. FileConfiguration config;
    3.  
    4. public void onEnable() {
    5. try {
    6. config = getConfig();
    7. config.options().header("Change the values to suit you best");
    8. config.get("storm.radius", 20);
    9. config.get("storm.repeat", 20);
    10. config.get("login.show.motd", true);
    11. config.get("login.show.rules", true);
    12. config.get("login.show.help", true);
    13. saveConfig();
    14. } catch (Exception e1) {
    15. e1.printStackTrace();
    16. }
    17. }
    18. }
    this code creates a file like this:
    Code:
    # Change the values to suit you best
    how do i get the rest of it?
     
  2. Offline

    snikkers

    Code:
    if(!config.contains("storm.radius")){
        config.set("storm.radius", 20);
    }
    
    and then if you need it config.getint("storm.radius")
     
  3. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    I think he means "How do I do this in a way that doesn't require a billion if() statements." :p
     
  4. Offline

    stelar7

    Yeah :p
    With the old you just used config.getint("storm.radius", 20); and there it was...
    maybe @Dinnerbone knows how?
    But it's fine if there is just a few like i had :p
     
  5. Offline

    Sagacious_Zed Bukkit Docs

    You mean like providing default values?
     
  6. Offline

    snikkers

    yeah i dont know why this does not work anymore, cause you can still provide default
    it is just not written to the config -_-

    and btw - i just recognised the adddefault(....) and options().copydefaults(true)
    perhaps it works with copydefaults true ?
     
  7. Offline

    TehRandomGuy

    Just tried and if you do config.options().copyDefaults(true); and use addDefault(whatever the arguments are); and then saveConfig(); it will work and only will set if its not there.
     
  8. Offline

    thehutch

    I figured it out kinda I just do this and it prints it out onto the config in thos order for once.
    Code:
        public void configSetup() {
    
        try {
            config = getConfig();
            config.set("String here", " default here ");
    
            config.set("String here ", " default here");
            saveConfig();
        }
         catch (Exception ex) {
            ex.printStackTrace();
        }
    
        }
     
Thread Status:
Not open for further replies.

Share This Page