[SPIGOT-6310] Entity#setCustomName limit cutting off colors Created: 09/Jan/21  Updated: 09/Jan/21

Status: Open
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: Shane Bee Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: None

Attachments: PNG File Screen Shot 2021-01-08 at 4.49.28 PM.png    
Version: n/a
Guidelines Read: Yes

 Description   

As one of the devs of Skript, it was recently brought to my attention that setting entity names with HEX color codes was extremely limited in length.

After doing some testing to make sure this was true, I took at look at the source code and found this:

@Override
public void setCustomName(String name) {
    // sane limit for name length
    if (name != null && name.length() > 256) {
        name = name.substring(0, 256);
    }

    getHandle().setCustomName(CraftChatMessage.fromStringOrNull(name));
}

https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java#762

As seen here, the length is limited without accounting for color codes. As we all know, HEX color codes can be quite long, so if using multiple HEX color codes for different parts of a string, you are extremely limited in the possible length you can use.

Doing some fun testing, when bypassing this limit, if I had 1000 characters, this failed to save the chunk as the name was too long.

Doing another test, with 256 characters (each with a different color code) the chunk saved/loaded with no issues. This shows me that 256 characters each with a different hex color code is very possible to achieve (see picture below - its a bunch of armor stands with 256 coloured character names)



 Comments   
Comment by Black Hole [ 09/Jan/21 ]

So using ChatColor.stripColor() to compare the length could be used here.

The maximum JSON text length that could be saved in NBT is 65535.

Generated at Sat Apr 05 09:53:40 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.