1.12.2 Help with changing nametags

Discussion in 'Spigot Plugin Development' started by davidclue, Mar 6, 2020.

  1. Code (Text):
    private void setPlayerName(Player p, String nick) {
            EntityPlayer changeName = ((CraftPlayer)p).getHandle();
            changeName.displayName = ChatColor.translateAlternateColorCodes('&', nick);
            for (Player all : Bukkit.getServer().getOnlinePlayers()) {
                PlayerConnection connection = ((CraftPlayer)all).getHandle().playerConnection;
                connection.sendPacket(new PacketPlayOutNamedEntitySpawn(changeName));
            }
        }
    I'm not sure why but that code doesn't work and I don't get why but it's supposed to change a targeted players name tag.
     
  2. It doesn't intake a EntityPlayer, but a EntityHuman for one of the constructors.
     
  3. why don't just use the spigot API and do
    player.setDisplayName("&athis is color");
    (if i was managed to help you please rep me)
     
  4. For one there's no such thing as a rep and you can't say to give you reactions in response of a potential correct answer, but yes that's a way but you forgot to include the translate as it's not built in.
     
  5. No that only changes the name displayed when they chat but I’m trying to make it change there name tag above there head
     
  6. So is it the changename.displayName constructor or I should change the EntityPlayer to EntityHuman instead