From d5545de81f1e48bc64a019a4e1cc8b86c6f58c6e Mon Sep 17 00:00:00 2001 From: GJ Date: Mon, 7 Oct 2013 13:04:36 -0400 Subject: [PATCH] Backup & replace the repair config files that have been updated. --- .../gmail/nossr50/config/ConfigLoader.java | 2 +- .../skills/repair/config/RepairConfig.java | 20 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/config/ConfigLoader.java b/src/main/java/com/gmail/nossr50/config/ConfigLoader.java index 2e8b0c804..cf2b14006 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigLoader.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigLoader.java @@ -11,7 +11,7 @@ import com.gmail.nossr50.mcMMO; public abstract class ConfigLoader { protected static final mcMMO plugin = mcMMO.p; protected String fileName; - private File configFile; + protected File configFile; protected FileConfiguration config; public ConfigLoader(String relativePath, String fileName) { diff --git a/src/main/java/com/gmail/nossr50/skills/repair/config/RepairConfig.java b/src/main/java/com/gmail/nossr50/skills/repair/config/RepairConfig.java index f278393f8..d8da917e6 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/config/RepairConfig.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/config/RepairConfig.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.skills.repair.config; +import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -33,9 +34,7 @@ public class RepairConfig extends ConfigLoader { for (String key : keys) { if (config.contains("Repairables." + key + ".ItemId")) { - plugin.getLogger().warning("You are using an old version of the " + fileName + " file."); - plugin.getLogger().warning("You should delete your current file and allow a new one to generate."); - plugin.getLogger().warning("Repair will not work properly until you do."); + backup(); return; } @@ -162,4 +161,19 @@ public class RepairConfig extends ConfigLoader { return issues.isEmpty(); } + + private void backup() { + plugin.getLogger().warning("You are using an old version of the " + fileName + " file."); + plugin.getLogger().warning("Your old file has been renamed to " + fileName + ".old and has been replaced by an updated version."); + + configFile.renameTo(new File(configFile.getPath() + ".old")); + + if (plugin.getResource(fileName) != null) { + plugin.saveResource(fileName, true); + } + + plugin.getLogger().warning("Reloading " + fileName + " with new values..."); + loadFile(); + loadKeys(); + } }