Search code examples
javaminecraftbukkit

Minecraft color codes not working properly (Spigot)


I'm using this:

public void onPlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent event) {
    event.getPlayer().sendRawMessage(Color.RED.toString()+"TEXT...");
}

but it appears as Color:[rgb0xFF00]TEXT... in the Chat.

I also tried getPlayer().sendMessage(...) and Color.RED, but neither is working.

What am I doing wrong?

Edit: I found the solution, see my answer below.


Solution

  • Ok, I found the solution. You have to use org.bukkit.ChatColor instead of org.bukkit.Color! (Stupid me)

    So:

    public void onPlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent event) {
        event.getPlayer().sendMessage(ChatColor.RED+"TEXT...");
    }