Fixes #287
This commit is contained in:
@@ -463,7 +463,7 @@ public final class StargateConfig {
|
|||||||
try {
|
try {
|
||||||
currentConfiguration.save(new File(dataFolderPath, "config.yml.old"));
|
currentConfiguration.save(new File(dataFolderPath, "config.yml.old"));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Stargate.debug("Stargate::migrateConfig", "Unable to save old backup and do migration");
|
Stargate.debug("StargateConfig::migrateConfig", "Unable to save old backup and do migration");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -482,7 +482,7 @@ public final class StargateConfig {
|
|||||||
FileHelper.getInputStreamForInternalFile("/config-migrations.txt")), "=",
|
FileHelper.getInputStreamForInternalFile("/config-migrations.txt")), "=",
|
||||||
ColorConversion.NORMAL);
|
ColorConversion.NORMAL);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Stargate.debug("Stargate::migrateConfig", "Unable to load config migration file");
|
Stargate.debug("StargateConfig::migrateConfig", "Unable to load config migration file");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -504,14 +504,15 @@ public final class StargateConfig {
|
|||||||
if (oldConfiguration.get(key) instanceof MemorySection) {
|
if (oldConfiguration.get(key) instanceof MemorySection) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Stargate.debug("Stargate::migrateConfig", "Setting " + key + " to " + oldConfiguration.get(key));
|
Stargate.debug("StargateConfig::migrateConfig", "Setting " + key + " to " +
|
||||||
|
oldConfiguration.get(key));
|
||||||
newConfiguration.set(key, oldConfiguration.get(key));
|
newConfiguration.set(key, oldConfiguration.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
newConfiguration.save(new File(dataFolderPath, "config.yml"));
|
newConfiguration.save(new File(dataFolderPath, "config.yml"));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Stargate.debug("Stargate::migrateConfig", "Unable to save migrated config");
|
Stargate.debug("StargateConfig::migrateConfig", "Unable to save migrated config");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -50,10 +50,15 @@ public class StargateYamlConfiguration extends YamlConfiguration {
|
|||||||
StringBuilder yamlBuilder = new StringBuilder();
|
StringBuilder yamlBuilder = new StringBuilder();
|
||||||
List<String> currentComment = new ArrayList<>();
|
List<String> currentComment = new ArrayList<>();
|
||||||
int commentId = 0;
|
int commentId = 0;
|
||||||
|
int previousIndentation = 0;
|
||||||
|
|
||||||
for (String line : configString.split("\n")) {
|
for (String line : configString.split("\n")) {
|
||||||
String trimmed = line.trim();
|
String trimmed = line.trim();
|
||||||
if (trimmed.startsWith("#")) {
|
if (trimmed.startsWith("#")) {
|
||||||
|
// Store the indentation of the block
|
||||||
|
if (currentComment.isEmpty()) {
|
||||||
|
previousIndentation = getIndentation(line);
|
||||||
|
}
|
||||||
//Temporarily store the comment line
|
//Temporarily store the comment line
|
||||||
if (trimmed.startsWith("# ")) {
|
if (trimmed.startsWith("# ")) {
|
||||||
currentComment.add(trimmed.replaceFirst("# ", START_OF_COMMENT_LINE));
|
currentComment.add(trimmed.replaceFirst("# ", START_OF_COMMENT_LINE));
|
||||||
@@ -63,9 +68,10 @@ public class StargateYamlConfiguration extends YamlConfiguration {
|
|||||||
} else {
|
} else {
|
||||||
//Write the full formatted comment to the StringBuilder
|
//Write the full formatted comment to the StringBuilder
|
||||||
if (!currentComment.isEmpty()) {
|
if (!currentComment.isEmpty()) {
|
||||||
int indentation = getIndentation(line);
|
int indentation = trimmed.isEmpty() ? previousIndentation : getIndentation(line);
|
||||||
generateCommentYAML(yamlBuilder, currentComment, commentId++, indentation);
|
generateCommentYAML(yamlBuilder, currentComment, commentId++, indentation);
|
||||||
currentComment.clear();
|
currentComment.clear();
|
||||||
|
previousIndentation = 0;
|
||||||
}
|
}
|
||||||
//Add the non-comment line assuming it isn't empty
|
//Add the non-comment line assuming it isn't empty
|
||||||
if (!trimmed.isEmpty()) {
|
if (!trimmed.isEmpty()) {
|
||||||
|
Reference in New Issue
Block a user