Attempt to fix a tracker exception

This commit is contained in:
libraryaddict 2021-06-16 19:37:52 +12:00
parent 6546dd256e
commit 6e69ae6fe2
2 changed files with 26 additions and 2 deletions

View File

@ -982,6 +982,7 @@ public class DisguiseUtilities {
return; return;
} }
// TODO Store reflection field
Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry); Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry);
// If the tracker exists. Remove himself from his tracker // If the tracker exists. Remove himself from his tracker
@ -991,7 +992,7 @@ public class DisguiseUtilities {
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId()); PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
for (Object p : trackedPlayers) { 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)) { if (player == disguise.getEntity() || disguise.canSee(player)) {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket); ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket);
@ -1188,6 +1189,7 @@ public class DisguiseUtilities {
Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity()); Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
if (entityTrackerEntry != null) { if (entityTrackerEntry != null) {
// TODO Store reflection field
Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry); Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry);
trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent
// ConcurrentModificationException // ConcurrentModificationException
@ -1701,6 +1703,7 @@ public class DisguiseUtilities {
if (entityTrackerEntry != null) { if (entityTrackerEntry != null) {
Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry); Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry);
// TODO Store the fields
final Method clear = ReflectionManager final Method clear = ReflectionManager
.getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear", ReflectionManager.getNmsClass("EntityPlayer")); .getNmsMethod("EntityTrackerEntry", NmsVersion.v1_14.isSupported() ? "a" : "clear", ReflectionManager.getNmsClass("EntityPlayer"));
@ -1710,7 +1713,8 @@ public class DisguiseUtilities {
trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); trackedPlayers = (Set) new HashSet(trackedPlayers).clone();
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId()); 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); Player player = (Player) ReflectionManager.getBukkitEntity(p);
if (disguise.getEntity() != player && disguise.canSee(player)) { if (disguise.getEntity() != player && disguise.canSee(player)) {
@ -1822,6 +1826,7 @@ public class DisguiseUtilities {
if (entityTrackerEntry != null) { if (entityTrackerEntry != null) {
// TODO Store reflection fields
// If the tracker exists. Remove himself from his tracker // If the tracker exists. Remove himself from his tracker
if (!runningPaper) { if (!runningPaper) {
Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry); Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry);
@ -2360,6 +2365,7 @@ public class DisguiseUtilities {
return; return;
} }
// TODO Store reflection fields
// Check for code differences in PaperSpigot vs Spigot // Check for code differences in PaperSpigot vs Spigot
if (!runningPaper) { if (!runningPaper) {
// Add himself to his own entity tracker // Add himself to his own entity tracker
@ -2385,6 +2391,7 @@ public class DisguiseUtilities {
boolean isMoving = false; boolean isMoving = false;
try { try {
// TODO Store the field
Field field = ReflectionManager.getNmsClass("EntityTrackerEntry") Field field = ReflectionManager.getNmsClass("EntityTrackerEntry")
.getDeclaredField(NmsVersion.v1_17.isSupported() ? "r" : NmsVersion.v1_14.isSupported() ? "q" : "isMoving"); .getDeclaredField(NmsVersion.v1_17.isSupported() ? "r" : NmsVersion.v1_14.isSupported() ? "q" : "isMoving");
field.setAccessible(true); field.setAccessible(true);

View File

@ -104,6 +104,7 @@ public class ReflectionManager {
private static Constructor mobEffectConstructor; private static Constructor mobEffectConstructor;
private static Method boundingBoxMethod; private static Method boundingBoxMethod;
private static Method bukkitEntityMethod; private static Method bukkitEntityMethod;
private static Method connectionEntityMethod;
private static Field noDamageTicks; private static Field noDamageTicks;
private static Method isInvul; private static Method isInvul;
private static Object genericDamage; private static Object genericDamage;
@ -196,6 +197,7 @@ public class ReflectionManager {
villagerProfessionRegistry = getNmsField("IRegistry", "ap").get(null); villagerProfessionRegistry = getNmsField("IRegistry", "ap").get(null);
villagerTypeRegistry = getNmsField("IRegistry", "ao").get(null); villagerTypeRegistry = getNmsField("IRegistry", "ao").get(null);
playerConnection = getNmsField("EntityPlayer", "b"); playerConnection = getNmsField("EntityPlayer", "b");
connectionEntityMethod = getNmsMethod("PlayerConnection", "d");
} else { } else {
villagerProfessionRegistry = getNmsField("IRegistry", "VILLAGER_PROFESSION").get(null); villagerProfessionRegistry = getNmsField("IRegistry", "VILLAGER_PROFESSION").get(null);
villagerTypeRegistry = getNmsField("IRegistry", "VILLAGER_TYPE").get(null); villagerTypeRegistry = getNmsField("IRegistry", "VILLAGER_TYPE").get(null);
@ -596,6 +598,21 @@ public class ReflectionManager {
return null; 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) { public static Entity getBukkitEntity(Object nmsEntity) {
try { try {
return (Entity) bukkitEntityMethod.invoke(nmsEntity); return (Entity) bukkitEntityMethod.invoke(nmsEntity);