Solved ChatColor and formats

Discussion in 'Spigot Plugin Development' started by bys1, May 12, 2016.

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

    Is it true that ChatColor.translateAlternateColorCodes() and ChatColor.stripColors() only translate/strip colors, and not formats (&k &l &m &n &o)?
    If so, how to translate or strip formats?
  2. I'm pretty sure it includes the formats.
    You can read the Javadocs on it if you'd like.
    • Agree Agree x 1
  3. But &e&l didn't work for me
  4. I'm just going by the Javadocs but maybe if I could see the code you are using I'd be able to figure it out.
  5. conversation
  6. It does indeed strip/translate format codes. If it is not working for you show the relevant code.
  7. No iea what you said but im just saying
    String text = "&cHello There, &rnormal &9blue";
    String new = ChatColor.translateAlternateColorCodes("&", text);
  8. Wouldn't it be:
    Code (Text):
    String new = ChatColor.translateAlternateColorCodes('&', text);
    with single quotes around &..
    • Agree Agree x 1
  9. sent it in conversation
  10. Sorry my power went out <,<
    Could you tell me what happens when you try to set the player's name? Does it only set the color or only the format?
  11. Well I notice your never passing the nickname to the stripUnallowedCodes method here "setNick(args[0],player);"
    Does this code output as expected?
    Code (Text):

    sender.sendMessage(ChatColor.GREEN + player.getName() + "'s nickname has been changed to "
        + ChatColor.translateAlternateColorCodes('&', stripUnallowedCodes(args[0],player)));
  12. only color
  13. Try reversing the order of the codes when you type out the nickname and see if it works.
  14. My code is changing the player's nick and also sending the cmd sender a message with the new nick. But it only translates colors but not formats and magic
  15. already tried that
  16. Right, but I was just saying you're never stripping or translating the code from the nick here "setNick(args[0],player);" so that will never show anything other than the original string.

    As for the other part I will test.
  17. Did you view my setNick() method? The setNick() method does that for me
  18. Got it sorry I am pretty tired.
  19. But I still don't understand why it doesn't translate the formats properly.
  20. Are you importing the correct ChatColor? There is a bungee and a bukkit one, you need to import the bukkit one.
Thread Status:
Not open for further replies.