Skip to content

Commit 6d1f0fe

Browse files
committed
update config from 6 to 7
1 parent fb0d179 commit 6d1f0fe

File tree

4 files changed

+83
-2
lines changed

4 files changed

+83
-2
lines changed

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

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

116-
public final int CONFIG_VERSION = 6;
116+
public final int CONFIG_VERSION = 7;
117117
public final Logger logger = this.getLogger();
118118
public final File configFile = new File(this.getDataFolder(), "config.yml");
119119

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import lol.hyper.toolstats.ToolStats;
3838
import lol.hyper.toolstats.tools.config.versions.Version6;
39+
import lol.hyper.toolstats.tools.config.versions.Version7;
3940

4041
public class ConfigUpdater {
4142

@@ -49,9 +50,16 @@ public void updateConfig() {
4950
int version = toolStats.config.getInt("config-version");
5051

5152
// this will be a switch in the future
53+
// Upgrade 5 to 6
5254
if (version == 5) {
5355
Version6 version6 = new Version6(toolStats);
5456
version6.update();
5557
}
58+
59+
// Upgrade 6 to 7
60+
if (version == 6) {
61+
Version7 version7 = new Version7(toolStats);
62+
version7.update();
63+
}
5664
}
5765
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
22+
import java.io.File;
23+
import java.io.IOException;
24+
import java.util.ArrayList;
25+
import java.util.Collections;
26+
import java.util.List;
27+
28+
public class Version7 {
29+
30+
private final ToolStats toolStats;
31+
32+
/**
33+
* Used for updating from version 6 to 7.
34+
*
35+
* @param toolStats ToolStats instance.
36+
*/
37+
public Version7(ToolStats toolStats) {
38+
this.toolStats = toolStats;
39+
}
40+
41+
/**
42+
* Perform the config update.
43+
*/
44+
public void update() {
45+
// save the old config first
46+
try {
47+
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-6.yml");
48+
} catch (IOException exception) {
49+
toolStats.logger.severe("Unable to save config-5.yml!");
50+
throw new RuntimeException(exception);
51+
}
52+
53+
// we make this super verbose so that admins can see what's being added
54+
toolStats.logger.info("Updating config.yml to version 7.");
55+
toolStats.config.set("config-version", 7);
56+
57+
toolStats.logger.info("Adding messages.flight-time to config.yml.");
58+
toolStats.config.set("messages.flight-time", "&7Flight time: &8{time}");
59+
60+
toolStats.logger.info("Adding enabled.flight-time to config.yml.");
61+
toolStats.config.set("enabled.flight-time", true);
62+
63+
// save the config and reload it
64+
try {
65+
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
66+
} catch (IOException exception) {
67+
toolStats.logger.severe("Unable to save config.yml!");
68+
throw new RuntimeException(exception);
69+
}
70+
toolStats.loadConfig();
71+
toolStats.logger.info("Config has been updated to version 7. A copy of version 5 has been saved as config-6.yml");
72+
}
73+
}

src/main/resources/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ number-formats:
136136
# This has no use currently, but can be used for future features for dupe detection.
137137
generate-hash-for-items: true
138138

139-
config-version: 6
139+
config-version: 7

0 commit comments

Comments
 (0)