Changing a player's Nametag, and TabList name

Discussion in 'Spigot Plugin Development' started by JordanOsterberg, May 15, 2015.

  1. Hello, today I was asked to make a /disguise command for a project. I would like to know if there is a way I can chnage a player's nametag, and tablist name. Thank you!
  2. Use Scoreboard Team prefixes.
  3. @TheTrollzJ
    To change the TabList name you would use the method:
    Player#setPlayerListName(String name);
    Specifically what do you mean by changing the player's nametag? As in the player's name in chat?
  4. I mean changing the player's nametag, so it doesn't display their actual name.
  5. @TheTrollzJ
    Well people can already do that with the Essentials /nick command which most servers have but if you want to add that functionality, you'd use this method:
    Player#setDisplayName(String name);
  6. No he doesn't mean the display name he means the thingy above a players head!
  7. Use an API? :p That's the only easy way to change the nametag.
  8. If you want to change the name above a player's head, I think there is currently no api either from bukkit/spigot nor through any plugin. You'll have to handle with packets, preferably with ProtocolLib
  9. A disguise plugin could be difficult to work out. The most powerful way to make a Disguise plugin is using ProtocolLib and a bit of NMS but you have to know how Minecraft works internally.

    Any Player (in NMS, EntityPlayer) has linked in the client and server side a GameProfile (which is a class of the Mojang's AuthLib that defines a player name, UUID and skin). When a player has spawned, this GameProfile in the client is inmutable and, of course, you can't change it. So, to disguise a player, you have to despawn the player, and then respawn it with a new GameProfile (an invented one).

    To replace a GameProfile in the spawn packet you have to register a ProtocolLib PacketAdapter (see its wiki). There you should intercept the packet PacketPlayOutNamedEntitySpawn (that is the used to spawn a player) and replace its original GameProfile with the disguised GameProfile.

    And just to trigger that, you have to respawn the player:

    Code (Text):
     for (Player wx : disguise.getWorld().getPlayers())
                Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
                    public void run() {
                         for (Player wx : disguise.getWorld().getPlayers())
                }, 10L);
    I say again that make a disguise plugin can be tricky and so long to post it here :p
  10. .....or just download Lib's Disguises plugin and use its API to do whatever u want :D
    • Funny Funny x 2
    • Like Like x 1