Solved RGB Color in chat, tab, scoreboard 1.16.5

Discussion in 'Spigot Plugin Development' started by Hoshion, Jul 10, 2021.

  1. In snapshot 20w17a Mojand added support for RGB Colors. How to use it in plugin?
     
  2. You need to create a method that can use Hex Color and use it.
     
  3. You can create RGB color with TextComponent

    Code (Java):
    new TextComponent("Potatoes Duck Codes").setColor(ChatColor.of("#123456"));
     
  4. There’s already a lot of thread on this. Just google hex color spigot
     
    • Optimistic Optimistic x 1
  5. Idk how to use TextComponent with Player#sendMessage(), so i tried to use BaseComponent with Player#spigot()#sendMessage()

    Or how can i use TextComponent?
     
  6. Code (Java):

    public String hexColor(String text) {
        Pattern pattern = Pattern.compile("#[a-fA-f0-9]{6}");
        Matcher matcher = pattern.matcher(text);
            while (matcher.find()) {
                String color = text.substring(matcher.start(), matcher.end());
                text = text.replace(color, net.md_5.bungee.api.ChatColor.of(color) + "");
            }
        }
        return net.md_5.bungee.api.ChatColor.translateAlternateColorCodes('&', text);
    }
     
    I don't know if it works for scoreboard and tablist, I have only tried for chat
     
    #8 reussy, Jul 10, 2021
    Last edited: Jul 10, 2021
  7. Using Bungee ChatColor#of will work for Tablist, Chat, Server List, Scoreboard, Titles, Actionbars and just about every other text input on minecraft