16.7_dev-24

This commit is contained in:
2024-07-05 22:40:29 +02:00
parent a350f9fb00
commit c7e392a0f0
10 changed files with 37 additions and 12 deletions

View File

@@ -64,7 +64,7 @@ public class T2C_ConfigWriter {
// Copy default values if they are missing
config.options().copyDefaults(true);
T2C_YmlWriter.saveConfigWithComments(configFile, config, comments, header);
T2C_YmlWriter.saveConfigWithComments(configFile, config, comments, false,header);
readConfig(prefix, configFile, config, values, isReload);
}

View File

@@ -61,7 +61,7 @@ public class T2C_LanguageWriter {
comments.put(item.getPath(), commandList);
}
}
T2C_YmlWriter.saveConfigWithComments(langFile, config, comments, header);
T2C_YmlWriter.saveConfigWithComments(langFile, config, comments, true, header);
}
}
readConfig(prefix, path, values, loadConfig, isReload);

View File

@@ -12,14 +12,14 @@ import java.util.List;
import java.util.Map;
public class T2C_YmlWriter {
protected static void saveConfigWithComments(File file, FileConfiguration config, Map<String, List<String>> comments, String... headers) {
protected static void saveConfigWithComments(File file, FileConfiguration config, Map<String, List<String>> comments, boolean oneListToString,String... headers) {
try {
StringBuilder configContent = new StringBuilder();
for (String h : headers) {
configContent.append(h).append("\n");
}
configContent.append("\n");
addSection(config, comments, configContent, "", 0);
addSection(config, comments, configContent, "", 0,oneListToString);
// Write the content to the file
Files.write(file.toPath(), configContent.toString().getBytes());
@@ -28,7 +28,7 @@ public class T2C_YmlWriter {
}
}
protected static void addSection(ConfigurationSection section, Map<String, List<String>> comments, StringBuilder builder, String prefix, int indentLevel) {
protected static void addSection(ConfigurationSection section, Map<String, List<String>> comments, StringBuilder builder, String prefix, int indentLevel, boolean oneListToString) {
String indent = " ".repeat(indentLevel);
for (String key : section.getKeys(false)) {
@@ -49,12 +49,19 @@ public class T2C_YmlWriter {
if (value instanceof ConfigurationSection) {
// Correctly add the section
builder.append(indent).append(key).append(":\n");
addSection((ConfigurationSection) value, comments, builder, fullKey, indentLevel + 1);
addSection((ConfigurationSection) value, comments, builder, fullKey, indentLevel + 1, oneListToString);
} else {
// Add value with proper indentation
// builder.append(indent).append(key).append(": ").append(value).append("\n");
if (value instanceof List) {
List<?> list = (List<?>) value;
if (oneListToString && list.size() == 1) {
for (Object s : list) {
builder.append(indent).append(key).append(": \"").append(s).append("\"\n");
}
continue;
}
if (list.isEmpty()) {
builder.append(indent).append(key).append(": []").append("\n");
continue;