@@ -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> </p>
128117 * <p>
129- * §/& color code or <#55F758> for normal hex and
130- * <#5e4fa2:#f79459> for gradient (use any color code to stop gradient).
118+ * Legacy Spigot formatting uses symbols like '&' or '§' and supports two specific formats:
119+ * </p>
120+ * <ul>
121+ * <li>Hexadecimal format: e.g., '&x&d&4&c&3&1&1'</li>
122+ * <li>Color codes: e.g., '&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> </p>
197- * <p>
198- * Legacy Spigot formatting uses symbols like '&' or '§' and supports two specific formats:
199- * </p>
200- * <ul>
201- * <li>Hexadecimal format: e.g., '&x&d&4&c&3&1&1'</li>
202- * <li>Color codes: e.g., '&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+ * §/& color code or <#55F758> for normal hex and
246+ * <#5e4fa2:#f79459> 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