Update getPerverts to be in the DisguiseUtilities
This commit is contained in:
parent
562785e54b
commit
25471787aa
@ -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<Object> 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<Object> 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<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
|
||||
*/
|
||||
|
@ -232,7 +232,7 @@ public class FlagWatcher {
|
||||
StructureModifier<Object> 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);
|
||||
|
@ -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<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) {
|
||||
List<TargetedDisguise> dis = new ArrayList<TargetedDisguise>();
|
||||
for (HashSet<TargetedDisguise> disguises : getDisguises().values()) {
|
||||
|
Loading…
Reference in New Issue
Block a user