Solved NMS / Changing name above the head

Discussion in 'Plugin Development' started by PumpMelon, Dec 13, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    PumpMelon

    Hello Bukkit,

    Title says it all. I'm not really that famaliar with NMS, and if someone can point me in the direction that would be appreciated. In particular I'm looking to change the player name above the head. (I have looked this up and most posts are outdated).

    Thanks,
     
  2. Player#setCustomName(Name);
     
  3. Offline

    FabeGabeMC

    @Zombie_Striker
    That will change the player's custom name in chat, not up in their head.
    I think the class @PumpMelon is looking for is PacketPlayOutNamedEntitySpawn, iirc.
    I have been dormant for almost 7 months, so please excuse any mistakes I may make referencing classes.
    However, if you are only going to change the player's name COLOR, I suggest just using the Scoreboard/Teams Classes already bundled into Bukkit.
     
  4. Offline

    PumpMelon

    Yes, though I need to do more than just color.
    Would I just need to use that class?
     
  5. Offline

    FabeGabeMC

    @PumpMelon Yea, plus, you need to use the GameProfile class to apply textures and what-not.
     
  6. Offline

    PumpMelon

    @FabeGabeMC
    Think you could point me where / what I would need to do, all I have is the class but no idea what to do with it.

    Still could use a hand of what to do, thanks

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 17, 2016
  7. Offline

    PumpMelon

    Hello,
    So I got this method but it doesn't seem like its working with 1.10, I modified a bit of it just so it'll compile but here it is

    Code:
    public static void setCustomName(Player player, String name) {
            for (Player online : Bukkit.getOnlinePlayers()) {
                if (!(online.equals(player))) {
                    PacketPlayOutEntityDestroy despawn = new PacketPlayOutEntityDestroy(player.getEntityId());
                    PacketPlayOutNamedEntitySpawn spawn = new PacketPlayOutNamedEntitySpawn(((CraftPlayer) player).getHandle());
                    try {
                        Field b = spawn.getClass().getDeclaredField("b");
                        b.setAccessible(true);
                        b.set(spawn, new GameProfile(player.getUniqueId(), name));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
    
                    ((CraftPlayer) online).getHandle().playerConnection.sendPacket(despawn);
                    ((CraftPlayer) online).getHandle().playerConnection.sendPacket(spawn);
                }
            }
        }
    
     
  8. @PumpMelon
    What does not work? Does the player still exist? Does the name change?
     
  9. Offline

    PumpMelon

    No, the name does not change and yes? the player still exists as in me being the player. I set this in a join event.
     
  10. Offline

    AlvinB

    @PumpMelon
    Have you checked the console? You should be getting some Reflection Exceptions, as the "b" field in PacketPlayOutNamedEntitySpawn is not a GameProfile, but a UUID.
     
Thread Status:
Not open for further replies.

Share This Page