Saving Custom Configs

Discussion in 'Plugin Development' started by MnMaxon, Aug 17, 2012.

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

    MnMaxon

    I have a method for saving my custom config, but I don't think it works because when I tried to change some, I couldn't see the change not save. Could someone please look at my method and tell me what's wrong with it?

    Code:
    public void saveConfig(File customConfigFile) {
        customConfig = YamlConfiguration.loadConfiguration(customConfigFile);
        if (customConfig == null || customConfigFile == null) {
            Bukkit.getServer().broadcastMessage("Null");
        } else {
            Bukkit.getServer().broadcastMessage("Not Null");
            try {
                customConfig.save(customConfigFile);
            } catch (IOException ex) {
                plugin.getLogger().log(Level.SEVERE,
                        "Could not save config to " + customConfigFile, ex);
            }
        }
    }
    Thanks
     
  2. Offline

    sd5

    MnMaxon likes this.
  3. Offline

    rjVapes

    Code:
    customConfig = YamlConfiguration.loadConfiguration(customConfigFile);
    customConfig shouldn't be defined inside the saveConfig function. It should be stored in the class that contains saveConfig, and that member variable should be used. No changes you're making outside this function will take effect because you're loading up a config, then instantly saving that new instance out to disk.
     
    MnMaxon likes this.
  4. Offline

    MnMaxon

    Thanks, It works now.

    I'm not really sure, I was trying to make it so it worked for multiple configs instead of it only working for one config, so I tried to copy the code from reloadCustomConfig() and I messed up.
     
Thread Status:
Not open for further replies.

Share This Page