Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static void load(YamlConfiguration config, CommonLogger commonLogger) {
for (String key : config.getConfigurationSection("messages").getKeys(true)) {
String value = config.getString("messages." + key);
if (value != null) {
newMessages.put(key, value.replace("\\n", "\n"));
newMessages.put(key, value.replace("\\n", "\n").replaceAll("(?<=\\n)(?=\\n)", " "));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package me.confuser.banmanager.common.configs;

import me.confuser.banmanager.common.BasePluginTest;
import me.confuser.banmanager.common.TestLogger;
import me.confuser.banmanager.common.configuration.file.YamlConfiguration;
import me.confuser.banmanager.common.util.Message;
import org.junit.Test;

import java.io.StringReader;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

public class MessagesConfigTest extends BasePluginTest {

Expand All @@ -15,4 +20,50 @@ public void isValid() {
.get("info.ban.temporary").set("reason", "abc").set("actor", "def").set("created",
"8th July").set("expires", "1d").toString());
}

@Test
public void doubleNewlineProducesNonEmptyLine() {
String yaml = "messages:\n test:\n greeting: 'Hello\\n\\nWorld'";
YamlConfiguration config = YamlConfiguration.loadConfiguration(new StringReader(yaml));
Message.load(config, new TestLogger());

String result = Message.get("test.greeting").toString();

assertEquals("Hello\n \nWorld", result);
}

@Test
public void tripleNewlineProducesNonEmptyLines() {
String yaml = "messages:\n test:\n greeting: 'Hello\\n\\n\\nWorld'";
YamlConfiguration config = YamlConfiguration.loadConfiguration(new StringReader(yaml));
Message.load(config, new TestLogger());

String result = Message.get("test.greeting").toString();

assertEquals("Hello\n \n \nWorld", result);
}

@Test
public void singleNewlineIsUnchanged() {
String yaml = "messages:\n test:\n greeting: 'Hello\\nWorld'";
YamlConfiguration config = YamlConfiguration.loadConfiguration(new StringReader(yaml));
Message.load(config, new TestLogger());

String result = Message.get("test.greeting").toString();

assertEquals("Hello\nWorld", result);
}

@Test
public void noConsecutiveEmptyLinesInLoadedMessages() {
String yaml = "messages:\n test:\n msg: 'Line1\\n\\nLine2\\n\\n\\nLine3'";
YamlConfiguration config = YamlConfiguration.loadConfiguration(new StringReader(yaml));
Message.load(config, new TestLogger());

String result = Message.get("test.msg").toString();

for (String line : result.split("\n", -1)) {
assertFalse("Empty lines should contain a space for chat rendering", line.isEmpty());
}
}
}
Loading