Question How to make color codes work?

  • After careful consideration and due to limited usage, we’ve made the decision to discontinue the PaperMC forums. Moving forward, we recommend using Hangar for plugin uploads, and for all other community discussions and support, please join us on Discord.

Durov

New member
Mar 29, 2022
3
0
1
Hello everyone, I am writing my plugin for the chat implementation, how can I implement the use of the symbol & + color code

At the moment I have a line

if(p.hasPermission("color.chat")){ e.getMessage().replaceAll("&", "§"); }

However, the plugin does not work in operation.
Note: I want to make the player when he writes a message, for example &c Hello and the color symbols disappear and the message is red.
 
Solution
You need to set the message contents with setMessage after you replace the &:
Java:
e.setMessage(e.getMessage().replaceAll("&", "§"));