Skip to content

Commit 3ee53e0

Browse files
committed
config updater for 13
1 parent 364859b commit 3ee53e0

File tree

4 files changed

+86
-36
lines changed

4 files changed

+86
-36
lines changed

src/main/java/lol/hyper/toolstats/ToolStats.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public final class ToolStats extends JavaPlugin {
120120
*/
121121
public final NamespacedKey originType = new NamespacedKey(this, "origin");
122122

123-
public final int CONFIG_VERSION = 12;
123+
public final int CONFIG_VERSION = 13;
124124
public final Logger logger = this.getLogger();
125125
public final File configFile = new File(this.getDataFolder(), "config.yml");
126126
public boolean tokens = false;

src/main/java/lol/hyper/toolstats/tools/config/ConfigUpdater.java

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,40 +31,15 @@ public ConfigUpdater(ToolStats toolStats) {
3131
public void updateConfig() {
3232
int version = toolStats.config.getInt("config-version");
3333

34-
// Version 5 to 6
35-
if (version == 5) {
36-
Version6 version6 = new Version6(toolStats);
37-
version6.update();
38-
}
39-
// Version 6 to 7
40-
if (version == 6) {
41-
Version7 version7 = new Version7(toolStats);
42-
version7.update();
43-
}
44-
// Version 7 to 8
45-
if (version == 7) {
46-
Version8 version8 = new Version8(toolStats);
47-
version8.update();
48-
}
49-
// Version 8 to 9
50-
if (version == 8) {
51-
Version9 version9 = new Version9(toolStats);
52-
version9.update();
53-
}
54-
// Version 9 to 10
55-
if (version == 9) {
56-
Version10 version10 = new Version10(toolStats);
57-
version10.update();
58-
}
59-
// Version 10 to 11
60-
if (version == 10) {
61-
Version11 version11 = new Version11(toolStats);
62-
version11.update();
63-
}
64-
// Version 11 to 12
65-
if (version == 11) {
66-
Version12 version12 = new Version12(toolStats);
67-
version12.update();
34+
switch (version) {
35+
case 5 -> new Version6(toolStats).update(); // 5 to 6
36+
case 6 -> new Version7(toolStats).update(); // 6 to 7
37+
case 7 -> new Version8(toolStats).update(); // 7 to 8
38+
case 8 -> new Version9(toolStats).update(); // 8 to 9
39+
case 9 -> new Version10(toolStats).update(); // 9 to 10
40+
case 10 -> new Version11(toolStats).update(); // 10 to 11
41+
case 11 -> new Version12(toolStats).update(); // 11 to 12
42+
case 12 -> new Version13(toolStats).update(); // 12 to 13
6843
}
6944
}
7045
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* This file is part of ToolStats.
3+
*
4+
* ToolStats is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* ToolStats is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package lol.hyper.toolstats.tools.config.versions;
19+
20+
import lol.hyper.toolstats.ToolStats;
21+
import org.bukkit.configuration.ConfigurationSection;
22+
23+
import java.io.File;
24+
import java.io.IOException;
25+
26+
public class Version13 {
27+
28+
private final ToolStats toolStats;
29+
30+
/**
31+
* Used for updating from version 12 to 13.
32+
*
33+
* @param toolStats ToolStats instance.
34+
*/
35+
public Version13(ToolStats toolStats) {
36+
this.toolStats = toolStats;
37+
}
38+
39+
/**
40+
* Perform the config update.
41+
*/
42+
public void update() {
43+
// save the old config first
44+
try {
45+
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-12.yml");
46+
} catch (IOException exception) {
47+
toolStats.logger.severe("Unable to save config-12.yml!");
48+
throw new RuntimeException(exception);
49+
}
50+
51+
toolStats.logger.info("Updating config.yml to version 13.");
52+
toolStats.config.set("config-version", 13);
53+
54+
for (String key : toolStats.config.getConfigurationSection("tokens.data").getKeys(false)) {
55+
toolStats.logger.info("Adding tokens.data." + key + ".material");
56+
toolStats.config.set("tokens.data." + key + ".material", "PAPER");
57+
toolStats.logger.info("Adding tokens.data." + key + ".custom-model-data.enabled");
58+
toolStats.config.set("tokens.data." + key + ".custom-model-data.enabled", false);
59+
toolStats.logger.info("Adding tokens.data." + key + ".custom-model-data.type");
60+
toolStats.config.set("tokens.data." + key + ".custom-model-data.type", "float");
61+
toolStats.logger.info("Adding tokens.data." + key + ".custom-model-data.value");
62+
toolStats.config.set("tokens.data." + key + ".custom-model-data.value", 1001);
63+
}
64+
65+
// save the config and reload it
66+
try {
67+
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
68+
} catch (IOException exception) {
69+
toolStats.logger.severe("Unable to save config.yml!");
70+
throw new RuntimeException(exception);
71+
}
72+
toolStats.loadConfig();
73+
toolStats.logger.info("Config has been updated to version 13. A copy of version 12 has been saved as config-12.yml");
74+
}
75+
}

src/main/resources/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,4 @@ normalize-time-creation: false
346346
# Allows stats and origins to be tracked if the player is in creative mode.
347347
allow-creative: false
348348

349-
config-version: 12
349+
config-version: 13

0 commit comments

Comments
 (0)