From e65613e7507c43bac574bf6eaf896556d96f9423 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 4 Sep 2014 15:08:17 +1200 Subject: [PATCH] Send destroy packet as well. Can't trust mojang to properly send their packets --- .../disguise/utilities/DisguiseUtilities.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 3a344ce0..252228ca 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -530,9 +530,11 @@ public class DisguiseUtilities { public static void refreshTracker(final TargetedDisguise disguise, String player) { if (disguise.getEntity() != null && disguise.getEntity().isValid()) { try { + PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId()); if (disguise.isDisguiseInUse() && disguise.getEntity() instanceof Player && ((Player) disguise.getEntity()).getName().equalsIgnoreCase(player)) { removeSelfDisguise((Player) disguise.getEntity()); + ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), destroyPacket); Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { public void run() { try { @@ -554,8 +556,10 @@ public class DisguiseUtilities { ReflectionManager.getNmsClass("EntityPlayer")); HashSet cloned = (HashSet) trackedPlayers.clone(); for (final Object p : cloned) { - if (player.equalsIgnoreCase(((Player) ReflectionManager.getBukkitEntity(p)).getName())) { + Player pl = (Player) ReflectionManager.getBukkitEntity(p); + if (player.equalsIgnoreCase((pl).getName())) { clear.invoke(entityTrackerEntry, p); + ProtocolLibrary.getProtocolManager().sendServerPacket(pl, destroyPacket); Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { public void run() { try { @@ -582,6 +586,7 @@ public class DisguiseUtilities { public static void refreshTrackers(Entity entity) { if (entity.isValid()) { try { + PacketContainer destroyPacket = getDestroyPacket(entity.getEntityId()); final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(entity); if (entityTrackerEntry != null) { HashSet trackedPlayers = (HashSet) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get( @@ -595,6 +600,7 @@ public class DisguiseUtilities { Player player = (Player) ReflectionManager.getBukkitEntity(p); if (player != entity) { clear.invoke(entityTrackerEntry, p); + ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket); Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { public void run() { try { @@ -618,9 +624,11 @@ public class DisguiseUtilities { */ public static void refreshTrackers(final TargetedDisguise disguise) { if (disguise.getEntity().isValid()) { + PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId()); try { if (selfDisguised.contains(disguise.getEntity().getUniqueId()) && disguise.isDisguiseInUse()) { removeSelfDisguise((Player) disguise.getEntity()); + ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), destroyPacket); Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { public void run() { try { @@ -644,6 +652,7 @@ public class DisguiseUtilities { Player player = (Player) ReflectionManager.getBukkitEntity(p); if (disguise.getEntity() != player && disguise.canSee(player.getName())) { clear.invoke(entityTrackerEntry, p); + ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket); Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { public void run() { try { @@ -662,6 +671,12 @@ public class DisguiseUtilities { } } + public static PacketContainer getDestroyPacket(int... ids) { + PacketContainer destroyPacket = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY); + destroyPacket.getIntegerArrays().write(0, ids); + return destroyPacket; + } + public static boolean removeDisguise(TargetedDisguise disguise) { UUID entityId = disguise.getEntity().getUniqueId(); if (getDisguises().containsKey(entityId) && getDisguises().get(entityId).remove(disguise)) {