From 001b11efc691ecab8e2c289279e2affda849670b Mon Sep 17 00:00:00 2001 From: t00thpick1 Date: Fri, 11 Mar 2016 21:54:57 -0500 Subject: [PATCH] Better Auto-Update config loader, still cannot handle multiple options with the exact same name and spacing, but will not break configs anymore in those situations, just mis-comment. --- .../nossr50/config/AutoUpdateConfigLoader.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/config/AutoUpdateConfigLoader.java b/src/main/java/com/gmail/nossr50/config/AutoUpdateConfigLoader.java index 424bf3faf..bf95cb291 100644 --- a/src/main/java/com/gmail/nossr50/config/AutoUpdateConfigLoader.java +++ b/src/main/java/com/gmail/nossr50/config/AutoUpdateConfigLoader.java @@ -64,6 +64,9 @@ public abstract class AutoUpdateConfigLoader extends ConfigLoader { while (output.replaceAll("[//s]", "").startsWith("#")) { output = output.substring(output.indexOf('\n', output.indexOf('#')) + 1); } + + String[] keys = output.split("\n"); + // Read the internal config to get comments, then put them in the new one try { @@ -86,11 +89,15 @@ public abstract class AutoUpdateConfigLoader extends ConfigLoader { } } + output = ""; // Dump to the new one - for (String key : comments.keySet()) { - if (output.contains(key)) { - output = output.substring(0, output.indexOf(key)) + comments.get(key) + output.substring(output.indexOf(key)); + for (String key : keys) { + String comment = comments.get(key.substring(0, key.indexOf(":") + 1)); + if (comment != null) { + output += comment; } + output += key; + output += "\n"; } } catch (Exception e) {