Add support for RGB colors using the color char

Examples include:
`&x00002a00002b&lText`
This commit is contained in:
games647
2022-06-24 16:21:53 +02:00
parent 5e159cac64
commit f182adc3bc
2 changed files with 28 additions and 1 deletions

View File

@ -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));
}
}

View File

@ -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]);
}