mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-30 00:56:47 +01:00
Merge pull request #2800 from DorCoMaNdO/master
Fix config auto update.
This commit is contained in:
commit
e1cf4c0c67
@ -6,6 +6,7 @@ import java.io.File;
|
|||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -65,14 +66,11 @@ public abstract class AutoUpdateConfigLoader extends ConfigLoader {
|
|||||||
output = output.substring(output.indexOf('\n', output.indexOf('#')) + 1);
|
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
|
// Read the internal config to get comments, then put them in the new one
|
||||||
try {
|
try {
|
||||||
// Read internal
|
// Read internal
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource(fileName)));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource(fileName)));
|
||||||
HashMap<String, String> comments = new HashMap<String, String>();
|
LinkedHashMap<String, String> comments = new LinkedHashMap<String, String>();
|
||||||
String temp = "";
|
String temp = "";
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
@ -83,21 +81,37 @@ public abstract class AutoUpdateConfigLoader extends ConfigLoader {
|
|||||||
else if (line.contains(":")) {
|
else if (line.contains(":")) {
|
||||||
line = line.substring(0, line.indexOf(":") + 1);
|
line = line.substring(0, line.indexOf(":") + 1);
|
||||||
if (!temp.isEmpty()) {
|
if (!temp.isEmpty()) {
|
||||||
|
if(comments.containsKey(line)) {
|
||||||
|
int index = 0;
|
||||||
|
while(comments.containsKey(line + index)) {
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
line = line + index;
|
||||||
|
}
|
||||||
|
|
||||||
comments.put(line, temp);
|
comments.put(line, temp);
|
||||||
temp = "";
|
temp = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output = "";
|
|
||||||
// Dump to the new one
|
// Dump to the new one
|
||||||
for (String key : keys) {
|
HashMap<String, Integer> indexed = new HashMap<String, Integer>();
|
||||||
String comment = comments.get(key.substring(0, key.indexOf(":") + 1));
|
for (String key : comments.keySet()) {
|
||||||
if (comment != null) {
|
String actualkey = key.substring(0, key.indexOf(":") + 1);
|
||||||
output += comment;
|
|
||||||
|
int index = 0;
|
||||||
|
if(indexed.containsKey(actualkey)) {
|
||||||
|
index = indexed.get(actualkey);
|
||||||
|
}
|
||||||
|
boolean isAtTop = !output.contains("\n" + actualkey);
|
||||||
|
index = output.indexOf((isAtTop ? "" : "\n") + actualkey, index);
|
||||||
|
|
||||||
|
if (index >= 0) {
|
||||||
|
output = output.substring(0, index) + "\n" + comments.get(key) + output.substring(isAtTop ? index : index + 1);
|
||||||
|
indexed.put(actualkey, index + comments.get(key).length() + actualkey.length() + 1);
|
||||||
}
|
}
|
||||||
output += key;
|
|
||||||
output += "\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user