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,12 +484,17 @@ public abstract class Disguise { | |||||||
|      * @return removeDiguise |      * @return removeDiguise | ||||||
|      */ |      */ | ||||||
|     public boolean removeDisguise() { |     public boolean removeDisguise() { | ||||||
|         if (disguiseInUse) { |         if (!isDisguiseInUse()) | ||||||
|  |             return false; | ||||||
|  |  | ||||||
|         UndisguiseEvent event = new UndisguiseEvent(entity, this); |         UndisguiseEvent event = new UndisguiseEvent(entity, this); | ||||||
|  |  | ||||||
|         Bukkit.getPluginManager().callEvent(event); |         Bukkit.getPluginManager().callEvent(event); | ||||||
|  |  | ||||||
|             if (!event.isCancelled() || (getEntity() instanceof Player && !((Player) getEntity()).isOnline())) { |         // If this disguise is not in use, and the entity isnt a player | ||||||
|  |         if (event.isCancelled() && (!(getEntity() instanceof Player) || ((Player) getEntity()).isOnline())) | ||||||
|  |             return false; | ||||||
|  |  | ||||||
|         disguiseInUse = false; |         disguiseInUse = false; | ||||||
|  |  | ||||||
|         if (task != null) { |         if (task != null) { | ||||||
| @@ -502,8 +502,6 @@ public abstract class Disguise { | |||||||
|             task = null; |             task = null; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|                 HashMap<UUID, HashSet<TargetedDisguise>> disguises = DisguiseUtilities.getDisguises(); |  | ||||||
|  |  | ||||||
|         // If this disguise has a entity set |         // If this disguise has a entity set | ||||||
|         if (getEntity() != null) { |         if (getEntity() != null) { | ||||||
|             if (this instanceof PlayerDisguise) { |             if (this instanceof PlayerDisguise) { | ||||||
| @@ -518,7 +516,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, deleteTab); |                             ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab); | ||||||
| @@ -546,10 +545,9 @@ public abstract class Disguise { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (isHidePlayer() && getEntity() instanceof Player && ((Player) getEntity()).isOnline()) { |             if (isHidePlayer() && getEntity() instanceof Player && ((Player) getEntity()).isOnline()) { | ||||||
|                         PlayerInfoData playerInfo = new PlayerInfoData( |                 PlayerInfoData playerInfo = new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), | ||||||
|                                 ReflectionManager.getGameProfile((Player) getEntity()), 0, |                         0, NativeGameMode.fromBukkit(((Player) getEntity()).getGameMode()), | ||||||
|                                 NativeGameMode.fromBukkit(((Player) getEntity()).getGameMode()), WrappedChatComponent |                         WrappedChatComponent.fromText(DisguiseUtilities.getPlayerListName((Player) getEntity()))); | ||||||
|                                 .fromText(DisguiseUtilities.getPlayerListName((Player) getEntity()))); |  | ||||||
|  |  | ||||||
|                 PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); |                 PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO); | ||||||
|  |  | ||||||
| @@ -558,7 +556,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); | ||||||
| @@ -585,10 +584,6 @@ public abstract class Disguise { | |||||||
|  |  | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return false; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Set the entity of the disguise. Only used for internal things. |      * Set the entity of the disguise. Only used for internal things. | ||||||
| @@ -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