Bukkit Coding – (5) Adding Color to Chat

It’s great to now be able to send text to players in the chat, but white is a little boring, isn’t it? It’s time to add some color. Adding color is really easy to do. I’m going to go ahead and insert the same code that we had with our Hello World script, but this time, I’ll make the server send “world” to the player as green text.

There’s only one bit of code that we’ve changed, so it should be pretty quick to go over.

ChatColor.GREEN + – There’s actually two things going on here. First off, we have ChatColor.GREEN. This is just telling the server to switch the chat color to Green. The + symbol is called a concatenation symbol. concatenation symbols are used to connect things together. In this case, we’re combining the color green, with the string “world”.

REMEMBER, if you get an error, always check to see what the error is be hovering over it in Eclipse. Often times, like in this case, you just have to click on import. In this case, we have to import org.bukkit.ChatColor.

You may have noticed that as you typed “ChatColor.”, a list of colors came up in Eclipse. This the same feature that you saw. Eclipse is trying to guess what you want to type next. In fact, Eclipse gives you a full list of colors that you can use, as well as some other formatting options you can use. For an example, you could try ChatColor.BLUE for blue text, or you could do ChatColor.BOLD to make the text bold. Seems pretty easy, right? Well, that’s probably because it is. But what if you want to use multiple colors at once? Well, that’s pretty easy to do as well. For an example, if we wanted to output “world” like this: “world”, we would make our code like this.

This time, we just have three concatenations rather than one like before. We could also have multiple words of different colors. For an example

Notice, there is a space after the string “Hello”. That is because concatenations don’t add spaces. You have to insert them yourself.

Be the first to comment

Leave a Reply

Your email address will not be published.


*