mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-08 13:44:59 +00:00
make config updater better
This commit is contained in:
@@ -18,10 +18,7 @@
|
|||||||
package lol.hyper.toolstats.tools.config;
|
package lol.hyper.toolstats.tools.config;
|
||||||
|
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.config.versions.Version6;
|
import lol.hyper.toolstats.tools.config.versions.*;
|
||||||
import lol.hyper.toolstats.tools.config.versions.Version7;
|
|
||||||
import lol.hyper.toolstats.tools.config.versions.Version8;
|
|
||||||
import lol.hyper.toolstats.tools.config.versions.Version9;
|
|
||||||
|
|
||||||
public class ConfigUpdater {
|
public class ConfigUpdater {
|
||||||
|
|
||||||
@@ -34,31 +31,30 @@ public class ConfigUpdater {
|
|||||||
public void updateConfig() {
|
public void updateConfig() {
|
||||||
int version = toolStats.config.getInt("config-version");
|
int version = toolStats.config.getInt("config-version");
|
||||||
|
|
||||||
switch(version) {
|
// Version 5 to 6
|
||||||
case 5: {
|
if (version == 5) {
|
||||||
// Version 5 to 6
|
Version6 version6 = new Version6(toolStats);
|
||||||
Version6 version6 = new Version6(toolStats);
|
version6.update();
|
||||||
version6.update();
|
}
|
||||||
break;
|
// Version 6 to 7
|
||||||
}
|
if (version == 6) {
|
||||||
case 6: {
|
Version7 version7 = new Version7(toolStats);
|
||||||
// Version 6 to 7
|
version7.update();
|
||||||
Version7 version7 = new Version7(toolStats);
|
}
|
||||||
version7.update();
|
// Version 7 to 8
|
||||||
break;
|
if (version == 7) {
|
||||||
}
|
Version8 version8 = new Version8(toolStats);
|
||||||
case 7: {
|
version8.update();
|
||||||
// Version 7 to 8
|
}
|
||||||
Version8 version8 = new Version8(toolStats);
|
// Version 8 to 9
|
||||||
version8.update();
|
if (version == 8) {
|
||||||
break;
|
Version9 version9 = new Version9(toolStats);
|
||||||
}
|
version9.update();
|
||||||
case 8: {
|
}
|
||||||
// Version 8 to 9
|
// Version 9 to 10
|
||||||
Version9 version9 = new Version9(toolStats);
|
if (version == 9) {
|
||||||
version9.update();
|
Version10 version10 = new Version10(toolStats);
|
||||||
break;
|
version10.update();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ToolStats.
|
||||||
|
*
|
||||||
|
* ToolStats is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ToolStats is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package lol.hyper.toolstats.tools.config.versions;
|
||||||
|
|
||||||
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class Version10 {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for updating from version 9 to 10.
|
||||||
|
*
|
||||||
|
* @param toolStats ToolStats instance.
|
||||||
|
*/
|
||||||
|
public Version10(ToolStats toolStats) {
|
||||||
|
this.toolStats = toolStats;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform the config update.
|
||||||
|
*/
|
||||||
|
public void update() {
|
||||||
|
// save the old config first
|
||||||
|
try {
|
||||||
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-9.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.severe("Unable to save config-9.yml!");
|
||||||
|
throw new RuntimeException(exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
// we make this super verbose so that admins can see what's being added
|
||||||
|
toolStats.logger.info("Updating config.yml to version 10.");
|
||||||
|
toolStats.config.set("config-version", 10);
|
||||||
|
|
||||||
|
// Add missing values I forgot...
|
||||||
|
toolStats.logger.info("Adding entry for enabled.created-by.fishing-rod");
|
||||||
|
toolStats.config.set("enabled.created-by.fishing-rod", true);
|
||||||
|
toolStats.logger.info("Adding entry for enabled.created-date.fishing-rod");
|
||||||
|
toolStats.config.set("enabled.created-date.fishing-rod", true);
|
||||||
|
toolStats.logger.info("Adding entry for enabled.fished-tag.fishing-rod");
|
||||||
|
toolStats.config.set("enabled.fished-tag.fishing-rod", true);
|
||||||
|
toolStats.logger.info("Adding entry for enabled.looted-tag.fishing-rod");
|
||||||
|
toolStats.config.set("enabled.looted-tag.fishing-rod", true);
|
||||||
|
toolStats.logger.info("Adding entry for enabled.traded-tag.fishing-rod");
|
||||||
|
toolStats.config.set("enabled.traded-tag.fishing-rod", true);
|
||||||
|
toolStats.logger.info("Adding entry for enabled.spawned-in.fishing-rod");
|
||||||
|
toolStats.config.set("enabled.spawned-in.fishing-rod", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding entry for enabled.crops-harvested");
|
||||||
|
toolStats.config.set("enabled.crops-harvested", true);
|
||||||
|
|
||||||
|
// save the config and reload it
|
||||||
|
try {
|
||||||
|
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.severe("Unable to save config.yml!");
|
||||||
|
throw new RuntimeException(exception);
|
||||||
|
}
|
||||||
|
toolStats.loadConfig();
|
||||||
|
toolStats.logger.info("Config has been updated to version 10. A copy of version 9 has been saved as config-9.yml");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user