From cb58cdd8d3aaecaa42cf2799d189b15bcb4097ee Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 28 Feb 2014 10:59:22 +1300 Subject: [PATCH] Added convidence method for me to use in other plugins --- .../disguise/utilities/DisguiseUtilities.java | 65 ++++++++++++++----- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 3980f9a3..cf164405 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -294,6 +294,39 @@ public class DisguiseUtilities { } } + /** + * @param A convidence method for me to refresh trackers in other plugins + */ + public static void refreshTrackers(Entity entity) { + try { + Object world = ReflectionManager.getWorld(entity.getWorld()); + Object tracker = world.getClass().getField("tracker").get(world); + Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker); + Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class) + .invoke(trackedEntities, entity.getEntityId()); + if (entityTrackerEntry != null) { + HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers") + .get(entityTrackerEntry); + Method clear = entityTrackerEntry.getClass().getMethod("clear", ReflectionManager.getNmsClass("EntityPlayer")); + Method updatePlayer = entityTrackerEntry.getClass().getMethod("updatePlayer", + ReflectionManager.getNmsClass("EntityPlayer")); + HashSet cloned = (HashSet) trackedPlayers.clone(); + for (Object p : cloned) { + Player player = (Player) ReflectionManager.getBukkitEntity(p); + // if (entity instanceof Player && !((Player) ReflectionManager.getBukkitEntity(player)).canSee((Player) + // entity)) + // continue; + if (!(entity instanceof Player) || player.canSee((Player) entity)) { + clear.invoke(entityTrackerEntry, p); + updatePlayer.invoke(entityTrackerEntry, p); + } + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + /** * @param Resends * the entity to all the watching players, which is where the magic begins @@ -386,22 +419,6 @@ public class DisguiseUtilities { } } - /** - * Method to send a packet to the self disguise, translate his entity ID to the fake id. - */ - private static void sendSelfPacket(Player player, PacketContainer packet, int fakeId) { - PacketContainer[] packets = PacketsManager.transformPacket(packet, player, player); - try { - for (PacketContainer p : packets) { - p = p.deepClone(); - p.getIntegers().write(0, fakeId); - ProtocolLibrary.getProtocolManager().sendServerPacket(player, p, false); - } - } catch (InvocationTargetException e) { - e.printStackTrace(); - } - } - /** * Sends the self disguise to the player */ @@ -507,6 +524,22 @@ public class DisguiseUtilities { } } + /** + * Method to send a packet to the self disguise, translate his entity ID to the fake id. + */ + private static void sendSelfPacket(Player player, PacketContainer packet, int fakeId) { + PacketContainer[] packets = PacketsManager.transformPacket(packet, player, player); + try { + for (PacketContainer p : packets) { + p = p.deepClone(); + p.getIntegers().write(0, fakeId); + ProtocolLibrary.getProtocolManager().sendServerPacket(player, p, false); + } + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + /** * Setup it so he can see himself when disguised */