Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-6310

Entity#setCustomName limit cutting off colors

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • None
    • None
    • n/a
    • Yes

      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)

            Unassigned Unassigned
            ShaneBee Shane Bee
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: