From 25471787aae4c689d274917e7fb7c68a66992b98 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 24 Dec 2013 17:30:39 +1300 Subject: [PATCH] Update getPerverts to be in the DisguiseUtilities --- .../disguise/disguisetypes/Disguise.java | 32 ++----------------- .../disguise/disguisetypes/FlagWatcher.java | 4 +-- .../disguise/utilities/DisguiseUtilities.java | 27 ++++++++++++++++ 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index b16b25ee..63f01e20 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -2,7 +2,6 @@ package me.libraryaddict.disguise.disguisetypes; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -237,7 +236,7 @@ public abstract class Disguise { } try { Field ping = ReflectionManager.getNmsClass("EntityPlayer").getField("ping"); - for (Player player : getPerverts()) { + for (Player player : DisguiseUtilities.getPerverts(disguise)) { PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_VELOCITY); StructureModifier mods = packet.getModifier(); if (getEntity() == player) { @@ -268,7 +267,7 @@ public abstract class Disguise { PacketContainer packet = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE); StructureModifier mods = packet.getModifier(); mods.write(0, getEntity().getEntityId()); - for (Player player : getPerverts()) { + for (Player player : DisguiseUtilities.getPerverts(disguise)) { if (DisguiseAPI.isViewDisguises() || getEntity() != player) { try { ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); @@ -291,33 +290,6 @@ public abstract class Disguise { return entity; } - /** - * Get all EntityPlayers who have this entity in their Entity Tracker And they are in the targetted disguise. - */ - protected ArrayList getPerverts() { - ArrayList players = new ArrayList(); - try { - Object world = ReflectionManager.getWorld(getEntity().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, getEntity().getEntityId()); - if (entityTrackerEntry != null) { - HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers") - .get(entityTrackerEntry); - for (Object p : trackedPlayers) { - Player player = (Player) ReflectionManager.getBukkitEntity(p); - if (((TargetedDisguise) this).canSee(player)) { - players.add(player); - } - } - } - } catch (Exception ex) { - ex.printStackTrace(); - } - return players; - } - /** * Get the disguise type */ diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index 9e453ac2..26f850be 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -232,7 +232,7 @@ public class FlagWatcher { StructureModifier mods = packet.getModifier(); mods.write(0, entity.getEntityId()); packet.getWatchableCollectionModifier().write(0, list); - for (Player player : getDisguise().getPerverts()) { + for (Player player : DisguiseUtilities.getPerverts(getDisguise())) { if (DisguiseAPI.isViewDisguises() || player != entity) { try { ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); @@ -315,7 +315,7 @@ public class FlagWatcher { mods.write(0, getDisguise().getEntity().getEntityId()); mods.write(1, slot); mods.write(2, itemToSend); - for (Player player : getDisguise().getPerverts()) { + for (Player player : DisguiseUtilities.getPerverts(getDisguise())) { if (player != getDisguise().getEntity()) { try { ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 14ae8d4b..d375230a 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -199,6 +199,33 @@ public class DisguiseUtilities { return new TargetedDisguise[0]; } + /** + * Get all EntityPlayers who have this entity in their Entity Tracker And they are in the targetted disguise. + */ + public static ArrayList getPerverts(Disguise disguise) { + ArrayList players = new ArrayList(); + try { + Object world = ReflectionManager.getWorld(disguise.getEntity().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, disguise.getEntity().getEntityId()); + if (entityTrackerEntry != null) { + HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers") + .get(entityTrackerEntry); + for (Object p : trackedPlayers) { + Player player = (Player) ReflectionManager.getBukkitEntity(p); + if (((TargetedDisguise) disguise).canSee(player)) { + players.add(player); + } + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + return players; + } + public static List getSeenDisguises(String viewer) { List dis = new ArrayList(); for (HashSet disguises : getDisguises().values()) {