/**
* Update configuration files, if needed.
* @param simpleSpleef
*/
public void updateConfigurationVersion(SimpleSpleef simpleSpleef) {
Configuration config = SimpleSpleef.getPlugin().getConfig();
// check version number in config file
int version = config.getInt("version", 1);
// changed?
boolean changed = false;
// update stuff
if (version <= 1) {
config.set("allowDiggingOutsideArena", null); // delete obsolete setting allowDiggingOutsideArena
changed = true;
}
if (version <= 2) {
//update loose => lose
if (config.contains("announceLoose")) {
config.set("announceLose", config.getBoolean("announceLoose", true));
config.set("announceLoose", null);
}
ConfigHelper configHelper = new ConfigHelper();
// for each arena
for (String arena : config.getConfigurationSection("arenas").getKeys(false)) {
ConfigurationSection myConfig = config.getConfigurationSection("arenas." + arena);
if (myConfig.contains("looseOnTouchBlocks")) {
myConfig.set("loseOnTouchBlocks", myConfig.getBoolean("looseOnTouchBlocks", true));
myConfig.set("looseOnTouchBlocks", null);
}
if (myConfig.contains("looseBlocks")) {
if (myConfig.isList("looseBlocks"))
myConfig.set("loseBlocks", myConfig.getStringList("looseBlocks"));
else myConfig.set("loseBlocks", myConfig.get("looseBlocks"));
myConfig.set("looseBlocks", null);
}
if (myConfig.contains("looseOnDeath")) {
myConfig.set("loseOnDeath", myConfig.getBoolean("looseOnDeath", true));
myConfig.set("looseOnDeath", null);
}
if (myConfig.contains("looseOnLogout")) {
myConfig.set("loseOnLogout", myConfig.getBoolean("looseOnLogout", true));
myConfig.set("looseOnLogout", null);
}
if (myConfig.contains("playersLooseShovelAtGameEnd")) {
myConfig.set("playersLoseShovelAtGameEnd", myConfig.getBoolean("playersLooseShovelAtGameEnd", true));
myConfig.set("playersLooseShovelAtGameEnd", null);
}
if (myConfig.contains("loose") && myConfig.isConfigurationSection("loose")) {
// copy loose to lose
ConfigurationSection newSection = myConfig.createSection("lose");
configHelper.copySection(newSection, myConfig.getConfigurationSection("loose"));
myConfig.set("loose", null); // delete old section
}
if (myConfig.contains("looseSpawn") && myConfig.isConfigurationSection("looseSpawn")) {
// copy looseSpawn to loseSpawn
ConfigurationSection newSection = myConfig.createSection("loseSpawn");
configHelper.copySection(newSection, myConfig.getConfigurationSection("looseSpawn"));
myConfig.set("looseSpawn", null); // delete old section
}
}
changed = true;
}
// add new update versions here
// increase version number
if (changed) {
SimpleSpleef.log.info("[SimpleSpleef] Updating configuration from version " + version + " to version 3.");
config.set("version", 3);
SimpleSpleef.getPlugin().saveConfig();
}
}