Solved kick

Discussion in 'Spigot Plugin Development' started by M7MDMCGamer, May 2, 2017.

  1. 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
     
  2. I've never used color for kick messages but try ChatColor or ยง
     
  3. Use chat color. You can translate color codes with a char and a string, using a method in ChatColor like ChatColor.translateAlternateColorCodes('&', kickmessagewithcolors);
     
  4. what code will be where to place
    Code (Java):
    ChatColor.translateAlternateColorCodes('&', kickmessagewithcolors);
     
  5. It's and example, don't copy paste...
     
  6. its my first time see this ChatColor.translateAlternateColorCodes('&', kickmessagewithcolors); how to use it
     
  7. 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!
     
    #7 xPlumpOrange, May 2, 2017
    Last edited: May 2, 2017
  8. 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.
     
  9. 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'
     
  10. 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.
     
  11. I wasn't the one to suggest color code translate, he did ask how to use it, he said "I'm new to translateAlternateColorCodes'
     
  12. 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.