How to use UPDATE_DISPLAY_NAME with HEX colors
Luncaaa opened this issue · 2 comments
Make sure you're doing the following
- You're using the latest build for your server version
- This isn't an issue caused by another plugin
- You've checked for duplicate issues
- You didn't use
/reload
Describe the question
How can I HEX colors in use the PLAYER_INFO UPDATE_DISPLAY_NAME packet? I am trying to update the player's display name in TAB using HEX but only the last color code will appear. If, for example, I have §x§F§9§F§1§8§9Name
, the name will be blue because the last code is §9.
API method(s) used
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
Where packet is the PLAYER_INFO packet.
Expected behavior
The name in the tablist should be HEX.
Code
The packet that is being sent -> https://pastebin.com/cXw4DPQE
"newName" is the name that has the color codes. For example: §x§F§9§F§1§8§9Name
Additional context
I've tried using an external TAB plugin and placeholders and it did work, it only doesn't work when using packets.
You need to use WrappedChatComponent, from a legacy text (like you have) or, with a way more cleaner way, from json, e.g. with Adventure API (also work with the json serialize of BungeeCord chat api) :
private static PlayerInfoData getPlayerInfoData(Player player) {
return new PlayerInfoData(WrappedGameProfile.fromPlayer(player),
player.getPing(),
EnumWrappers.NativeGameMode.fromBukkit(player.getGameMode()),
WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(player.playerListName())),
WrappedProfilePublicKey.ofPlayer(player).getKeyData());
}