From 3ee53e0cf76f623bbce93245edcc9242fec09544 Mon Sep 17 00:00:00 2001 From: hyperdefined Date: Thu, 15 May 2025 18:44:48 -0400 Subject: [PATCH] config updater for 13 --- .../java/lol/hyper/toolstats/ToolStats.java | 2 +- .../toolstats/tools/config/ConfigUpdater.java | 43 +++-------- .../tools/config/versions/Version13.java | 75 +++++++++++++++++++ src/main/resources/config.yml | 2 +- 4 files changed, 86 insertions(+), 36 deletions(-) create mode 100644 src/main/java/lol/hyper/toolstats/tools/config/versions/Version13.java diff --git a/src/main/java/lol/hyper/toolstats/ToolStats.java b/src/main/java/lol/hyper/toolstats/ToolStats.java index 6630776..4857234 100644 --- a/src/main/java/lol/hyper/toolstats/ToolStats.java +++ b/src/main/java/lol/hyper/toolstats/ToolStats.java @@ -120,7 +120,7 @@ public final class ToolStats extends JavaPlugin { */ public final NamespacedKey originType = new NamespacedKey(this, "origin"); - public final int CONFIG_VERSION = 12; + public final int CONFIG_VERSION = 13; public final Logger logger = this.getLogger(); public final File configFile = new File(this.getDataFolder(), "config.yml"); public boolean tokens = false; diff --git a/src/main/java/lol/hyper/toolstats/tools/config/ConfigUpdater.java b/src/main/java/lol/hyper/toolstats/tools/config/ConfigUpdater.java index f411e90..c15b72b 100644 --- a/src/main/java/lol/hyper/toolstats/tools/config/ConfigUpdater.java +++ b/src/main/java/lol/hyper/toolstats/tools/config/ConfigUpdater.java @@ -31,40 +31,15 @@ public class ConfigUpdater { public void updateConfig() { int version = toolStats.config.getInt("config-version"); - // Version 5 to 6 - if (version == 5) { - Version6 version6 = new Version6(toolStats); - version6.update(); - } - // Version 6 to 7 - if (version == 6) { - Version7 version7 = new Version7(toolStats); - version7.update(); - } - // Version 7 to 8 - if (version == 7) { - Version8 version8 = new Version8(toolStats); - version8.update(); - } - // Version 8 to 9 - if (version == 8) { - Version9 version9 = new Version9(toolStats); - version9.update(); - } - // Version 9 to 10 - if (version == 9) { - Version10 version10 = new Version10(toolStats); - version10.update(); - } - // Version 10 to 11 - if (version == 10) { - Version11 version11 = new Version11(toolStats); - version11.update(); - } - // Version 11 to 12 - if (version == 11) { - Version12 version12 = new Version12(toolStats); - version12.update(); + switch (version) { + case 5 -> new Version6(toolStats).update(); // 5 to 6 + case 6 -> new Version7(toolStats).update(); // 6 to 7 + case 7 -> new Version8(toolStats).update(); // 7 to 8 + case 8 -> new Version9(toolStats).update(); // 8 to 9 + case 9 -> new Version10(toolStats).update(); // 9 to 10 + case 10 -> new Version11(toolStats).update(); // 10 to 11 + case 11 -> new Version12(toolStats).update(); // 11 to 12 + case 12 -> new Version13(toolStats).update(); // 12 to 13 } } } \ No newline at end of file diff --git a/src/main/java/lol/hyper/toolstats/tools/config/versions/Version13.java b/src/main/java/lol/hyper/toolstats/tools/config/versions/Version13.java new file mode 100644 index 0000000..3a8641b --- /dev/null +++ b/src/main/java/lol/hyper/toolstats/tools/config/versions/Version13.java @@ -0,0 +1,75 @@ +/* + * 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 . + */ + +package lol.hyper.toolstats.tools.config.versions; + +import lol.hyper.toolstats.ToolStats; +import org.bukkit.configuration.ConfigurationSection; + +import java.io.File; +import java.io.IOException; + +public class Version13 { + + private final ToolStats toolStats; + + /** + * Used for updating from version 12 to 13. + * + * @param toolStats ToolStats instance. + */ + public Version13(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-12.yml"); + } catch (IOException exception) { + toolStats.logger.severe("Unable to save config-12.yml!"); + throw new RuntimeException(exception); + } + + toolStats.logger.info("Updating config.yml to version 13."); + toolStats.config.set("config-version", 13); + + for (String key : toolStats.config.getConfigurationSection("tokens.data").getKeys(false)) { + toolStats.logger.info("Adding tokens.data." + key + ".material"); + toolStats.config.set("tokens.data." + key + ".material", "PAPER"); + toolStats.logger.info("Adding tokens.data." + key + ".custom-model-data.enabled"); + toolStats.config.set("tokens.data." + key + ".custom-model-data.enabled", false); + toolStats.logger.info("Adding tokens.data." + key + ".custom-model-data.type"); + toolStats.config.set("tokens.data." + key + ".custom-model-data.type", "float"); + toolStats.logger.info("Adding tokens.data." + key + ".custom-model-data.value"); + toolStats.config.set("tokens.data." + key + ".custom-model-data.value", 1001); + } + + // 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 13. A copy of version 12 has been saved as config-12.yml"); + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index a95c13f..deb1580 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -346,4 +346,4 @@ normalize-time-creation: false # Allows stats and origins to be tracked if the player is in creative mode. allow-creative: false -config-version: 12 \ No newline at end of file +config-version: 13 \ No newline at end of file