소스 검색

Added config option to make .new config files instead over writing over old ones when updating

NuclearW 12 년 전
부모
커밋
3b07d4055a
4개의 변경된 파일12개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 0
      Changelog.txt
  2. 1 0
      src/main/java/com/gmail/nossr50/config/Config.java
  3. 7 1
      src/main/java/com/gmail/nossr50/config/ConfigLoader.java
  4. 2 0
      src/main/resources/config.yml

+ 2 - 0
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

+ 1 - 0
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); }
 

+ 7 - 1
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();

+ 2 - 0
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