Skip to content

Commit 52c20a9

Browse files
committed
Sort the methods in correct order
Moved the private methods on the bottom.
1 parent 113b20d commit 52c20a9

2 files changed

Lines changed: 61 additions & 60 deletions

File tree

Color Conversion/src/main/java/org/broken/arrow/library/color/ChatColors.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,28 @@
2525
public final class ChatColors {
2626

2727
/**
28-
* The special character which prefixes all chat colour codes. Use this if
29-
* you need to dynamically convert colour codes from your custom format.
28+
* The special character which prefixes all chat color codes. Use this if
29+
* you need to dynamically convert color codes from your custom format.
3030
*/
3131
public static final char COLOR_CHAR = '\u00A7';
3232
/**
33-
* The special character which prefixes all chat colour codes. Use this if
34-
* you need to dynamically convert colour codes from your custom format.
33+
* The special character which prefixes all chat color codes. Use this if
34+
* you need to dynamically convert color codes from your custom format.
3535
*/
3636
public static final char COLOR_AMPERSAND = '\u0026';
3737
private static final char[] ALL_CODES = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'R', 'r', 'X', 'x'};
3838
private static final char[] ALL_CHAR_COLOR_CODES = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'R', 'r', 'X', 'x'};
3939
private static final char[] SPECIAL_SIGN = {'l', 'n', 'o', 'k', 'm', 'r'};
4040
/**
41-
* Pattern to remove all colour codes.
41+
* Pattern to remove all color codes.
4242
*/
4343
public static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + COLOR_CHAR + "[0-9A-FK-ORX]");
4444
/**
45-
* Colour instances keyed by their active character.
45+
* Color instances keyed by their active character.
4646
*/
4747
private static final Map<Character, ChatColors> BY_CHAR = new HashMap<>();
4848
/**
49-
* Colour instances keyed by their name.
49+
* Color instances keyed by their name.
5050
*/
5151
private static final Map<String, ChatColors> BY_NAME = new HashMap<>();
5252
/**

Color Conversion/src/main/java/org/broken/arrow/library/color/TextTranslator.java

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -110,42 +110,24 @@ public static JsonObject toComponent(String message) {
110110
}
111111

112112
/**
113-
* This is for component when you want to send message through vanilla minecraft MNS for example.
114-
* DO NOT WORK IN SPIGOT API. Use {@link #toSpigotFormat(String)}
115-
*
116-
* @param message your string message.
117-
* @param defaultColor set default color when colors are not set in the message.
118-
* @return json object with the set colors.
119-
*/
120-
private JsonObject componentFormat(String message, String defaultColor) {
121-
CreateComponent createComponent = new CreateComponent(this,message);
122-
return createComponent.componentFormat(defaultColor);
123-
}
124-
125-
126-
/**
127-
* Type your message/string text here. you use
113+
* Converts a legacy Spigot formatted string to a JSON object, suitable for use with Minecraft's chat serializer.
114+
* Most usefully for Minecraft version 1.16 and newer, when you want to use gradients or hexadecimal colors,
115+
* and not want to use my methods to convert colors.
116+
* <p>&nbsp;</p>
128117
* <p>
129-
* §/&amp; color code or &lt;#55F758&gt; for normal hex and
130-
* &lt;#5e4fa2:#f79459&gt; for gradient (use any color code to stop gradient).
118+
* Legacy Spigot formatting uses symbols like '&amp;' or '§' and supports two specific formats:
119+
* </p>
120+
* <ul>
121+
* <li>Hexadecimal format: e.g., '&amp;x&amp;d&amp;4&amp;c&amp;3&amp;1&amp;1'</li>
122+
* <li>Color codes: e.g., '&amp;f' for white.</li>
123+
* </ul>
131124
*
132-
* @param message your string message.
133-
* @return spigot compatible translation.
125+
* @param message The input string to check and convert to JSON.
126+
* @param defaultColor The default color to use if a color is not specified in the message.
127+
* @return A JSON object representing the formatted text.
134128
*/
135-
136-
private String spigotFormat(String message) {
137-
String messageCopy = checkStringForGradient(message);
138-
Matcher matcher = HEX_PATTERN.matcher(messageCopy);
139-
140-
while (matcher.find()) {
141-
String match = matcher.group(0);
142-
int firstPos = match.indexOf("#");
143-
if (match.length() <= 9)
144-
messageCopy = messageCopy.replace(match, "&x&" + match.charAt(firstPos + 1) + "&" + match.charAt(firstPos + 1) + "&" + match.charAt(firstPos + 2) + "&" + match.charAt(firstPos + 2) + "&" + match.charAt(firstPos + 3) + "&" + match.charAt(firstPos + 3));
145-
else
146-
messageCopy = messageCopy.replace(match, "&x&" + match.charAt(firstPos + 1) + "&" + match.charAt(firstPos + 2) + "&" + match.charAt(firstPos + 3) + "&" + match.charAt(firstPos + 4) + "&" + match.charAt(firstPos + 5) + "&" + match.charAt(firstPos + 6));
147-
}
148-
return ChatColor.translateAlternateColorCodes('&', messageCopy);
129+
public static JsonObject fromLegacyText(String message, ChatColors defaultColor) {
130+
return CreateFromLegacyText.fromLegacyText( message,defaultColor);
149131
}
150132

151133
/**
@@ -189,26 +171,6 @@ public String checkStringForGradient(final String text) {
189171
return messageCopy;
190172
}
191173

192-
/**
193-
* Converts a legacy Spigot formatted string to a JSON object, suitable for use with Minecraft's chat serializer.
194-
* Most usefully for Minecraft version 1.16 and newer, when you want to use gradients or hexadecimal colors,
195-
* and not want to use my methods to convert colors.
196-
* <p>&nbsp;</p>
197-
* <p>
198-
* Legacy Spigot formatting uses symbols like '&amp;' or '§' and supports two specific formats:
199-
* </p>
200-
* <ul>
201-
* <li>Hexadecimal format: e.g., '&amp;x&amp;d&amp;4&amp;c&amp;3&amp;1&amp;1'</li>
202-
* <li>Color codes: e.g., '&amp;f' for white.</li>
203-
* </ul>
204-
*
205-
* @param message The input string to check and convert to JSON.
206-
* @param defaultColor The default color to use if a color is not specified in the message.
207-
* @return A JSON object representing the formatted text.
208-
*/
209-
public static JsonObject fromLegacyText(String message, ChatColors defaultColor) {
210-
return CreateFromLegacyText.fromLegacyText( message,defaultColor);
211-
}
212174

213175
/**
214176
* Sets the color for the text.
@@ -262,4 +224,43 @@ public String getType() {
262224
return type;
263225
}
264226
}
227+
228+
/**
229+
* This is for component when you want to send message through vanilla minecraft MNS for example.
230+
* DO NOT WORK IN SPIGOT API. Use {@link #toSpigotFormat(String)}
231+
*
232+
* @param message your string message.
233+
* @param defaultColor set default color when colors are not set in the message.
234+
* @return json object with the set colors.
235+
*/
236+
private JsonObject componentFormat(String message, String defaultColor) {
237+
CreateComponent createComponent = new CreateComponent(this,message);
238+
return createComponent.componentFormat(defaultColor);
239+
}
240+
241+
242+
/**
243+
* Type your message/string text here. you use
244+
* <p>
245+
* §/&amp; color code or &lt;#55F758&gt; for normal hex and
246+
* &lt;#5e4fa2:#f79459&gt; for gradient (use any color code to stop gradient).
247+
*
248+
* @param message your string message.
249+
* @return spigot compatible translation.
250+
*/
251+
252+
private String spigotFormat(String message) {
253+
String messageCopy = checkStringForGradient(message);
254+
Matcher matcher = HEX_PATTERN.matcher(messageCopy);
255+
256+
while (matcher.find()) {
257+
String match = matcher.group(0);
258+
int firstPos = match.indexOf("#");
259+
if (match.length() <= 9)
260+
messageCopy = messageCopy.replace(match, "&x&" + match.charAt(firstPos + 1) + "&" + match.charAt(firstPos + 1) + "&" + match.charAt(firstPos + 2) + "&" + match.charAt(firstPos + 2) + "&" + match.charAt(firstPos + 3) + "&" + match.charAt(firstPos + 3));
261+
else
262+
messageCopy = messageCopy.replace(match, "&x&" + match.charAt(firstPos + 1) + "&" + match.charAt(firstPos + 2) + "&" + match.charAt(firstPos + 3) + "&" + match.charAt(firstPos + 4) + "&" + match.charAt(firstPos + 5) + "&" + match.charAt(firstPos + 6));
263+
}
264+
return ChatColor.translateAlternateColorCodes('&', messageCopy);
265+
}
265266
}

0 commit comments

Comments
 (0)