Get name from displayname... HELP!

Discussion in 'Plugin Development' started by stelar7, Sep 16, 2011.

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

    stelar7

    so I've got this code here: http://pastie.org/2544512

    As far a i know it should work, but it does not...

    Why, Why!, WHY!!!?
     
  2. Offline

    nisovin

    Does the display name have colors? If it does you won't be able to type it in properly.
     
  3. Offline

    DrAgonmoray

    Yeah. There's invisible symbols that looks like this: ยง
    After the symbol there's a letter or number (0-9a-f) that give text the color. You'll probably want to get rid of all those sequences.
     
  4. Offline

    bergerkiller

    Yup, @nisovin is right. Try to strip the display name of colors and then using equals.
    Code:
                String dname = ChatColor.stripColor(p.getDisplayName());
                if (dname.equalsIgnoreCase(args[0])) {
                    sender.sendMessage(dname + " is " + p.getName());
                    return true;
                }
    Or you can use contains on the 'to lower cased' strings.
    Code:
    public static boolean match(String value, String comparer) {
        value = value.toLowerCase();
        comparer = comparer.toLowerCase();
        return value.contains(comparer);
    }
     
  5. Offline

    DrAgonmoray

    Ooh, I didn't know about stripColor.
    Learn somethin' new every day, eh? :D
     
  6. Offline

    bergerkiller

    It basically does this:
    Code:
    return input.replaceAll("(?i)\u00A7[0-F]", "");
    No idea how it works, but it works. :D
     
    DrAgonmoray likes this.
  7. Offline

    DrAgonmoray

    string patterns is one of the great mysteries of java
     
Thread Status:
Not open for further replies.

Share This Page