Search code examples
javaminecraftbukkit

How can I stop my config from overriding new values?


So i'm a bit new to the Bukkit API, so please don't go too hard on me, with that aside i've been making a plugin where i want the config able to be customized by the admins, but i've run into an issue that no matter what I do, it replaces the new values someone tries to enter into the config, with the defaults.

So here's a list i setup in the default config in the code itself:

PersonalBoosterTypes:
- 5#60
- 2#60
- 3#60
- 5#45
- 2#180
- 3#120
- 2#90

Now if i add a new value in the plugin config not in the code like so:

PersonalBoosterTypes:
- 5#60
- 2#60
- 3#60
- 5#45
- 2#180
- 3#120
- 2#90
- 3#180 // new value

and after that i reload the server, it deletes that value and keeps the defaults. I've put this method in my onEnable:

private void loadConfig() {
    this.getConfig().options().copyDefaults(true);
    this.saveConfig();
}

Is there a other way to load the defaults without overriding or do i have to manually add every default with addDefault()?

Please help! Cheers, Daniel


Solution

  • After some researching i've actually found the solution by myself and it's suprisingly simple, all i had to do is in my onDisable method, I've just needed to add these two lines:

    this.reloadConfig();
    this.saveConfig();
    

    I was suprised at first, but it works as a charm, Hopefully this helps others to find this solution to the problem