i want when player join it check the config if maintenance = true here is my code Code (Java): @EventHandler public void onJoin(PlayerJoinEvent e){ if(!config.getBoolean("maintenance")){ e.getPlayer().kickPlayer("Maintenance Mode Is Enabled Please Join Later."); } } my question is how to make the kick message colored
Use chat color. You can translate color codes with a char and a string, using a method in ChatColor like ChatColor.translateAlternateColorCodes('&', kickmessagewithcolors);
what code will be where to place Code (Java): ChatColor.translateAlternateColorCodes('&', kickmessagewithcolors);
its my first time see this ChatColor.translateAlternateColorCodes('&', kickmessagewithcolors); how to use it
You first obviously type that where the kick message would go then you type your message with & color code which is the color code essentials use for essentialchat. Example: ChatColor.translateAlternateColorCodes('&', "&4You Have Been Kicked!") Output: You Have Been Kicked!
Why do it that way? Typically I tend to do it that way if I am retrieving it from a configuration, so other owners of servers can change colour codes accordingly, but if I am looking to change the colour of text in-code, then you can just simply, in the place of a string, use ChatColor.colour So, Code (Text): @EventHandler public void onJoin(PlayerJoinEvent e){ if(!config.getBoolean("maintenance")){ e.getPlayer().kickPlayer(ChatColor.RED + "Maintenance Mode Is Enabled Please Join Later."); } } That would make the message red. There are also many other different variations.
I know but he asked how to use alternate color codes, and plus I feel like for what he is doing he should just use ChatColor.'Color'
No he didnt, he asked how to add colour to his kick message. Both methods work, but considering he is obviously new to the spigot API, suggesting to translate alternate colour codes, as even though it isnt difficult for me, may be difficult to him. It's easier to read and understand if he just uses ChatColor.color, as aforementioned and described above.
I wasn't the one to suggest color code translate, he did ask how to use it, he said "I'm new to translateAlternateColorCodes'
The guy who originally posted about translating colour codes didnt suggest it either. He said to use the ChatColor class, and gave an example of using it. That just happened to be the ChatColor#translateAlternateColorCodes method... He said he was new to it, which means, considering this is incredibly basic, is that you need to understand what he is actually after, and that is just simply finding out how to use colour in his messages. Both methods work, one was just more appropriate.