Fixed switching to non-self disguise freezing players

This commit is contained in:
libraryaddict 2019-08-13 20:32:13 +12:00
parent aec78e2321
commit 0c4262a6ff

View File

@ -1132,7 +1132,6 @@ public class DisguiseUtilities {
return; return;
} }
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
try { try {
if (selfDisguised.contains(disguise.getEntity().getUniqueId()) && disguise.isDisguiseInUse()) { if (selfDisguised.contains(disguise.getEntity().getUniqueId()) && disguise.isDisguiseInUse()) {
@ -1140,6 +1139,8 @@ public class DisguiseUtilities {
selfDisguised.add(disguise.getEntity().getUniqueId()); selfDisguised.add(disguise.getEntity().getUniqueId());
PacketContainer destroyPacket = getDestroyPacket(DisguiseAPI.getSelfDisguiseId());
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), destroyPacket); ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), destroyPacket);
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> { Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
@ -1165,6 +1166,7 @@ public class DisguiseUtilities {
.getNmsMethod("EntityTrackerEntry", "b", ReflectionManager.getNmsClass("EntityPlayer")); .getNmsMethod("EntityTrackerEntry", "b", ReflectionManager.getNmsClass("EntityPlayer"));
trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); trackedPlayers = (Set) new HashSet(trackedPlayers).clone();
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
for (final Object p : trackedPlayers) { for (final Object p : trackedPlayers) {
Player player = (Player) ReflectionManager.getBukkitEntity(p); Player player = (Player) ReflectionManager.getBukkitEntity(p);
@ -1256,8 +1258,7 @@ public class DisguiseUtilities {
// If the tracker exists. Remove himself from his tracker // If the tracker exists. Remove himself from his tracker
if (isHashSet(trackedPlayersObj)) { if (isHashSet(trackedPlayersObj)) {
((Set<Object>) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") ((Set<Object>) trackedPlayersObj).remove(ReflectionManager.getNmsEntity(player));
.get(entityTrackerEntry)).remove(ReflectionManager.getNmsEntity(player));
} else { } else {
((Map<Object, Object>) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap") ((Map<Object, Object>) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap")
.get(entityTrackerEntry)).remove(ReflectionManager.getNmsEntity(player)); .get(entityTrackerEntry)).remove(ReflectionManager.getNmsEntity(player));
@ -1548,8 +1549,7 @@ public class DisguiseUtilities {
// Check for code differences in PaperSpigot vs Spigot // Check for code differences in PaperSpigot vs Spigot
if (isHashSet(trackedPlayersObj)) { if (isHashSet(trackedPlayersObj)) {
((Set<Object>) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") ((Set<Object>) trackedPlayersObj).add(ReflectionManager.getNmsEntity(player));
.get(entityTrackerEntry)).add(ReflectionManager.getNmsEntity(player));
} else { } else {
((Map<Object, Object>) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap") ((Map<Object, Object>) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayerMap")
.get(entityTrackerEntry)).put(ReflectionManager.getNmsEntity(player), true); .get(entityTrackerEntry)).put(ReflectionManager.getNmsEntity(player), true);