From 3b07d4055a75dfb275faae08314efda6d3b02338 Mon Sep 17 00:00:00 2001 From: NuclearW Date: Fri, 22 Feb 2013 11:59:56 -0500 Subject: [PATCH] Added config option to make .new config files instead over writing over old ones when updating --- Changelog.txt | 2 ++ src/main/java/com/gmail/nossr50/config/Config.java | 1 + src/main/java/com/gmail/nossr50/config/ConfigLoader.java | 8 +++++++- src/main/resources/config.yml | 2 ++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Changelog.txt b/Changelog.txt index 9e5884526..1ceacadca 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -36,6 +36,8 @@ Version 1.4.00-dev + Added config option to disable automatic zip backups. + Added particle effects for many abilities. + Added '/mcnotify' command to toggle ability notifications on/off + + Added ability for config files to automatically update with new keys, and prune out old ones + + Added config option to make .new config files instead over writing over old ones when updating = Fixed Green Thumb on wheat not working properly at rank 4 = Fixed Green Thumb and Green Terra consuming twice the amount of seed needed = Fixed Green Terra not also checking Green Thumb permissions diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index a0b3f9bae..3a03bbbe6 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -44,6 +44,7 @@ public class Config extends ConfigLoader { public boolean getEventCallbackEnabled() { return config.getBoolean("General.Event_Callback", true); } public boolean getBackupsEnabled() { return config.getBoolean("General.Generate_Backups", true); } public boolean getVerboseLoggingEnabled() { return config.getBoolean("General.Verbose_Logging", false); } + public boolean getConfigOverwriteEnabled() { return config.getBoolean("General.Config_Update_Overwrite", true); } public boolean getPartyDisplayNames() { return config.getBoolean("Commands.p.Use_Display_Names", true); } public boolean getAdminDisplayNames() { return config.getBoolean("Commands.a.Use_Display_Names", true); } diff --git a/src/main/java/com/gmail/nossr50/config/ConfigLoader.java b/src/main/java/com/gmail/nossr50/config/ConfigLoader.java index fa6dcacde..f5d18a530 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigLoader.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigLoader.java @@ -121,7 +121,13 @@ public abstract class ConfigLoader { // Save it try { - BufferedWriter writer = new BufferedWriter(new FileWriter(new File(plugin.getDataFolder(), fileName))); + String saveName = fileName; + // At this stage we cannot guarantee that Config has been loaded, so we do the check directly here + if (!plugin.getConfig().getBoolean("General.Config_Update_Overwrite", true)) { + saveName += ".new"; + } + + BufferedWriter writer = new BufferedWriter(new FileWriter(new File(plugin.getDataFolder(), saveName))); writer.write(output); writer.flush(); writer.close(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 4047ad80c..0979873dd 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -24,6 +24,8 @@ General: Power_Level_Cap: 0 #Should mcMMO print out debug messages? Verbose_Logging: false + #Should mcMMO over-write configs to update, or make new ones ending in .new? + Config_Update_Overwrite: true Database_Purging: #Amount of time (in hours) to wait between database purging