Solved Overwrite ChatColor and formatting on nickname

Discussion in 'Spigot Plugin Development' started by MimoBot, Feb 12, 2020.

  1. I am trying to output a players nickname and username in one string but it seems that whatever formatting the nickname has is overriding the formatting I add. For example, if the players nickname is red in-game, it appears as red when I print out the string, regardless of the ChatColor function I use. How can I force the ChatColor I specify to the one color the text appears as? Here is the bit of code in question:

    Code (Text):
    usernameNickname = "" + ChatColor.WHITE + ess.getUser(p).getNickname().toString() + ChatColor.WHITE + " - " + ess.getUser(p).getName().toString();
    Maybe get the nickname as just the nickname string, without any extra formatting?
     
  2. chatcolor.reset is what youre looking for. this will reset the formatting from text before it so it does not apply to text after it.
     
  3. getNickname() might come with a chat color embedded in it.
    You can try
    Code (Java):
    usernameNickname = "" + ChatColor.WHITE + ChatColor.stripColor(ess.getUser(p).getNickname().toString()) + ChatColor.WHITE + " - " + ess.getUser(p).getName().toString();
    or a cleaned up version:
    Code (Java):
    usernameNickname = "" + ChatColor.stripColor(ess.getUser(p).getNickname() +  " - " + ess.getUser(p).getName());
     
    #3 ForbiddenSoul, Feb 13, 2020
    Last edited: Feb 13, 2020
    • Agree Agree x 2
  4. That did the trick, thank you. It was frustrating me to no end that I couldn't get the formatting to work correctly.
     
  5. Please mark this thread as solved so others know that you're no longer looking for help.