Set player display name (without Scoreboard)?

How I can set player display name?
I writed this:

@Listener(order = Order.PRE) public void nick(MessageChannelEvent.Chat event) { String plain = event.getRawMessage().toPlain(); Player player = event.getCause().first(Player.class).get(); if (plain.equals("NICK1")) { DisplayNameData data = player.getDisplayNameData(); data.displayName().set(Text.of("TESTNICK")); player.offer(data); player.sendMessage(Text.of("Successfully set nick!")); } else if (plain.equals("NICK2")) { player.offer(Keys.DISPLAY_NAME, Text.of("TESTNICK2")); player.sendMessage(Text.of("Successfully set nick!2")); } }
I got messages (when typing “NICK1” or “NICK2” to chat), but my display name not changed…

In some variations your attempt should work. But this is just easier:

player.offer(Keys.DISPLAY_NAME, Text.of("nick"))

Edit: If you want to register commands, read this: https://docs.spongepowered.org/master/en/plugin/commands/index.html

Yes,I tried this too:

} else if (plain.equals("NICK2")) { player.offer(Keys.DISPLAY_NAME, Text.of("TESTNICK2")); player.sendMessage(Text.of("Successfully set nick!2")); }
I got message, but display name do not changes…

Oh, sorry, I read too fast :wink:

The displayname is the name of the player entity, over the head, not in the chat. Is it what you want?

Yes, I want change nickname over the head.
I joined the server from two accounts, in one account writed “NICK1” got message “Successfully set nick!” and checked my nickname over the head from second account, nothing changes. Same when I writed “NICK2”.
(Sorry for my bad English :-()

Setting name over head isn’t implemented yet because it isn’t something the server can’t do naturally. Sponge would need to do a “hack” (for lack of a better word) to make this work.

5 Likes