Fix dying while disguised creating problems

This commit is contained in:
libraryaddict 2018-02-16 15:00:34 +13:00
parent ebb1fa3c35
commit f4bc01f916
2 changed files with 89 additions and 99 deletions

View File

@ -394,16 +394,9 @@ public class DisguiseListener implements Listener {
DisguiseUtilities.saveDisguises(player.getUniqueId(), disguises);
}
@EventHandler
public void onRespawn(PlayerRespawnEvent event) {
Disguise[] disguises = DisguiseAPI.getDisguises(event.getPlayer());
for (Disguise disguise : disguises) {
if (disguise.isRemoveDisguiseOnDeath()) {
disguise.removeDisguise();
}
}
if (DisguiseConfig.isBedPacketsEnabled()) {
final Player player = event.getPlayer();

View File

@ -203,11 +203,6 @@ public abstract class Disguise {
if (isRemoveDisguiseOnDeath()) {
removeDisguise();
} else {
entity = null;
watcher = getWatcher().clone(disguise);
task.cancel();
task = null;
}
}
} else {
@ -489,12 +484,17 @@ public abstract class Disguise {
* @return removeDiguise
*/
public boolean removeDisguise() {
if (disguiseInUse) {
if (!isDisguiseInUse())
return false;
UndisguiseEvent event = new UndisguiseEvent(entity, this);
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;
if (task != null) {
@ -502,8 +502,6 @@ public abstract class Disguise {
task = null;
}
HashMap<UUID, HashSet<TargetedDisguise>> disguises = DisguiseUtilities.getDisguises();
// If this disguise has a entity set
if (getEntity() != null) {
if (this instanceof PlayerDisguise) {
@ -518,7 +516,8 @@ public abstract class Disguise {
try {
for (Player player : Bukkit.getOnlinePlayers()) {
if (!((TargetedDisguise) this).canSee(player))
if (!((TargetedDisguise) this).canSee(player) ||
(!isSelfDisguiseVisible() && getEntity() == player))
continue;
ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab);
@ -546,10 +545,9 @@ public abstract class Disguise {
}
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())));
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);
@ -558,7 +556,8 @@ public abstract class Disguise {
try {
for (Player player : Bukkit.getOnlinePlayers()) {
if (!((TargetedDisguise) this).canSee(player))
if (!((TargetedDisguise) this).canSee(player) ||
(!isSelfDisguiseVisible() && getEntity() == player))
continue;
ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab);
@ -585,10 +584,6 @@ public abstract class Disguise {
return true;
}
}
return false;
}
/**
* Set the entity of the disguise. Only used for internal things.
@ -804,7 +799,8 @@ public abstract class Disguise {
try {
for (Player player : Bukkit.getOnlinePlayers()) {
if (!((TargetedDisguise) this).canSee(player))
if (!((TargetedDisguise) this).canSee(player) ||
(!isSelfDisguiseVisible() && getEntity() == player))
continue;
ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab);
@ -844,7 +840,8 @@ public abstract class Disguise {
try {
for (Player player : Bukkit.getOnlinePlayers()) {
if (!((TargetedDisguise) this).canSee(player))
if (!((TargetedDisguise) this).canSee(player) ||
(!isSelfDisguiseVisible() && getEntity() == player))
continue;
ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab);