mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
update config from 6 to 7
This commit is contained in:
@@ -113,7 +113,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 = 6;
|
public final int CONFIG_VERSION = 7;
|
||||||
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");
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ 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.Version6;
|
||||||
|
import lol.hyper.toolstats.tools.config.versions.Version7;
|
||||||
|
|
||||||
public class ConfigUpdater {
|
public class ConfigUpdater {
|
||||||
|
|
||||||
@@ -49,9 +50,16 @@ public class ConfigUpdater {
|
|||||||
int version = toolStats.config.getInt("config-version");
|
int version = toolStats.config.getInt("config-version");
|
||||||
|
|
||||||
// this will be a switch in the future
|
// this will be a switch in the future
|
||||||
|
// Upgrade 5 to 6
|
||||||
if (version == 5) {
|
if (version == 5) {
|
||||||
Version6 version6 = new Version6(toolStats);
|
Version6 version6 = new Version6(toolStats);
|
||||||
version6.update();
|
version6.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Upgrade 6 to 7
|
||||||
|
if (version == 6) {
|
||||||
|
Version7 version7 = new Version7(toolStats);
|
||||||
|
version7.update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Version7 {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for updating from version 6 to 7.
|
||||||
|
*
|
||||||
|
* @param toolStats ToolStats instance.
|
||||||
|
*/
|
||||||
|
public Version7(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-6.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.severe("Unable to save config-5.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 7.");
|
||||||
|
toolStats.config.set("config-version", 7);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding messages.flight-time to config.yml.");
|
||||||
|
toolStats.config.set("messages.flight-time", "&7Flight time: &8{time}");
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding enabled.flight-time to config.yml.");
|
||||||
|
toolStats.config.set("enabled.flight-time", 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 7. A copy of version 5 has been saved as config-6.yml");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -136,4 +136,4 @@ number-formats:
|
|||||||
# This has no use currently, but can be used for future features for dupe detection.
|
# This has no use currently, but can be used for future features for dupe detection.
|
||||||
generate-hash-for-items: true
|
generate-hash-for-items: true
|
||||||
|
|
||||||
config-version: 6
|
config-version: 7
|
||||||
Reference in New Issue
Block a user