Attempt to fix a tracker exception
This commit is contained in:
parent
6546dd256e
commit
6e69ae6fe2
@ -982,6 +982,7 @@ public class DisguiseUtilities {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO Store reflection field
|
||||
Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry);
|
||||
|
||||
// If the tracker exists. Remove himself from his tracker
|
||||
@ -991,7 +992,7 @@ public class DisguiseUtilities {
|
||||
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
|
||||
|
||||
for (Object p : trackedPlayers) {
|
||||
Player player = (Player) ReflectionManager.getBukkitEntity(p);
|
||||
Player player = (Player) ReflectionManager.getBukkitEntity(ReflectionManager.getTrackerPlayer(p));
|
||||
|
||||
if (player == disguise.getEntity() || disguise.canSee(player)) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket);
|
||||
@ -1188,6 +1189,7 @@ public class DisguiseUtilities {
|
||||
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
|
||||
|
||||
if (entityTrackerEntry != null) {
|
||||
// TODO Store reflection field
|
||||
Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry);
|
||||
trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent
|
||||
// ConcurrentModificationException
|
||||
@ -1701,6 +1703,7 @@ public class DisguiseUtilities {
|
||||
if (entityTrackerEntry != null) {
|
||||
Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry);
|
||||
|
||||
// TODO Store the fields
|
||||
final Method clear = ReflectionManager
|
||||
.getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear", ReflectionManager.getNmsClass("EntityPlayer"));
|
||||
|
||||
@ -1710,7 +1713,8 @@ public class DisguiseUtilities {
|
||||
trackedPlayers = (Set) new HashSet(trackedPlayers).clone();
|
||||
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
|
||||
|
||||
for (final Object p : trackedPlayers) {
|
||||
for (final Object o : trackedPlayers) {
|
||||
Object p = ReflectionManager.getTrackerPlayer(o);
|
||||
Player player = (Player) ReflectionManager.getBukkitEntity(p);
|
||||
|
||||
if (disguise.getEntity() != player && disguise.canSee(player)) {
|
||||
@ -1822,6 +1826,7 @@ public class DisguiseUtilities {
|
||||
|
||||
if (entityTrackerEntry != null) {
|
||||
|
||||
// TODO Store reflection fields
|
||||
// If the tracker exists. Remove himself from his tracker
|
||||
if (!runningPaper) {
|
||||
Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry);
|
||||
@ -2360,6 +2365,7 @@ public class DisguiseUtilities {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO Store reflection fields
|
||||
// Check for code differences in PaperSpigot vs Spigot
|
||||
if (!runningPaper) {
|
||||
// Add himself to his own entity tracker
|
||||
@ -2385,6 +2391,7 @@ public class DisguiseUtilities {
|
||||
boolean isMoving = false;
|
||||
|
||||
try {
|
||||
// TODO Store the field
|
||||
Field field = ReflectionManager.getNmsClass("EntityTrackerEntry")
|
||||
.getDeclaredField(NmsVersion.v1_17.isSupported() ? "r" : NmsVersion.v1_14.isSupported() ? "q" : "isMoving");
|
||||
field.setAccessible(true);
|
||||
|
@ -104,6 +104,7 @@ public class ReflectionManager {
|
||||
private static Constructor mobEffectConstructor;
|
||||
private static Method boundingBoxMethod;
|
||||
private static Method bukkitEntityMethod;
|
||||
private static Method connectionEntityMethod;
|
||||
private static Field noDamageTicks;
|
||||
private static Method isInvul;
|
||||
private static Object genericDamage;
|
||||
@ -196,6 +197,7 @@ public class ReflectionManager {
|
||||
villagerProfessionRegistry = getNmsField("IRegistry", "ap").get(null);
|
||||
villagerTypeRegistry = getNmsField("IRegistry", "ao").get(null);
|
||||
playerConnection = getNmsField("EntityPlayer", "b");
|
||||
connectionEntityMethod = getNmsMethod("PlayerConnection", "d");
|
||||
} else {
|
||||
villagerProfessionRegistry = getNmsField("IRegistry", "VILLAGER_PROFESSION").get(null);
|
||||
villagerTypeRegistry = getNmsField("IRegistry", "VILLAGER_TYPE").get(null);
|
||||
@ -596,6 +598,21 @@ public class ReflectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object getTrackerPlayer(Object nmsEntity) {
|
||||
try {
|
||||
if (NmsVersion.v1_17.isSupported()) {
|
||||
// Convert from player connection to EntityPlayer
|
||||
nmsEntity = connectionEntityMethod.invoke(nmsEntity);
|
||||
}
|
||||
|
||||
return nmsEntity;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Entity getBukkitEntity(Object nmsEntity) {
|
||||
try {
|
||||
return (Entity) bukkitEntityMethod.invoke(nmsEntity);
|
||||
|
Loading…
Reference in New Issue
Block a user