player.getDisplayName() crashing client

Discussion in 'Plugin Development' started by Nodren, Feb 9, 2011.

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

    Nodren

    As a plugin developer, i've experienced this several times: I utilize player.getDisplayName() in one of my player.sendMessage() commands. this will crash the player's minecraft client. Server elicits no exception over the behavior. Meanwhile, the person who's getDisplayName() crashed someone's client, can easily chat or do other things with out issue.

    I've had this happen in numerous situations, and have suggested to users it's bad formatting on another plugin author's part. but I don't believe that to be true. What is actually causing this behavior, and how can I prevent it from crashing a person's client?
     
  2. Offline

    jrobert755

    I believe it is a ChatColor that is causing the problem. If a player's display name's color has been changed, it adds characters to the display name. Trying to send these characters to the client seems to crash the client. The easiest way to fix it is to remove the characters from the display name before sending it to the client. This is what I use to do it, and it has worked fine for me:

    Code:
    String display_name = player.getDisplayName();
    for(int i = 0; i < 16; i++){
        display_name = display_name.replaceAll(String.format("\u00A7%x", i), "");
    }
    Edit: Apparently, ending the line sent to the client with a ChatColor code, it causes the client to crash. There is a bug submitted on leaky.bukkit.org with this problem.
     
Thread Status:
Not open for further replies.

Share This Page