Fix dying while disguised creating problems
This commit is contained in:
		| @@ -394,16 +394,9 @@ public class DisguiseListener implements Listener { | |||||||
|         DisguiseUtilities.saveDisguises(player.getUniqueId(), disguises); |         DisguiseUtilities.saveDisguises(player.getUniqueId(), disguises); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|     @EventHandler |     @EventHandler | ||||||
|     public void onRespawn(PlayerRespawnEvent event) { |     public void onRespawn(PlayerRespawnEvent event) { | ||||||
|         Disguise[] disguises = DisguiseAPI.getDisguises(event.getPlayer()); |  | ||||||
|  |  | ||||||
|         for (Disguise disguise : disguises) { |  | ||||||
|             if (disguise.isRemoveDisguiseOnDeath()) { |  | ||||||
|                 disguise.removeDisguise(); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         if (DisguiseConfig.isBedPacketsEnabled()) { |         if (DisguiseConfig.isBedPacketsEnabled()) { | ||||||
|             final Player player = event.getPlayer(); |             final Player player = event.getPlayer(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -203,11 +203,6 @@ public abstract class Disguise { | |||||||
|  |  | ||||||
|                         if (isRemoveDisguiseOnDeath()) { |                         if (isRemoveDisguiseOnDeath()) { | ||||||
|                             removeDisguise(); |                             removeDisguise(); | ||||||
|                         } else { |  | ||||||
|                             entity = null; |  | ||||||
|                             watcher = getWatcher().clone(disguise); |  | ||||||
|                             task.cancel(); |  | ||||||
|                             task = null; |  | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } else { |                 } else { | ||||||
| @@ -489,105 +484,105 @@ public abstract class Disguise { | |||||||
|      * @return removeDiguise |      * @return removeDiguise | ||||||
|      */ |      */ | ||||||
|     public boolean removeDisguise() { |     public boolean removeDisguise() { | ||||||
|         if (disguiseInUse) { |         if (!isDisguiseInUse()) | ||||||
|             UndisguiseEvent event = new UndisguiseEvent(entity, this); |             return false; | ||||||
|  |  | ||||||
|             Bukkit.getPluginManager().callEvent(event); |         UndisguiseEvent event = new UndisguiseEvent(entity, this); | ||||||
|  |  | ||||||
|             if (!event.isCancelled() || (getEntity() instanceof Player && !((Player) getEntity()).isOnline())) { |         Bukkit.getPluginManager().callEvent(event); | ||||||
|                 disguiseInUse = false; |  | ||||||
|  |  | ||||||
|                 if (task != null) { |         // If this disguise is not in use, and the entity isnt a player | ||||||
|                     task.cancel(); |         if (event.isCancelled() && (!(getEntity() instanceof Player) || ((Player) getEntity()).isOnline())) | ||||||
|                     task = null; |             return false; | ||||||
|  |  | ||||||
|  |         disguiseInUse = false; | ||||||
|  |  | ||||||
|  |         if (task != null) { | ||||||
|  |             task.cancel(); | ||||||
|  |             task = null; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // If this disguise has a entity set | ||||||
|  |         if (getEntity() != null) { | ||||||
|  |             if (this instanceof PlayerDisguise) { | ||||||
|  |                 PlayerDisguise disguise = (PlayerDisguise) this; | ||||||
|  |  | ||||||
|  |                 if (disguise.isDisplayedInTab()) { | ||||||
|  |                     PacketContainer deleteTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); | ||||||
|  |                     deleteTab.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER); | ||||||
|  |                     deleteTab.getPlayerInfoDataLists().write(0, Collections.singletonList( | ||||||
|  |                             new PlayerInfoData(disguise.getGameProfile(), 0, NativeGameMode.SURVIVAL, | ||||||
|  |                                     WrappedChatComponent.fromText(disguise.getName())))); | ||||||
|  |  | ||||||
|  |                     try { | ||||||
|  |                         for (Player player : Bukkit.getOnlinePlayers()) { | ||||||
|  |                             if (!((TargetedDisguise) this).canSee(player) || | ||||||
|  |                                     (!isSelfDisguiseVisible() && getEntity() == player)) | ||||||
|  |                                 continue; | ||||||
|  |  | ||||||
|  |                             ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab); | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                     catch (InvocationTargetException e) { | ||||||
|  |                         e.printStackTrace(); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             // If this disguise is active | ||||||
|  |             // Remove the disguise from the current disguises. | ||||||
|  |             if (DisguiseUtilities.removeDisguise((TargetedDisguise) this)) { | ||||||
|  |                 if (getEntity() instanceof Player) { | ||||||
|  |                     DisguiseUtilities.removeSelfDisguise((Player) getEntity()); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 HashMap<UUID, HashSet<TargetedDisguise>> disguises = DisguiseUtilities.getDisguises(); |                 // Better refresh the entity to undisguise it | ||||||
|  |                 if (getEntity().isValid()) { | ||||||
|                 // If this disguise has a entity set |                     DisguiseUtilities.refreshTrackers((TargetedDisguise) this); | ||||||
|                 if (getEntity() != null) { |  | ||||||
|                     if (this instanceof PlayerDisguise) { |  | ||||||
|                         PlayerDisguise disguise = (PlayerDisguise) this; |  | ||||||
|  |  | ||||||
|                         if (disguise.isDisplayedInTab()) { |  | ||||||
|                             PacketContainer deleteTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); |  | ||||||
|                             deleteTab.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER); |  | ||||||
|                             deleteTab.getPlayerInfoDataLists().write(0, Collections.singletonList( |  | ||||||
|                                     new PlayerInfoData(disguise.getGameProfile(), 0, NativeGameMode.SURVIVAL, |  | ||||||
|                                             WrappedChatComponent.fromText(disguise.getName())))); |  | ||||||
|  |  | ||||||
|                             try { |  | ||||||
|                                 for (Player player : Bukkit.getOnlinePlayers()) { |  | ||||||
|                                     if (!((TargetedDisguise) this).canSee(player)) |  | ||||||
|                                         continue; |  | ||||||
|  |  | ||||||
|                                     ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab); |  | ||||||
|                                 } |  | ||||||
|                             } |  | ||||||
|                             catch (InvocationTargetException e) { |  | ||||||
|                                 e.printStackTrace(); |  | ||||||
|                             } |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|  |  | ||||||
|                     // If this disguise is active |  | ||||||
|                     // Remove the disguise from the current disguises. |  | ||||||
|                     if (DisguiseUtilities.removeDisguise((TargetedDisguise) this)) { |  | ||||||
|                         if (getEntity() instanceof Player) { |  | ||||||
|                             DisguiseUtilities.removeSelfDisguise((Player) getEntity()); |  | ||||||
|                         } |  | ||||||
|  |  | ||||||
|                         // Better refresh the entity to undisguise it |  | ||||||
|                         if (getEntity().isValid()) { |  | ||||||
|                             DisguiseUtilities.refreshTrackers((TargetedDisguise) this); |  | ||||||
|                         } else { |  | ||||||
|                             DisguiseUtilities.destroyEntity((TargetedDisguise) this); |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|  |  | ||||||
|                     if (isHidePlayer() && getEntity() instanceof Player && ((Player) getEntity()).isOnline()) { |  | ||||||
|                         PlayerInfoData playerInfo = new PlayerInfoData( |  | ||||||
|                                 ReflectionManager.getGameProfile((Player) getEntity()), 0, |  | ||||||
|                                 NativeGameMode.fromBukkit(((Player) getEntity()).getGameMode()), WrappedChatComponent |  | ||||||
|                                 .fromText(DisguiseUtilities.getPlayerListName((Player) getEntity()))); |  | ||||||
|  |  | ||||||
|                         PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); |  | ||||||
|  |  | ||||||
|                         addTab.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER); |  | ||||||
|                         addTab.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfo)); |  | ||||||
|  |  | ||||||
|                         try { |  | ||||||
|                             for (Player player : Bukkit.getOnlinePlayers()) { |  | ||||||
|                                 if (!((TargetedDisguise) this).canSee(player)) |  | ||||||
|                                     continue; |  | ||||||
|  |  | ||||||
|                                 ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab); |  | ||||||
|                             } |  | ||||||
|                         } |  | ||||||
|                         catch (InvocationTargetException e) { |  | ||||||
|                             e.printStackTrace(); |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                 } else { |                 } else { | ||||||
|                     // Loop through the disguises because it could be used with a unknown entity id. |                     DisguiseUtilities.destroyEntity((TargetedDisguise) this); | ||||||
|                     HashMap<Integer, HashSet<TargetedDisguise>> future = DisguiseUtilities.getFutureDisguises(); |                 } | ||||||
|  |             } | ||||||
|  |  | ||||||
|                     Iterator<Integer> itel = DisguiseUtilities.getFutureDisguises().keySet().iterator(); |             if (isHidePlayer() && getEntity() instanceof Player && ((Player) getEntity()).isOnline()) { | ||||||
|  |                 PlayerInfoData playerInfo = new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), | ||||||
|  |                         0, NativeGameMode.fromBukkit(((Player) getEntity()).getGameMode()), | ||||||
|  |                         WrappedChatComponent.fromText(DisguiseUtilities.getPlayerListName((Player) getEntity()))); | ||||||
|  |  | ||||||
|                     while (itel.hasNext()) { |                 PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); | ||||||
|                         int id = itel.next(); |  | ||||||
|  |  | ||||||
|                         if (future.get(id).remove(this) && future.get(id).isEmpty()) { |                 addTab.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER); | ||||||
|                             itel.remove(); |                 addTab.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfo)); | ||||||
|                         } |  | ||||||
|  |                 try { | ||||||
|  |                     for (Player player : Bukkit.getOnlinePlayers()) { | ||||||
|  |                         if (!((TargetedDisguise) this).canSee(player) || | ||||||
|  |                                 (!isSelfDisguiseVisible() && getEntity() == player)) | ||||||
|  |                             continue; | ||||||
|  |  | ||||||
|  |                         ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  |                 catch (InvocationTargetException e) { | ||||||
|  |                     e.printStackTrace(); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } else { | ||||||
|  |             // Loop through the disguises because it could be used with a unknown entity id. | ||||||
|  |             HashMap<Integer, HashSet<TargetedDisguise>> future = DisguiseUtilities.getFutureDisguises(); | ||||||
|  |  | ||||||
|                 return true; |             Iterator<Integer> itel = DisguiseUtilities.getFutureDisguises().keySet().iterator(); | ||||||
|  |  | ||||||
|  |             while (itel.hasNext()) { | ||||||
|  |                 int id = itel.next(); | ||||||
|  |  | ||||||
|  |                 if (future.get(id).remove(this) && future.get(id).isEmpty()) { | ||||||
|  |                     itel.remove(); | ||||||
|  |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return false; |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -804,7 +799,8 @@ public abstract class Disguise { | |||||||
|  |  | ||||||
|                 try { |                 try { | ||||||
|                     for (Player player : Bukkit.getOnlinePlayers()) { |                     for (Player player : Bukkit.getOnlinePlayers()) { | ||||||
|                         if (!((TargetedDisguise) this).canSee(player)) |                         if (!((TargetedDisguise) this).canSee(player) || | ||||||
|  |                                 (!isSelfDisguiseVisible() && getEntity() == player)) | ||||||
|                             continue; |                             continue; | ||||||
|  |  | ||||||
|                         ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab); |                         ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab); | ||||||
| @@ -844,7 +840,8 @@ public abstract class Disguise { | |||||||
|  |  | ||||||
|             try { |             try { | ||||||
|                 for (Player player : Bukkit.getOnlinePlayers()) { |                 for (Player player : Bukkit.getOnlinePlayers()) { | ||||||
|                     if (!((TargetedDisguise) this).canSee(player)) |                     if (!((TargetedDisguise) this).canSee(player) || | ||||||
|  |                             (!isSelfDisguiseVisible() && getEntity() == player)) | ||||||
|                         continue; |                         continue; | ||||||
|  |  | ||||||
|                     ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab); |                     ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user