|
7 | 7 | import java.util.Map; |
8 | 8 |
|
9 | 9 | public class MOTDFormatter { |
10 | | - private static final char COLOR_CHAR = '&'; |
| 10 | + private static final String COLOR_CHAR = "\u00A7"; |
11 | 11 | private final Map<Character, String> colorMap = new HashMap<>(); |
12 | 12 | private final Map<Character, String> styleMap = new HashMap<>(); |
13 | 13 |
|
@@ -38,29 +38,27 @@ public MOTDFormatter() { |
38 | 38 | } |
39 | 39 |
|
40 | 40 | public JSONArray format(String motd) { |
41 | | - motd = motd.replace("§", "&"); // Because JAVA not working with '§' symbol. idk |
42 | 41 | JSONArray jsonArray = new JSONArray(); |
43 | 42 | StringBuilder currentText = new StringBuilder(); |
44 | 43 | JSONObject currentJson = new JSONObject(); |
45 | 44 |
|
46 | 45 | for (int i = 0; i < motd.length(); i++) { |
47 | 46 | 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()) { |
49 | 48 | if (!currentText.isEmpty()) { |
50 | 49 | currentJson.put("text", currentText.toString()); |
51 | 50 | jsonArray.put(currentJson); |
52 | 51 | currentText = new StringBuilder(); |
53 | 52 | currentJson = new JSONObject(); |
54 | 53 | } |
55 | 54 |
|
56 | | - char formatChar = motd.charAt(i + 1); |
| 55 | + char formatChar = motd.charAt(i + 2); |
57 | 56 | if (colorMap.containsKey(formatChar)) { |
58 | 57 | currentJson.put("color", colorMap.get(formatChar)); |
59 | 58 | } else if (styleMap.containsKey(formatChar)) { |
60 | 59 | currentJson.put(styleMap.get(formatChar), true); |
61 | 60 | } |
62 | | - |
63 | | - i++; |
| 61 | + i += 2; |
64 | 62 | } else { |
65 | 63 | currentText.append(c); |
66 | 64 | } |
|
0 commit comments