Player Changing Name Tag

Discussion in 'Spigot Plugin Development' started by solarnova921, May 18, 2018.

  1. Hi, I made a plugin that changes a players name above their head, but it sends to everyone but me. when I remove the check in the loop if it's sending the packet to me, it summons an npe with my skin and the selected name above it's head, but I can't move. how would I make it so that it changes my nametag and I can see it and move? (like with 5zig)
    here is my code:

    Code (Text):
    for(Player p : Bukkit.getOnlinePlayers()) {
                if(p == player) continue;
                ((CraftPlayer)p).getHandle().playerConnection.sendPacket((Packet) new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, ((CraftPlayer)player).getHandle()));
                GameProfile gp = ((CraftPlayer)p).getProfile();
                 try {
                        Field nameField = GameProfile.class.getDeclaredField("name");
                        Field modifiersField = Field.class.getDeclaredField("modifiers");
                        modifiersField.setInt(nameField, nameField.getModifiers() & ~Modifier.FINAL);

                        nameField.set(gp, newName);
                    } catch (IllegalAccessException | NoSuchFieldException ex) {
                        throw new IllegalStateException(ex);

Share This Page