I was looking for a method doing this…
I know, that it is possible to change the Text above a player.
My questions:
How can I change the name (add something like a prefix) above a players head?
How can I edit / add a second line? (like in plugins, showing players health in the second line above their head)
Thanks
Blue
January 8, 2016, 2:59pm
2
Hello, i want to change the name of the player when he joins a game…
(exemple: i want a player named Marc with color red)
i want if it’s possible to change the name over the player, and the tablist…
i saw an server did it…
thx
But that’s a pretty old post … maybe something changed? ^^
1 Like
Blue
January 8, 2016, 3:03pm
3
That is done with scoreboards … you can set a scoreboard-display below the players name
1 Like
okey, I got it Seems like I have to work with the data API, thanks for helping me!
Blue:
scoreboard-display
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
player.offer(Keys.DISPLAY_NAME, Text.of("test"));
is not working for me…
Blue
January 8, 2016, 3:39pm
6
It IS a scoreboard … http://minecraft.gamepedia.com/Scoreboard#Display_slots
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
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();
obj.setDisplayName(Text.of("lel"));
scoreboard.addObjective(obj);
player.setScoreboard(scoreboard);
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…
Blue
January 8, 2016, 4:18pm
8
And this is the moment where i can’t help you further because i’ve never worked with scoreboards before… shame on me
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();
data.set(data.displayName().set(Text.of("new_name"));
player.offer(data);
Or you can shorten it to:
player.set(Keys.DISPLAY_NAME, Text.of("new_name"));
When I use this code, nothing happens…
@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event) {
Player player = event.getTargetEntity();
DisplayNameData data = player.getDisplayNameData();
data.set(data.displayName().set(Text.of("Player " + player.getName())));
player.offer(data);
}
What’s the return value of player.offer(data);
?
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:
Hey,
I created a topic, asking how to add a scoreboard.
Now I know, that I can create a scoreboard with following code:
Scoreboard scoreboard = Sponge.getGame().getRegistry().createBuilder(Scoreboard.Builder.class).build();
Objective obj = Sponge.getGame().getRegistry().createBuilder(Objective.Builder.class).criterion(Criteria.DUMMY).name("Village-Name").displayName(Text.of("Village-Name")).build();
obj.setDisplayName(Text.of(player.getName()));
scoreboard.addObjective…
@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
maybe the src in this project might help
HealthName
Description
This plugins display the health of players or mobs above their head.
Links
Github - Source Code
Download
Please leave star on Github or a like/comment on this thread. Feel free to clone, fork or contribute to this repository.
Features
Works without client modifications
You can customize the character which will be displayed in the healthbar
Works with mobs and players
Config
# Show health bar above mobs
enabledMob=true
# Show the health of a player besides his nameta…
1 Like
I was looking at this plugin a few days ago, and there was no source code, lol
But thanks, I will give it a try
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.
Hitzk0pf:
How can I change the name (add something like a prefix) above a players head?
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.
Builder newMessageBuilder = Text.builder(oldMessage, "");
for (Text child : oldMessage.getChildren()) {
if (child instanceof LiteralText) {
String content = ((LiteralText) child).getContent();
String newContent = content.replace(String.valueOf(settings.getConfig().getDisplayChar()), "");
newMessageBuilder.append(Text.builder(child, newContent).build());
continue;
}
newMessageBuilder.append(child);
}
deathEntityEvent.setMessage(newMessageBuilder.build());
}
}
private void updateHealth(double maxHealth, double newHealth, Entity targetEntity) {
Text healthMessage = generateHealthMessage(newHealth, maxHealth);
if (targetEntity.getType() == EntityTypes.PLAYER) {
Player targetPlayer = (Player) targetEntity;
String playerName = targetPlayer.getName();
Hitzk0pf:
How can I edit / add a second line? (like in plugins, showing players health in the second line above their head)
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.
Living targetEntity = deathEntityEvent.getTargetEntity();
if (!deathEntityEvent.isMessageCancelled()) {
//clear entity properties
if (targetEntity.getType() == EntityTypes.PLAYER) {
Player targetPlayer = (Player) targetEntity;
Scoreboard playerScoreboard = targetPlayer.getScoreboard();
String playerName = targetPlayer.getName();
playerScoreboard.getTeam(playerName).ifPresent(Team::unregister);
} else if (targetEntity.supports(Keys.DISPLAY_NAME)) {
targetEntity.remove(Keys.DISPLAY_NAME);
}
//clean message
Text oldMessage = deathEntityEvent.getMessage();
Builder newMessageBuilder = Text.builder(oldMessage, "");
for (Text child : oldMessage.getChildren()) {
if (child instanceof LiteralText) {
String content = ((LiteralText) child).getContent();
String newContent = content.replace(String.valueOf(settings.getConfig().getDisplayChar()), "");
3 Likes
Blue
January 9, 2016, 6:00pm
20
I’ll bookmark this! This will definitely be handy later!
2 Likes