I want to do delays/countdowns for each class/job. I created a config and changed some things in it, every server reload/restart resets it to default values.
onEnable():
public void onEnable() {
PluginManager pm = this.getServer().getPluginManager();
pm.addPermission(new Permission("kit." + getConfig().getString("Kits.Names")));
try {
saveConfig();
setupConfig(getConfig());
saveConfig();
} catch (Exception e) {
e.printStackTrace();
}
}
setupConfig():
private void setupConfig(FileConfiguration config) throws IOException {
config.set("Kits.Miner.Items", "274 1, 50 64");
config.set("Kits.Woodcutter.Items", "275 1, 58 1, 4 32");
config.set("Kits.Names", "Miner, Woodcutter");
config.set("Kits.Miner.Delay", 5000);
config.set("Kits.Woodcutter.Delay", 5000);
config.set("np", "You must be a player to execute that command!");
config.set("kg", "You get the");
config.set("ctgtk", "You can't get that kit yet!");
config.set("ugtk", "You got the kit");
config.set("cgtk", "You can get the kit now!");
config.set("udthp", "You don't have permission for this command!");
}
config.yml:
Kits:
Names: Miner, Woodcutter
Miner:
Items: 274 1, 50 64
Delay: 5000
Woodcutter:
Items: 275 1, 58 1, 4 32
Delay: 5000
np: You must be a player to execute that command!
kg: You get the
ctgtk: You can't get that kit yet!
ugtk: You got the kit
cgtk: You can get the kit now!
udthp: You don't have permission for this command!
I'm going to point out what significant things are happening here:
public void onEnable() {
try {
setupConfig(getConfig());
saveConfig();
} catch (Exception e) {
e.printStackTrace();
}
This is all the relevant information, just for clarification, you're taking your config, setting the values to the default and then saving it. Try checking if the config file doesn't exist before saving the default values.