java - Add color code support to a Bukkit plugin -
I would like to add color code support in my config.yml
. How do I add translateAlternateColorCode
to my code correctly? Public boolean on command (CommandSender sender, command CMD, string label, string [] args) {player player = (player) sender; If (cmd.getName () .all ignored cas ("member") {player.sendMessage (getConfig (). GetString ("member text")); }
You can simply use translateAltranateColorCodes
. Here's an example:
string nonColoredText = getConfig (). GetString ("member text"); // "member text" string get colored text = raw string. Translate Altinetic Color Code ('& amp;', nonColoredText); // Edit the colors code
Any of the above text which is & amp;
starts with the correct color code, for example, if & amp; A
was in config, it would convert it to green color or ChatColor.GREEN
, which will show the message in green, it also works with other characters such as you color If you want to use the $
symbol for the codes, you can do this:
string color text = translation optional caller code ('$', non- Collard text);
So if the code above was entered in the code above, it will translate to ChatColor.GREEN
, the text is green Will make in
What the first code is doing, it is getting the string from the config file under MemberText
, and it is inserted into string nonColoredText
Then, it is translating the optional color code, which is the & amp; Starts with
, and puts it in the coloredtext
after which you can send coloredtext
, or you can do anything else with it.
is a short example, if the following member text
/ P>
and welcome to my server, and I hope you have a great time is! & Amp; A & amp; Amp; See the rules / rules rule
that will translate to nonColoredText
, and coloredtext
to do this:
ChatColor.GREEN + "Welcome to my server," + ChatColor.AQUA + "I hope you have a great time!" + Chat Koror. Yellow + Chatolor BA + "Check the rules of rules", "
That message can be sent to a player, and it will be shown accordingly, and colorful!
Comments
Post a Comment