Bukkit Standard Config Help :S

Discussion in 'Plugin Development' started by NeoSilky, Oct 1, 2011.

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

    NeoSilky

    okay, so i am not at home, but thought i'd write this question so i can look when i am home.

    My plugin creates a config with properties that i set in the onenable, such as config.setProperty("blahhh", true); or profiles.setProperty("online", true); (both being two different yml files) but i have a couple of problems:
    1. When i stop and start the server, it resets the properties to their defaults that is caused by the next problem: in general, how can i use config.save(); okay and save without the restore??
    2. I try to add certain details to the profile.yml using the normal: profile.setProperty(player.getDisplayName + ".online", true); it unfortunately save and therefore overrides most of the code in the config, which is the wrong file entirely.

    It is my first plugin using the standard bukkit yml, so im kinda confused :p If anyone wants to see code, i can give it tomorrow, but if anyone can provide an answer, i can write an example of the current code from my head.

    Also, after the JavaPlugin crap, i put protected static Configuration config/profiles, then i wrote the dir paths, then used the file making config thing from the huge plugin tutorial, and then set defaults.

    If you read this far, well done, but please help, maybe @codename_B ? :D
     
  2. Offline

    DirtyStarfish

    If you use setProperty in onEnable then its always going to set it to that.
    You need to get the information.
    So if you had:
    Code:
    boolean enable;
    
    onEnable {
    
    enable = config.setProperty("enable", true);
    }
    It will always set that property to true on enabling the plugin.

    Whereas if you used:
    Code:
    boolean enable;
    
    onEnable {
    enable = getBoolean("enable", true);
    }
    It would set enable to whatever it is set to in the config, if its not there then it will default to what you put in onEnable. (I think).
     
  3. Offline

    NeoSilky

    What about it writing in the wrong file? :S
     
  4. Offline

    DirtyStarfish

    I haven't needed to create more than one file yet, so I can't really answer that... Hopefully someone more experienced will answer, I would also like to know how to manage more than one file. Maybe look at the source's of some plugins that you know use more than one file.
     
  5. Offline

    ZerothAngel

    @NeoSilky @DirtyStarfish

    Code:
    Configuration otherconfig = new Configuration(new File(getDataFolder(), "myotherconfig.yml"));
    otherconfig.load();
    
    // read/set properties in otherconfig using setProperty(), getBoolean(), getString(), etc.
    
    otherconfig.save();
    
     
  6. Offline

    NeoSilky

    what do i do about defining it up at the top. Such as the config is: protected static Configuration config; but the other file i am making is not a Configuration, or does that not matter?

    okay, whats wrong with this code?

    Code:
        (new File(plugindir)).mkdir();
        (new File(plugindirpro)).mkdir();
    
        if (!new File(plugindir, "config.yml").exists()) {
            Configuration config = getConfiguration();
            config.setHeader("#OPTIONS");
            config.getBoolean("makeProfile", true);
            config.getBoolean("closeProfile", true);
            config.save();
            this.logger.info("[SocialCrafting] SocialCrafting Config has been created!");
        } else {
            this.logger.info("[SocialCrafting] SocialCrafting Config is loaded!");
        }
    
        if (!new File(plugindirpro, "profiles.yml").exists()) {
            Configuration profiles = getConfiguration();
            profiles.setHeader("#Player Profiles and Details List Here:");
            profiles.save();
            this.logger.info("[SocialCrafting] SocialCrafting Profiles has been created!");
        } else {
            this.logger.info("[SocialCrafting] SocialCrafting Profiles is loaded!");
        }
    It doesnt write the second .yml but writes all the headers for the profiles.yml into the config.yml :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  7. Offline

    ZerothAngel

    @NeoSilky

    The 2nd line in this needs to be changed:
    Code:
        if (!new File(plugindirpro, "profiles.yml").exists()) {
            Configuration profiles = getConfiguration();
    
    to
    Code:
            Configuration profiles = new Configuration(new File(plugindirpro, "profiles.yml"));
    
    The thing to remember is that getConfiguration() will always return the config object for your "config.yml", so if you want other files, you have to explicitly create the Configuration object.
     
  8. Offline

    NeoSilky

    I literally love you now.... :D:D:D
     
Thread Status:
Not open for further replies.

Share This Page