mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
config updater for 13
This commit is contained in:
@@ -120,7 +120,7 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
*/
|
*/
|
||||||
public final NamespacedKey originType = new NamespacedKey(this, "origin");
|
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 Logger logger = this.getLogger();
|
||||||
public final File configFile = new File(this.getDataFolder(), "config.yml");
|
public final File configFile = new File(this.getDataFolder(), "config.yml");
|
||||||
public boolean tokens = false;
|
public boolean tokens = false;
|
||||||
|
|||||||
@@ -31,40 +31,15 @@ public class ConfigUpdater {
|
|||||||
public void updateConfig() {
|
public void updateConfig() {
|
||||||
int version = toolStats.config.getInt("config-version");
|
int version = toolStats.config.getInt("config-version");
|
||||||
|
|
||||||
// Version 5 to 6
|
switch (version) {
|
||||||
if (version == 5) {
|
case 5 -> new Version6(toolStats).update(); // 5 to 6
|
||||||
Version6 version6 = new Version6(toolStats);
|
case 6 -> new Version7(toolStats).update(); // 6 to 7
|
||||||
version6.update();
|
case 7 -> new Version8(toolStats).update(); // 7 to 8
|
||||||
}
|
case 8 -> new Version9(toolStats).update(); // 8 to 9
|
||||||
// Version 6 to 7
|
case 9 -> new Version10(toolStats).update(); // 9 to 10
|
||||||
if (version == 6) {
|
case 10 -> new Version11(toolStats).update(); // 10 to 11
|
||||||
Version7 version7 = new Version7(toolStats);
|
case 11 -> new Version12(toolStats).update(); // 11 to 12
|
||||||
version7.update();
|
case 12 -> new Version13(toolStats).update(); // 12 to 13
|
||||||
}
|
|
||||||
// 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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -346,4 +346,4 @@ normalize-time-creation: false
|
|||||||
# Allows stats and origins to be tracked if the player is in creative mode.
|
# Allows stats and origins to be tracked if the player is in creative mode.
|
||||||
allow-creative: false
|
allow-creative: false
|
||||||
|
|
||||||
config-version: 12
|
config-version: 13
|
||||||
Reference in New Issue
Block a user