diff --git a/src/main/java/to/us/tf/DeathSpectating/listeners/DamageListener.java b/src/main/java/to/us/tf/DeathSpectating/listeners/DamageListener.java index 5e45847..55237ee 100644 --- a/src/main/java/to/us/tf/DeathSpectating/listeners/DamageListener.java +++ b/src/main/java/to/us/tf/DeathSpectating/listeners/DamageListener.java @@ -1,11 +1,14 @@ package to.us.tf.DeathSpectating.listeners; +import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.PlayerInventory; import to.us.tf.DeathSpectating.DeathSpectating; /** @@ -32,10 +35,15 @@ void onPlayerBasicallyWouldBeDead(EntityDamageEvent event) if (!instance.getConfigManager().canSpectate(player, event.getCause())) return; - //Check if player would be dead or not because of this + //Ignore if player will survive this damage if (player.getHealth() > event.getFinalDamage()) return; + //Ignore if player is holding a totem of undying + PlayerInventory inventory = player.getInventory(); + if (inventory.getItemInMainHand().getType() == Material.TOTEM || inventory.getItemInOffHand().getType() == Material.TOTEM) + return; + //Ignore if this is probably the result of the Essentials suicide command //Essentials will perform Player#setHealth(0), which does not fire a damage event, but does kill the player. This will lead to a double death message. if ((event.getCause() == EntityDamageEvent.DamageCause.CUSTOM || event.getCause() == EntityDamageEvent.DamageCause.SUICIDE)