This commit is contained in:
libraryaddict 2021-06-26 05:37:30 +12:00
parent fe166bdbea
commit 5ab0e4a45c
2 changed files with 13 additions and 11 deletions

View File

@ -1035,7 +1035,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(ReflectionManager.getTrackerPlayer(p)); Player player = (Player) ReflectionManager.getBukkitEntity(ReflectionManager.getPlayerFromPlayerConnection(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);
@ -1237,7 +1237,7 @@ public class DisguiseUtilities {
trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent
// ConcurrentModificationException // ConcurrentModificationException
for (Object p : trackedPlayers) { for (Object p : trackedPlayers) {
Player player = (Player) ReflectionManager.getBukkitEntity(p); Player player = (Player) ReflectionManager.getBukkitEntity(ReflectionManager.getPlayerFromPlayerConnection(p));
if (((TargetedDisguise) disguise).canSee(player)) { if (((TargetedDisguise) disguise).canSee(player)) {
players.add(player); players.add(player);
@ -1636,7 +1636,8 @@ public class DisguiseUtilities {
trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent
// ConcurrentModificationException // ConcurrentModificationException
for (final Object p : trackedPlayers) { for (final Object o : trackedPlayers) {
Object p = ReflectionManager.getPlayerFromPlayerConnection(o);
Player pl = (Player) ReflectionManager.getBukkitEntity(p); Player pl = (Player) ReflectionManager.getBukkitEntity(p);
if (pl == null || !player.equalsIgnoreCase((pl).getName())) { if (pl == null || !player.equalsIgnoreCase((pl).getName())) {
@ -1689,7 +1690,8 @@ public class DisguiseUtilities {
trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent
// ConcurrentModificationException // ConcurrentModificationException
for (final Object p : trackedPlayers) { for (final Object o : trackedPlayers) {
Object p = ReflectionManager.getPlayerFromPlayerConnection(o);
Player player = (Player) ReflectionManager.getBukkitEntity(p); Player player = (Player) ReflectionManager.getBukkitEntity(p);
if (player != entity) { if (player != entity) {
@ -1757,7 +1759,7 @@ public class DisguiseUtilities {
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId()); PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
for (final Object o : trackedPlayers) { for (final Object o : trackedPlayers) {
Object p = ReflectionManager.getTrackerPlayer(o); Object p = ReflectionManager.getPlayerFromPlayerConnection(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)) {
@ -1874,10 +1876,10 @@ public class DisguiseUtilities {
if (!runningPaper) { if (!runningPaper) {
Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry); Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry);
((Set<Object>) trackedPlayersObj).remove(ReflectionManager.getEntityTrackerInstance(player)); ((Set<Object>) trackedPlayersObj).remove(ReflectionManager.getPlayerConnectionOrPlayer(player));
} else { } else {
((Map<Object, Object>) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap").get(entityTrackerEntry)) ((Map<Object, Object>) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap").get(entityTrackerEntry))
.remove(ReflectionManager.getEntityTrackerInstance(player)); .remove(ReflectionManager.getPlayerConnectionOrPlayer(player));
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
@ -2414,10 +2416,10 @@ public class DisguiseUtilities {
// Add himself to his own entity tracker // Add himself to his own entity tracker
Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry); Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry);
((Set<Object>) trackedPlayersObj).add(ReflectionManager.getEntityTrackerInstance(player)); ((Set<Object>) trackedPlayersObj).add(ReflectionManager.getPlayerConnectionOrPlayer(player));
} else { } else {
Field field = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap"); Field field = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap");
Object nmsEntity = ReflectionManager.getEntityTrackerInstance(player); Object nmsEntity = ReflectionManager.getPlayerConnectionOrPlayer(player);
Map<Object, Object> map = ((Map<Object, Object>) field.get(entityTrackerEntry)); Map<Object, Object> map = ((Map<Object, Object>) field.get(entityTrackerEntry));
map.put(nmsEntity, true); map.put(nmsEntity, true);
} }

View File

@ -446,7 +446,7 @@ public class ReflectionManager {
return -1; return -1;
} }
public static Object getEntityTrackerInstance(Player player) { public static Object getPlayerConnectionOrPlayer(Player player) {
try { try {
if (NmsVersion.v1_17.isSupported()) { if (NmsVersion.v1_17.isSupported()) {
return playerConnection.get(getNmsEntity(player)); return playerConnection.get(getNmsEntity(player));
@ -598,7 +598,7 @@ public class ReflectionManager {
return null; return null;
} }
public static Object getTrackerPlayer(Object nmsEntity) { public static Object getPlayerFromPlayerConnection(Object nmsEntity) {
try { try {
if (NmsVersion.v1_17.isSupported()) { if (NmsVersion.v1_17.isSupported()) {
// Convert from player connection to EntityPlayer // Convert from player connection to EntityPlayer