/** * Sets the damage for the specified modifier. * * @param damage the scalar value of the damage's modifier * @see #getFinalDamage() * @throws IllegalArgumentException if type is null * @throws UnsupportedOperationException if the caller does not support * the particular DamageModifier, or to rephrase, when {@link * #isApplicable(DamageModifier)} returns false */ public void setDamage(DamageModifier type, double damage) throws IllegalArgumentException, UnsupportedOperationException { if (!modifiers.containsKey(type)) { throw type == null ? new IllegalArgumentException("Cannot have null DamageModifier") : new UnsupportedOperationException(type + " is not applicable to " + getEntity()); } modifiers.put(type, damage); }
/** * Runs an EntityDamageEvent and updates {@link org.bukkit.entity.Entity#setLastDamageCause} and * (for a {@link LivingEntity} only) {@link LivingEntity#setLastDamage(double)}. * * @param event the event to run * @param <T> the event's type * @return the completed event */ public <T extends EntityDamageEvent> T onEntityDamage(T event) { T result = callEvent(event); if (!result.isCancelled()) { result.getEntity().setLastDamageCause(result); if (result.getEntity() instanceof LivingEntity) { ((LivingEntity) result.getEntity()).setLastDamage(result.getDamage()); } } return result; }
@Override public boolean execute(CommandSender sender, String currentAlias, String[] args) { if (!testPermission(sender)) return true; if (sender instanceof Player) { Player player = (Player) sender; EntityDamageEvent ede = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.SUICIDE, 1000); Bukkit.getPluginManager().callEvent(ede); if (ede.isCancelled()) return true; ede.getEntity().setLastDamageCause(ede); player.setHealth(0); sender.sendMessage("Ouch. That look like it hurt."); } else { sender.sendMessage("You can only perform this command as a player"); } return true; }
@EventHandler public void onPlayerDamage(EntityDamageEvent event) { if(godModed.containsKey(event.getEntity())) { event.setCancelled(true); } }
@Override public MCEntity getEntity() { return BukkitConvertor.BukkitGetCorrectEntity(event.getEntity()); }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onEntityDamage(EntityDamageEvent event) { onTouch(event, event.getEntity(), false); }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) private void onPlayerHurt(EntityDamageEvent ev) { if (ev.getEntity() instanceof Player) { Player e = (Player) ev.getEntity(); for (ItemStack item : e.getInventory().getContents()) { RPGItem ri = ItemManager.toRPGItem(item).orElse(null); if (ri == null) continue; ri.power(e, item, ev, Trigger.HURT); } } }
@Override public boolean isAccepted(MobImpl value) { return e.getEntity().getUniqueId().equals(value.getEntity().getUniqueId()); } });
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) public void onEntityDamage(final EntityDamageEvent event) { if (event.getCause() != DamageCause.FALL) { return; } final Entity entity = event.getEntity(); if (!(entity instanceof Player)) { return; } checkFallDamageEvent((Player) entity, event); }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void on(EntityDamageEvent event) { if (done || !event.getEntity().equals(player)) { return; } arena.getMessenger().tell(player, Msg.JOIN_INTERRUPTED_BY_DAMAGE); interrupt(); }
private void onArmorStandDamage(EntityDamageEvent event) { if (protect && !arena.inEditMode() && region.contains(event.getEntity().getLocation())) { event.setCancelled(true); } }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onEntitySuffocatedByTempBlocks(final EntityDamageEvent event) { if (event.getCause() == DamageCause.SUFFOCATION) { if (TempBlock.isTempBlock(event.getEntity().getLocation().add(0, 1, 0).getBlock())) { event.setCancelled(true); } } }
@EventHandler (priority = EventPriority.HIGHEST) public static void onEntityDamage(EntityDamageEvent e){ Entity entity = e.getEntity(); if(!(entity instanceof LivingEntity)) return; LivingEntity le = (LivingEntity) entity; double armourDamageReduction = e.getDamage(EntityDamageEvent.DamageModifier.ARMOR); double armourPoints = le.getAttribute(Attribute.GENERIC_ARMOR).getValue(); double newReduction = armourPoints * 0.04 * - (e.getDamage() + e.getDamage(EntityDamageEvent.DamageModifier.BLOCKING)); //todo don't hardcode this value e.setDamage (EntityDamageEvent.DamageModifier.ARMOR, newReduction); INSTANCE.debug("Armour points: " + armourPoints + " Reduction: " + armourDamageReduction + " After: " + newReduction, le); }