Help with Packets

Discussion in 'Plugin Development' started by OppositeGamer, Aug 17, 2014.

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

    OppositeGamer

    Any idea why this isnt renaming the player??

    Code:
        public static void renamePlayer(Player player, String name) {
            PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(player.getPlayer().getEntityId());
            try {
                PacketPlayOutNamedEntitySpawn packet1 = new PacketPlayOutNamedEntitySpawn(((CraftPlayer) player).getHandle());
                Field profileField = packet1.getClass().getDeclaredField("b");
                profileField.setAccessible(true);
                profileField.set(packet1, new GameProfile(player.getUniqueId(), "haha"));
                profileField.setAccessible(false);
                for (Player p : Bukkit.getServer().getOnlinePlayers()) {
                    if (p != player) {
                        ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
                        ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet1);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
     
  2. Offline

    teej107

    OppositeGamer Use .equals() for comparing the value of objects. Not == or !=.
     
  3. Offline

    OppositeGamer

    Thanks for the reply, but I highly doubt that's the issue.
     
  4. Offline

    Forseth11

    teej107 is right. I have had that be the problem for me before.
     
  5. Offline

    _Filip

    teej107 His code would work because the two player objects are exactly the same.................
     
    xTrollxDudex likes this.
Thread Status:
Not open for further replies.

Share This Page