mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-29 18:27:36 +02:00
Add support for RGB colors using the color char
Examples include: `&x00002a00002b&lText`
This commit is contained in:
@ -0,0 +1,27 @@
|
||||
package com.github.games647.fastlogin.bukkit;
|
||||
|
||||
import com.github.games647.fastlogin.core.CommonUtil;
|
||||
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class FastLoginBukkitTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testRGB() {
|
||||
var message = "&x00002a00002b&lText";
|
||||
var msg = CommonUtil.translateColorCodes(message);
|
||||
assertThat(msg, is("§x00002a00002b§lText"));
|
||||
|
||||
var components = TextComponent.fromLegacyText(msg);
|
||||
var expected = """
|
||||
{"bold":true,"color":"#00a00b","text":"Text"}""";
|
||||
assertThat(ComponentSerializer.toString(components), is(expected));
|
||||
}
|
||||
}
|
@ -61,7 +61,7 @@ public class CommonUtil {
|
||||
public static String translateColorCodes(String rawMessage) {
|
||||
char[] chars = rawMessage.toCharArray();
|
||||
for (int i = 0; i < chars.length - 1; i++) {
|
||||
if (chars[i] == COLOR_CHAR && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(chars[i + 1]) > -1) {
|
||||
if (chars[i] == COLOR_CHAR && "x0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(chars[i + 1]) > -1) {
|
||||
chars[i] = TRANSLATED_CHAR;
|
||||
chars[i + 1] = Character.toLowerCase(chars[i + 1]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user