Beispiel #1
0
 @Override
 public void execute(final Event e) {
   double damage = 0;
   if (this.damage != null) {
     final Number n = this.damage.getSingle(e);
     if (n == null) return;
     damage = n.doubleValue();
   }
   for (final Object damageable : damageables.getArray(e)) {
     if (damageable instanceof Slot) {
       ItemStack is = ((Slot) damageable).getItem();
       if (this.damage == null) {
         is.setDurability((short) 0);
       } else {
         is.setDurability((short) Math.max(0, is.getDurability() + (heal ? -damage : damage)));
         if (is.getDurability() >= is.getType().getMaxDurability()) is = null;
       }
       ((Slot) damageable).setItem(is);
     } else if (damageable instanceof LivingEntity) {
       if (this.damage == null) {
         ((LivingEntity) damageable).setHealth(((LivingEntity) damageable).getMaxHealth());
       } else {
         if (!heal) {
           ((LivingEntity) damageable).damage((int) Math.round(2. * damage));
         } else {
           ((LivingEntity) damageable)
               .setHealth(
                   Math.max(
                       0,
                       Math.min(
                           ((LivingEntity) damageable).getMaxHealth(),
                           ((LivingEntity) damageable).getHealth()
                               + (int) Math.round(2. * damage))));
         }
       }
     }
   }
 }