From 62dcdb5d4b9a88992a995c4f0d40246d9b60abaa Mon Sep 17 00:00:00 2001 From: gravitylow Date: Thu, 16 Jan 2014 22:32:40 -0500 Subject: [PATCH] Drop old configuration files when upgrading to 2.0 --- .../anticheat/config/Configuration.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/Configuration.java b/src/main/java/net/gravitydevelopment/anticheat/config/Configuration.java index d6760b8..01b5b30 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/config/Configuration.java +++ b/src/main/java/net/gravitydevelopment/anticheat/config/Configuration.java @@ -33,7 +33,9 @@ import net.gravitydevelopment.anticheat.config.providers.Groups; import net.gravitydevelopment.anticheat.config.providers.Levels; import net.gravitydevelopment.anticheat.config.providers.Rules; import net.gravitydevelopment.anticheat.manage.AnticheatManager; +import org.bukkit.configuration.file.YamlConfiguration; +import java.io.File; import java.util.ArrayList; public class Configuration { @@ -52,6 +54,7 @@ public class Configuration { private ArrayList dbfiles; public Configuration(AntiCheat plugin, AnticheatManager manager) { + removeOldFiles(); this.manager = manager; config = new Config(plugin, this); plugin.setVerbose(config.verboseStartup.getValue()); @@ -121,6 +124,26 @@ public class Configuration { } } + private void removeOldFiles() { + ArrayList removed = new ArrayList(); + File configFile = new File(AntiCheat.getPlugin().getDataFolder(), "config.yml"); + if (configFile.exists() && YamlConfiguration.loadConfiguration(configFile).getString("System.Auto update") != null) { + configFile.renameTo(new File(AntiCheat.getPlugin().getDataFolder(), "config.old")); + removed.add("config.yml has been renamed to config.old and replaced with the new config.yml"); + } + File eventsFile = new File(AntiCheat.getPlugin().getDataFolder(), "events.yml"); + if (eventsFile.exists()) { + eventsFile.renameTo(new File(AntiCheat.getPlugin().getDataFolder(), "events.old")); + removed.add("events.yml has been renamed to events.old and replaced with groups.yml and rules.yml"); + } + if (removed.size() > 0) { + AntiCheat.getPlugin().getLogger().info("You are upgrading from an old version of AntiCheat. Due to configuration changes, the following files have been modified:"); + for (String s : removed) { + AntiCheat.getPlugin().getLogger().info(s); + } + } + } + public Config getConfig() { return config; }