To prevent disguises remaining on players after death, and enderdragons from missing out on animations

This commit is contained in:
libraryaddict 2014-04-04 19:17:56 +13:00
parent f3b3c15685
commit a49cea54e7
2 changed files with 27 additions and 10 deletions

View File

@ -19,6 +19,7 @@ import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent; import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.event.vehicle.VehicleExitEvent; import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
@ -103,6 +104,16 @@ public class DisguiseListener implements Listener {
} }
} }
@EventHandler
public void onRespawn(PlayerRespawnEvent event) {
Disguise[] disguises = DisguiseAPI.getDisguises(event.getPlayer());
for (Disguise disguise : disguises) {
if (disguise.isRemoveDisguiseOnDeath()) {
disguise.removeDisguise();
}
}
}
@EventHandler @EventHandler
public void onRightClick(PlayerInteractEntityEvent event) { public void onRightClick(PlayerInteractEntityEvent event) {
if (disguiseSlap.containsKey(event.getPlayer().getName())) { if (disguiseSlap.containsKey(event.getPlayer().getName())) {

View File

@ -189,16 +189,8 @@ public abstract class Disguise {
// This is to ensure that this disguise isn't removed while clients think its the real entity // This is to ensure that this disguise isn't removed while clients think its the real entity
// The delay is because if it sends the destroy entity packets straight away, then it means no death animation // The delay is because if it sends the destroy entity packets straight away, then it means no death animation
// This is probably still a problem for wither and enderdragon deaths. // This is probably still a problem for wither and enderdragon deaths.
if (deadTicks++ > 30) { if (deadTicks++ > (getType() == DisguiseType.ENDER_DRAGON ? 200 : 20)) {
if (isRemoveDisguiseOnDeath()) {
if (getEntity() instanceof Player ?
(Bukkit.getPlayerExact(((Player) getEntity()).getName()) == null ? !isKeepDisguiseOnPlayerLogout()
: !isKeepDisguiseOnPlayerDeath())
:
(!isKeepDisguiseOnEntityDespawn() || getEntity().isDead())) {
removeDisguise(); removeDisguise();
} else { } else {
entity = null; entity = null;
@ -369,6 +361,20 @@ public abstract class Disguise {
return false; return false;
} }
/**
* Internal use
*/
public boolean isRemoveDisguiseOnDeath() {
return getEntity() instanceof Player ?
(Bukkit.getPlayerExact(((Player) getEntity()).getName()) == null ? !isKeepDisguiseOnPlayerLogout()
: !isKeepDisguiseOnPlayerDeath())
:
(!isKeepDisguiseOnEntityDespawn() || getEntity().isDead());
}
public boolean isSelfDisguiseSoundsReplaced() { public boolean isSelfDisguiseSoundsReplaced() {
return hearSelfDisguise; return hearSelfDisguise;
} }