Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.

Commit e63b78e

Browse files
[InDev] Fixed bad code with MOTD Formatter
1 parent 6277e18 commit e63b78e

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/main/java/com/andcool/format/MOTDFormatter.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.util.Map;
88

99
public class MOTDFormatter {
10-
private static final char COLOR_CHAR = '&';
10+
private static final String COLOR_CHAR = "\u00A7";
1111
private final Map<Character, String> colorMap = new HashMap<>();
1212
private final Map<Character, String> styleMap = new HashMap<>();
1313

@@ -38,29 +38,27 @@ public MOTDFormatter() {
3838
}
3939

4040
public JSONArray format(String motd) {
41-
motd = motd.replace("§", "&"); // Because JAVA not working with '§' symbol. idk
4241
JSONArray jsonArray = new JSONArray();
4342
StringBuilder currentText = new StringBuilder();
4443
JSONObject currentJson = new JSONObject();
4544

4645
for (int i = 0; i < motd.length(); i++) {
4746
char c = motd.charAt(i);
48-
if (c == COLOR_CHAR && i + 1 < motd.length()) {
47+
if (motd.startsWith(COLOR_CHAR, i + 1) && i + 1 < motd.length()) {
4948
if (!currentText.isEmpty()) {
5049
currentJson.put("text", currentText.toString());
5150
jsonArray.put(currentJson);
5251
currentText = new StringBuilder();
5352
currentJson = new JSONObject();
5453
}
5554

56-
char formatChar = motd.charAt(i + 1);
55+
char formatChar = motd.charAt(i + 2);
5756
if (colorMap.containsKey(formatChar)) {
5857
currentJson.put("color", colorMap.get(formatChar));
5958
} else if (styleMap.containsKey(formatChar)) {
6059
currentJson.put(styleMap.get(formatChar), true);
6160
}
62-
63-
i++;
61+
i += 2;
6462
} else {
6563
currentText.append(c);
6664
}

0 commit comments

Comments
 (0)