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