Skip to content

Commit

Permalink
Totally forgot about the totem of undying
Browse files Browse the repository at this point in the history
  • Loading branch information
RoboMWM committed Feb 19, 2017
1 parent 4508d8c commit 1a82483
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -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)
Expand Down

0 comments on commit 1a82483

Please sign in to comment.