Hi, I’m discovering Sponge and I’m a bit lost. I’m trying to set player’s displayname on the join event.
@Listener
public void onPlayerJoin(ClientConnectionEvent.Join e){
Player p = e.getTargetEntity();
p.offer(Keys.DISPLAY_NAME, Text.of("§cTEST"));
}
But it doesn’t work
btw sorry for the raw posting. I don’t know how to format the code posting here.
Hi. So to format code on the forums, just add 4 spaces before the line. It uses Markup (same as github) so any github cheatsheet will work on here.
As for your code, it looks solid. When you say display name how do you mean? The name that appears in chat or the name above the head of the player.
A thing i would like to note is you shouldnt use Text.of unless you need to (its not in API 8 as far as im aware) so you should use the text builder
Text.builder("test").color(TextColor.RED).build()
That key isn’t implemented on players.
1 Like
First of all, thnx for your answers. Those informations are very useful. Next I would like to change player name over his head an in chat too.
If that key is not available for player. Is there a way to do it on sponge?
The display name over the players head is done though client. So sadly you cannot change it without modifying the client. The only way around it would be if you wanted to add prefix/suffix to the display name in which case you could use teams scoreboards to display that.
OK thnx for the info, BTW I did some spigot dev before and there is a function to deal with it. Why sponge did add something like that?
Ive been developing Bukkit plugins too, there was never a way to handle the above player name without using NMS where you sent a human entity with the new name to the client. As for why Sponge hasn’t done that, they dont add API for hacky things.
Due to forge support, Sponge cannot make some assumptions that Bukkit can. So you will find there is API within Bukkit that is missing (for good reason) in Sponge (One example of this would be that in Bukkit you can send text on a sign to a specific player, Bukkit creates a tileEntity of the sign and then sends that directly to the player. Sponge cannot do that as the creation of tile entities require a block to hold that data and so on which intervines with Forge which means it would break support for some mods). With that being said there is some API that is missing from Sponge that could be there, in which case make a issue on github about the missing API.
If your thinking of player.setDisplayName() from bukkit, that was for chat only which is allowed. I thought your code would do that but I’m wrong. It maybe a case that you need to hook into a chat plugin to make the changes, or it could be something to do with MessageChannel (its something I havent looked too much into)
Thnx.
Last point tp check if I understand the scoreboard team correctly. I can only add a prefix and a suffix to a player name with it. I cannot repalce player name value on the display ?
You can only add prefix and suffix
1 Like