From 3da79e7860fb821fd18bf5ca94e340b4573bbeea Mon Sep 17 00:00:00 2001 From: adrianoy Date: Wed, 28 Jul 2021 03:38:36 -0300 Subject: [PATCH] Fixes multi-line comments breaking --- .../java/draylar/omegaconfig/OmegaConfig.java | 20 ++++++++++++++++--- .../config/StructuresConfigTest.java | 20 +++++++++---------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/omega-config-base/src/main/java/draylar/omegaconfig/OmegaConfig.java b/omega-config-base/src/main/java/draylar/omegaconfig/OmegaConfig.java index 40a5bfe..a43edc6 100644 --- a/omega-config-base/src/main/java/draylar/omegaconfig/OmegaConfig.java +++ b/omega-config-base/src/main/java/draylar/omegaconfig/OmegaConfig.java @@ -123,11 +123,25 @@ public class OmegaConfig { // Check if we should insert comment for (Map.Entry entry : keyToComments.entrySet()) { - String key = entry.getKey(); String comment = entry.getValue(); - if (at.trim().startsWith(String.format("\"%s\"", key))) { - insertions.put(i + insertions.size(), String.format("%s//%s", getStartingWhitespace(at), comment)); + if (at.trim().startsWith(String.format("\"%s\"", entry.getKey()))) { + if (comment.contains("\n")) { + String[] comments = comment.split("\n"); + StringBuilder builder = new StringBuilder(); + + for (int j = 0; j < comments.length; j++) { + builder.append(String.format("%s//%s", getStartingWhitespace(at), comments[j])); + if (j != comments.length - 1) { + builder.append("\n"); + } + } + comment = builder.toString(); + } else { + comment = String.format("%s//%s", getStartingWhitespace(at), comment); + } + + insertions.put(i + insertions.size(), comment); break; } } diff --git a/src/testmod/java/draylar/omegatest/config/StructuresConfigTest.java b/src/testmod/java/draylar/omegatest/config/StructuresConfigTest.java index aadac90..97e87cb 100644 --- a/src/testmod/java/draylar/omegatest/config/StructuresConfigTest.java +++ b/src/testmod/java/draylar/omegatest/config/StructuresConfigTest.java @@ -13,16 +13,16 @@ public class StructuresConfigTest implements Config { @Comment(""" Welcome to Mo'Structures Config! - // - // Here, you can turn off structures, change their chance, and also change their salt. - // - // To turn off a structure, simply go to the corresponding entry and set `activated` to false. - // - // Mo' Structures uses the vanilla structure spawning system. That is- - // - Seperation is the minimum chunks between structures - // - Spacing is the average chunks between structures - // - // Salt is a special field that gives structures unique spawning positions. DO NOT TOUCH IT, ONLY ADVANCED TROUBLESHOOTING! + + Here, you can turn off structures, change their chance, and also change their salt. + + To turn off a structure, simply go to the corresponding entry and set `activated` to false. + + Mo' Structures uses the vanilla structure spawning system. That is- + - Seperation is the minimum chunks between structures + - Spacing is the average chunks between structures + + Salt is a special field that gives structures unique spawning positions. DO NOT TOUCH IT, ONLY ADVANCED TROUBLESHOOTING! """) public final Map structureConfigEntries = new HashMap<>(17);