Adding color-codes too custom broadcast command?

Discussion in 'Plugin Development' started by TheNoobiestCrafters, Nov 3, 2012.

Thread Status:
Not open for further replies.
  1. Hello all, I have a custom broadcast command. But I would like it too be compatible with the & color codes so I can color the messages just like /broadcast in Essentials.

    Here's my code:
    Code:
    } else if (args.length >= 1) {
                        StringBuilder str = new StringBuilder(args[0]);
                          for(int i = 1; i < args.length; i++) {
                            str.append(' ').append(args[i]);
                        }
                        getServer().broadcastMessage(ChatColor.GRAY + "[" + ChatColor.BLUE + "Moderators" + ChatColor.GRAY + "] " + ChatColor.GREEN + str.toString());
                        return true;
                    }
     
  2. Offline

    ferrybig

    do
    translateAlternateColorCodes('&',str.toString())
    instead of just
    str.toString()
     
  3. Offline

    cman1885

    str.toString().replaceAll("&","§") works too.
     
  4. Offline

    devilquak

  5. Offline

    cman1885

    Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have two problems.
    -Jamie Zawinski.

    No need for regex when both mine and ferrybig's solutions work.
     
  6. Offline

    devilquak

    Huh, didn't ever think of those.
     
  7. Offline

    ferrybig

    you forgot the bold and other codes for chatcolors
     
  8. Offline

    devilquak

    I didn't forget them, I just never put them in, I made this before the other fonts were introduced.
     
  9. How could I add them in?
     
  10. Offline

    ferrybig

    1. use this code
    translateAlternateColorCodes('&',str.toString())
    2. or use this code, but you will need to readd chatcolors if theres more added in the future:
    str.toString().replaceAll("(&([a-fk-or0-9]))", "§$2");
     
Thread Status:
Not open for further replies.

Share This Page