Checking message color

Discussion in 'Plugin Development' started by Maxx_Qc, Sep 21, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Maxx_Qc

    Hi guys, I just wanted to know if it was possible to get the color of a message.
    For exemple, the player send a message in red so we get the red to use it later.
    Thank you
     
  2. Offline

    Zombie_Striker

    @Maxx_Qc
    ChatColors are stored as such: §(0 - 9 and a - f): More HERE:

    Search through a string and see if it contains that character, and if it does, look to see what the char after it will be.
     
  3. Offline

    Maxx_Qc

    Well, doesn't seems to work...
    Code:
    public class PlayerChat implements Listener
    {
        private static String colorize(String string)
        {
           if (string == null) {
             return null;
           }
           return string.replaceAll("&([0-9a-z])", "§$1");
        }
    
        @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent e)
        {
            String messge = e.getMessage();
            e.setMessage(colorize(messge));
            if(messge.contains("§d")) {
                e.getPlayer().sendMessage("Did it worked?");
            }
        }
    }
    When I say "&dTest" or "&d Test" in the chat nothing happens.

    EDIT: GOT IT! THANK'S YOU

    Code:
    public class PlayerChat implements Listener
    {
        private static String colorize(String string)
        {
           if (string == null) {
             return null;
           }
           return string.replaceAll("&([0-9a-z])", "§$1");
        }
       
        @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent e)
        {
            String messge = e.getMessage();
            String newMessge = colorize(messge);
            e.setMessage(newMessge);
            if(newMessge.contains("§d")) {
                e.getPlayer().sendMessage("Did it worked?");
            }
        }
    }
     
  4. Offline

    Maxx_Qc

    Hello.
    Code:
    @EventHandler
        public void onChat(AsyncPlayerChatEvent event)
        {
            String newMessage = event.getMessage();
            String configsound = Config.getSound();
            String replacement = ChatColor.translateAlternateColorCodes('&', Config.getReplaceString());
    
            for (Player on : Bukkit.getServer().getOnlinePlayers())
            {
                if(on.hasPermission("nameshower.getnotified")) {
                    newMessage = newMessage.replaceAll("(?i)" + on.getName(), Main.colorize(replacement.replaceAll("%PLAYERNAME%", on.getName())));
                    if(Config.getEnableSound()) {
                        if (event.getMessage().toLowerCase().contains(on.getName().toLowerCase())) {
                            if(Config.getaLouder()) {
                                if(Config.getReplaceString().toLowerCase().contains("@")) {
                                    on.playSound(on.getLocation(), Sound.valueOf(configsound), 10.0F, 5.0F);
                                } else {
                                    on.playSound(on.getLocation(), Sound.valueOf(configsound), 3.0F, 5.0F);
                                }
                            } else {
                                on.playSound(on.getLocation(), Sound.valueOf(configsound), 10.0F, 5.0F);
                            }
                        }
                    }
                }
            }
            event.setMessage(newMessage);
        }
    Basically what my plugin does: when you say the name of a player in the chat, it becomes colored and the specified player received a sound. For exemple: Yo Maxx_Qc, will become Yo @Maxx_Qc and Maxx_Qc will get a notif-sound. What I want to do: I want to make that after the name, the color before come after.
    Let me show you with an example:
    [ACTUALLY] {ADMIN} yooo @Maxx_Qc what's up?
    {MAXX_QC} yoo @Admin, sup?
    The color after is red because we putted red in the config (ReplaceString: '&[email protected]%PLAYERNAME%&4').

    [WHAT I WANT] {ADMIN} yooo @Maxx_Qc what's up?
    {MAXX_QC} yoo @Admin, sup?
    The color after the same as before because we putted it in the config (ReplaceString: '&[email protected]%PLAYERNAME%&*').
    '&*' means 'use the same color as before' so the plugin is useful for every ranks.

    Thank you.
     
  5. Offline

    DoggyCode™

    Nice

    I don't see the difference?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  6. Offline

    Maxx_Qc

    Whatever the group, it uses the color used before the name after the name.
     
Thread Status:
Not open for further replies.

Share This Page