Hi,
I have been having developing a plugin to manage player nicknames. I am getting close to the end one thing I have not been able to figure out is well… changing the player’s display name. I have browsed some other posts on the forum and the data API in the documents and found that these 2 examples should work in theory
DisplayNameData displayNameData = player.getDisplayNameData();
displayNameData.displayName().set(Text.of("test"));
DataTransactionResult result1 = player.offer(displayNameData);
DataTransactionResult result2 = player.offer(Keys.DISPLAY_NAME, Text.of("test"));
Optional<Text> name = player.get(Keys.DISPLAY_NAME);
The first result returns FAILURE, the 2nd one SUCCES, the optional name still contains the original player name.
Is anyone would be able to help me out. Either I am as blind as a mole or something broke.
I am using spongevanilla-1.10.2-5.1.0-BETA-355
Solution as of 3th Nov 2016
There is no good implementation yet in the api. If you want to change the display name in the chat, the best thing you can do is edit the header of a message to the following format:
header: ’<Displayed name> ’ (space at the end)
body: untouched
footer: untouched
If I recall this isn’t possible yet. It only works for mob entities. I think there’s a way to change players display name above player in game using scoreboards but havent looked into it
I guess I should clearify what my intend is, My aim is to change the name displayed in chat. I can override the header of a text message but I believe that is considered bad practice.
Updated the title to clearify aswell.
Bad practice? News to me being the developer of SimpleTags. As far as I know it’s currently the only way. I actually looked into the same thing a while back and was informed that it’s not yet possible to do this with DisplayNameData.
1 Like
That is dissapointing.
I took a quick peep at your code and correct me if I am wrong, but if I would want my plugin te be able to co-exist along side yours I would need to override the header before yours.
So this means that any chat overhaul plugin needs to take to account that the header may already be changed by others. Which would also means, the best I can do to to simply override the name as early as possible > Order.EARLY since that is the first writable event according to the documentation.
1 Like
Sounds about right. It’s quite a pain. I’m actually dealing with issues with attempting to detect the players display name without knowing if something has already modified it. Its basically hit or miss but it’s either that or completely replace the header entirely but that opens up doors to more incompatibilities with other mods and plugins. That’s exactly why I was looking into DisplayNameData to eliminate the unknowns. Modifying the header is great for adding tags or prefixes but not so much for dealing with what’s already there. I suppose calling it bad practice is an apt description.
For what it’s worth you can always listen at any of the read-only event ordering.
I’ve not delved into renaming players display names, but I agree that having this in the actual API in some form would make this a lot easier, would also enable cross plugin support for tab-completion / specifying names that are nick names or display names only.
Thanks for the help, I have marked this as solved now.