Update getPerverts to be in the DisguiseUtilities

This commit is contained in:
libraryaddict 2013-12-24 17:30:39 +13:00
parent 562785e54b
commit 25471787aa
3 changed files with 31 additions and 32 deletions

View File

@ -2,7 +2,6 @@ package me.libraryaddict.disguise.disguisetypes;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -237,7 +236,7 @@ public abstract class Disguise {
} }
try { try {
Field ping = ReflectionManager.getNmsClass("EntityPlayer").getField("ping"); 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); PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_VELOCITY);
StructureModifier<Object> mods = packet.getModifier(); StructureModifier<Object> mods = packet.getModifier();
if (getEntity() == player) { if (getEntity() == player) {
@ -268,7 +267,7 @@ public abstract class Disguise {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE); PacketContainer packet = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE);
StructureModifier<Object> mods = packet.getModifier(); StructureModifier<Object> mods = packet.getModifier();
mods.write(0, getEntity().getEntityId()); mods.write(0, getEntity().getEntityId());
for (Player player : getPerverts()) { for (Player player : DisguiseUtilities.getPerverts(disguise)) {
if (DisguiseAPI.isViewDisguises() || getEntity() != player) { if (DisguiseAPI.isViewDisguises() || getEntity() != player) {
try { try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
@ -291,33 +290,6 @@ public abstract class Disguise {
return entity; return entity;
} }
/**
* Get all EntityPlayers who have this entity in their Entity Tracker And they are in the targetted disguise.
*/
protected ArrayList<Player> getPerverts() {
ArrayList<Player> players = new ArrayList<Player>();
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 * Get the disguise type
*/ */

View File

@ -232,7 +232,7 @@ public class FlagWatcher {
StructureModifier<Object> mods = packet.getModifier(); StructureModifier<Object> mods = packet.getModifier();
mods.write(0, entity.getEntityId()); mods.write(0, entity.getEntityId());
packet.getWatchableCollectionModifier().write(0, list); packet.getWatchableCollectionModifier().write(0, list);
for (Player player : getDisguise().getPerverts()) { for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
if (DisguiseAPI.isViewDisguises() || player != entity) { if (DisguiseAPI.isViewDisguises() || player != entity) {
try { try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
@ -315,7 +315,7 @@ public class FlagWatcher {
mods.write(0, getDisguise().getEntity().getEntityId()); mods.write(0, getDisguise().getEntity().getEntityId());
mods.write(1, slot); mods.write(1, slot);
mods.write(2, itemToSend); mods.write(2, itemToSend);
for (Player player : getDisguise().getPerverts()) { for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
if (player != getDisguise().getEntity()) { if (player != getDisguise().getEntity()) {
try { try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);

View File

@ -199,6 +199,33 @@ public class DisguiseUtilities {
return new TargetedDisguise[0]; 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<Player> getPerverts(Disguise disguise) {
ArrayList<Player> players = new ArrayList<Player>();
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<TargetedDisguise> getSeenDisguises(String viewer) { public static List<TargetedDisguise> getSeenDisguises(String viewer) {
List<TargetedDisguise> dis = new ArrayList<TargetedDisguise>(); List<TargetedDisguise> dis = new ArrayList<TargetedDisguise>();
for (HashSet<TargetedDisguise> disguises : getDisguises().values()) { for (HashSet<TargetedDisguise> disguises : getDisguises().values()) {