diff --git a/paper-api/src/main/java/org/bukkit/configuration/file/YamlConfiguration.java b/paper-api/src/main/java/org/bukkit/configuration/file/YamlConfiguration.java index d183d97465..fc4460d94d 100644 --- a/paper-api/src/main/java/org/bukkit/configuration/file/YamlConfiguration.java +++ b/paper-api/src/main/java/org/bukkit/configuration/file/YamlConfiguration.java @@ -204,7 +204,9 @@ public class YamlConfiguration extends FileConfiguration { if (comment.getCommentType() == CommentType.BLANK_LINE) { lines.add(null); } else { - lines.add(comment.getValue()); + String line = comment.getValue(); + line = line.startsWith(" ") ? line.substring(1) : line; + lines.add(line); } } } @@ -217,7 +219,9 @@ public class YamlConfiguration extends FileConfiguration { if (comment == null) { lines.add(new CommentLine(null, null, "", CommentType.BLANK_LINE)); } else { - lines.add(new CommentLine(null, null, comment, commentType)); + String line = comment; + line = line.isEmpty() ? line : " " + line; + lines.add(new CommentLine(null, null, line, commentType)); } } return lines; diff --git a/paper-api/src/test/java/org/bukkit/configuration/file/FileConfigurationTest.java b/paper-api/src/test/java/org/bukkit/configuration/file/FileConfigurationTest.java index 87bfa2c1da..d6a1410364 100644 --- a/paper-api/src/test/java/org/bukkit/configuration/file/FileConfigurationTest.java +++ b/paper-api/src/test/java/org/bukkit/configuration/file/FileConfigurationTest.java @@ -373,7 +373,7 @@ public abstract class FileConfigurationTest extends MemoryConfigurationTest { config.options().parseComments(true); config.loadFromString("key1: value1\nkey2: value2 # Test inline\nkey3: value3"); - assertEquals(Arrays.asList(" Test inline"), config.getInlineComments("key2")); + assertEquals(Arrays.asList("Test inline"), config.getInlineComments("key2")); } @Test @@ -384,7 +384,7 @@ public abstract class FileConfigurationTest extends MemoryConfigurationTest { config.set("key1", "value1"); config.set("key2", "value2"); config.set("key3", "value3"); - config.setInlineComments("key2", Arrays.asList(" Test inline")); + config.setInlineComments("key2", Arrays.asList("Test inline")); String result = config.saveToString(); String expected = "key1: value1\nkey2: value2 # Test inline\nkey3: value3\n"; diff --git a/paper-api/src/test/java/org/bukkit/configuration/file/YamlConfigurationTest.java b/paper-api/src/test/java/org/bukkit/configuration/file/YamlConfigurationTest.java index 57e31a2867..fa5f54a289 100644 --- a/paper-api/src/test/java/org/bukkit/configuration/file/YamlConfigurationTest.java +++ b/paper-api/src/test/java/org/bukkit/configuration/file/YamlConfigurationTest.java @@ -16,15 +16,15 @@ public class YamlConfigurationTest extends FileConfigurationTest { @Override public List getTestCommentInput() { List comments = new ArrayList<>(); - comments.add(" This is a sample"); - comments.add(" header."); - comments.add(" Newline above should be commented."); + comments.add("This is a sample"); + comments.add("header."); + comments.add("Newline above should be commented."); comments.add(""); comments.add(""); comments.add(null); comments.add(null); - comments.add(" Comment of first Key"); - comments.add(" and a second line."); + comments.add("Comment of first Key"); + comments.add("and a second line."); return comments; } @@ -35,7 +35,7 @@ public class YamlConfigurationTest extends FileConfigurationTest { @Override public List getTestHeaderComments() { - return Arrays.asList(" Header", " Second Line"); + return Arrays.asList("Header", "Second Line"); } @Override @@ -45,7 +45,7 @@ public class YamlConfigurationTest extends FileConfigurationTest { @Override public List getTestKeyComments() { - return Arrays.asList(" First key Comment", " Second Line"); + return Arrays.asList("First key Comment", "Second Line"); } @Override