Change Text above players head

I was looking for a method doing this…
I know, that it is possible to change the Text above a player.
My questions:

  1. How can I change the name (add something like a prefix) above a players head?
  2. How can I edit / add a second line? (like in plugins, showing players health in the second line above their head)
    Thanks :slight_smile:

But that’s a pretty old post … maybe something changed? ^^

1 Like

That is done with scoreboards … you can set a scoreboard-display below the players name

1 Like

okey, I got it :smiley: Seems like I have to work with the data API, thanks for helping me! :smiley:

Wait… Thats not a scoreboard!
I want to add a new line under the players name, which is above the players head (character). I was wondering, why this “named” scoreboards, but you really mean scoreboards :smile:
player.offer(Keys.DISPLAY_NAME, Text.of("test")); is not working for me…

It IS a scoreboard …

And if player.offer(Keys.DISPLAY_NAME, Text.of("test")); is not working i don’t know how/if you can change the name…

Okey, thats new to me :smiley:
I tried it like this:

Scoreboard scoreboard = Sponge.getGame().getRegistry().createBuilder(Scoreboard.Builder.class).build();
Objective obj = Sponge.getGame().getRegistry().createBuilder(Objective.Builder.class).criterion(Criteria.DUMMY).build();
scoreboard.updateDisplaySlot(obj, DisplaySlots.BELOW_NAME);

… but when I use this code, nothing happens…

Another thing, I do not understand is, why player.getDisplayNameData().displayName().set(Text.of("new_name")); shows no effect…

And this is the moment where i can’t help you further because i’ve never worked with scoreboards before… shame on me :smiley:

Someone else? ^^

1 Like

getDisplayNameData and displayName return copies of their internal stored values. What you need to do is something like this:

DisplayNameData data = player.getDisplayNameData();

Or you can shorten it to:

player.set(Keys.DISPLAY_NAME, Text.of("new_name"));

When I use this code, nothing happens…

public void onPlayerJoin(ClientConnectionEvent.Join event) {
    Player player = event.getTargetEntity();
    DisplayNameData data = player.getDisplayNameData();
    data.set(data.displayName().set(Text.of("Player " + player.getName())));

What’s the return value of player.offer(data);?

1 Like
1 Like

Okey, do you know, how to add a scoreboard under the playername, that displays the players uuid (just an example)?
I know, how to add one, but here I described my problem with them:

@TrentTech He’s talking about above the player’s head.

I know but I’m saying this player.set(Keys.DISPLAY_NAME, Text.of(“new_name”)); isn’t going to work

which is why the join event above does nothing

Yeah, I know, this is the reason, why I want to use scoreboards, but there is a problem too. I linked my other topic in my last post :slightly_smiling:

maybe the src in this project might help

1 Like

I was looking at this plugin a few days ago, and there was no source code, lol :smile:
But thanks, I will give it a try :slight_smile:

I forgot the link. It’s now added.

Both player features is done with scoreboards. I’ll try to explain what I did. I hope you understand it.


This can be done with the scoreboard teams. Just create a team (registerTeam) and add the player who should own the prefix and/or suffix (addMember). Then you could add the prefix and suffix with setPrefix() and setSuffix() on the team object. Keep in mind that this text shouldn’t be longer than 16 characters.

Create a objective with the displayslot BELOW_NAME. The display name of the objective is the name under the playername so in this case “Health” in red.Then add your player to the objective with getOrCreateScore(Texts.of(playerName) with the value (setScore) it should display before the display name like in the image 12.


I’ll bookmark this! This will definitely be handy later!