use of org.bukkit.event.entity.EntityResurrectEvent in project Glowstone by GlowstoneMC.
the class GlowLivingEntity method tryUseTotem.
/**
* Use "Totem of Undying" if equipped
*
* @return result of totem use
*/
public boolean tryUseTotem() {
// TODO: Should return false if player die in void.
if (!(this instanceof HumanEntity)) {
return false;
}
HumanEntity human = (HumanEntity) this;
ItemStack mainHand = human.getInventory().getItemInMainHand();
ItemStack offHand = human.getInventory().getItemInOffHand();
boolean hasTotem = false;
if (!InventoryUtil.isEmpty(mainHand) && mainHand.getType() == Material.TOTEM_OF_UNDYING) {
mainHand.setAmount(mainHand.getAmount() - 1);
human.getInventory().setItemInMainHand(InventoryUtil.createEmptyStack());
hasTotem = true;
} else if (!InventoryUtil.isEmpty(offHand) && offHand.getType() == Material.TOTEM_OF_UNDYING) {
human.getInventory().setItemInOffHand(InventoryUtil.createEmptyStack());
hasTotem = true;
}
EntityResurrectEvent event = EventFactory.getInstance().callEvent(new EntityResurrectEvent(this));
event.setCancelled(!hasTotem);
if (event.isCancelled()) {
return false;
}
this.setHealth(1.0F);
this.clearActivePotionEffects();
this.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 900, 1));
this.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 900, 1));
playEffectKnownAndSelf(EntityEffect.TOTEM_RESURRECT);
return true;
}
Aggregations