Paper: Uppercase Color Codes Incorrectly Handled

Created on 7 Dec 2018  路  8Comments  路  Source: PaperMC/Paper

What behavior is expected:

Both uppercase and lowercase color codes should be expected to validate when used in plugins or chat (搂e would be the same as using 搂E and &a would be the same as using &A)

What behavior is observed:

The console just spits out the color code without parsing it. Sometimes, it glitches and repeats certain characters. However, the game itself parses the color code correctly.

Steps/models to reproduce:

  1. Create a dummy plugin with a line in it like System.out.println("搂EHi);
  2. Type a message like &ETest in the chat (Essentials installed)

Plugin list:

  • EssentialsX
  • EssentialsX-Chat
  • A custom plugin with the aforementioned line in it

Paper build number:

git-Paper-474 (MC: 1.13.2) (Implementing API version 1.13.2-R0.1-SNAPSHOT)

Anything else:

Translation of color codes in individual plugins to lower-case may solve this issue temporarily, and testing was done in a Spigot 1.13 server, and the issue didn't occur there.

Images of the issue occurring:

issue1
issue2
issue3

bug

Most helpful comment

Turns out Bukkit is a piece of junk and accepts uppercase too. -.-

All 8 comments

Always used lowercase color codes. (I think, like everyone else)

Yeah, I don't think we're going to accept this - this has been the behaviour for years, and it is common knowledge to most people that the legacy formatting codes are lowercase-only.

Turns out Bukkit is a piece of junk and accepts uppercase too. -.-

I did manage to mitigate this issue in my own plugin. All it requires is simple regex in the following snippet:

public static String fixCodesToLowerCase(String codeStr){
    //Create a StringBuilder to hold the input string
    StringBuilder codeSB = new StringBuilder(codeStr);

    //Set the pattern to use on the string (section sign + color code)
    Pattern codePtn = Pattern.compile("\\u00A7[A-FK-OR]", Pattern.CASE_INSENSITIVE);

    //Create the matcher to use on the input string
    Matcher codeMatch = codePtn.matcher(codeSB);

    //Loop through the matcher finds
    while(codeMatch.find()){
        //Transform the finds to lower case, but leave everything else alone
        String tmpStr = codeSB.substring(codeMatch.start(), codeMatch.end()).toLowerCase();

        //Replace the entries in the substring
        codeSB = codeSB.replace(codeMatch.start(), codeMatch.end(), tmpStr);
    }

    //Return the fixed string
    return codeSB.toString();
}

Yeah, we can fix on our plugins but the problem is where the player can customize your chats like using other plugins like nicknames from Essentials or from PlaceholdersAPI tags.

An example:
https://prnt.sc/m39uo9

The first two line is from same player who sayd the last two messages. She just set the nickname using Essentials with &DGOD

So this is only causing problems in the console?

Frankly, if everyone was using translateAlternateColorCodes, this wouldn't happen, because it transforms all formatting codes to lower case:
https://github.com/Bukkit/Bukkit/blob/f210234e59275330f83b994e199c76f6abd41ee7/src/main/java/org/bukkit/ChatColor.java#L208-L211

Nevertheless, if the MC client accepts upper case color codes, then TerminalConsoleAppender needs to be fixed to accept the same.

Resolved pending a new release of TerminalConsoleAppender

This is fixed in the 1.14.x builds. Probably not going to get backported to 1.13.2 due to some issues with Windows in that version.

Was this page helpful?
0 / 5 - 0 ratings