Beispiel #1
0
  @Override
  public SpellResult perform(CastContext context) {
    Entity entity = context.getTargetEntity();
    if (entity == null || !(entity instanceof Damageable) || entity.isDead()) {
      return SpellResult.NO_TARGET;
    }

    double damage = 1;

    Damageable targetEntity = (Damageable) entity;
    LivingEntity livingTarget = (entity instanceof LivingEntity) ? (LivingEntity) entity : null;
    context.registerDamaged(targetEntity);
    Mage mage = context.getMage();
    MageController controller = context.getController();

    double previousKnockbackResistance = 0D;
    try {
      if (knockbackResistance != null && livingTarget != null) {
        AttributeInstance knockBackAttribute =
            livingTarget.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE);
        previousKnockbackResistance = knockBackAttribute.getBaseValue();
        knockBackAttribute.setBaseValue(knockbackResistance);
      }
      if (controller.isElemental(entity)) {
        damage = elementalDamage;
        controller.damageElemental(
            entity, damage * mage.getDamageMultiplier(), 0, mage.getCommandSender());
      } else {
        if (percentage != null) {
          damage = percentage * targetEntity.getMaxHealth();
        } else if (targetEntity instanceof Player) {
          damage = playerDamage;
        } else {
          damage = entityDamage;
        }
        damage *= mage.getDamageMultiplier();
        if (magicDamage && (magicEntityDamage || targetEntity instanceof Player)) {
          CompatibilityUtils.magicDamage(targetEntity, damage, mage.getEntity());
        } else {
          CompatibilityUtils.damage(targetEntity, damage, mage.getEntity());
        }
      }
    } finally {
      if (knockbackResistance != null && livingTarget != null) {
        AttributeInstance knockBackAttribute =
            livingTarget.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE);
        knockBackAttribute.setBaseValue(previousKnockbackResistance);
      }
    }

    return SpellResult.CAST;
  }
Beispiel #2
0
  @Override
  public SpellResult perform(CastContext context) {
    Entity entity = context.getTargetEntity();
    if (entity == null || !(entity instanceof LivingEntity)) {
      return SpellResult.NO_TARGET;
    }

    LivingEntity targetEntity = (LivingEntity) entity;
    Collection<PotionEffect> currentEffects = targetEntity.getActivePotionEffects();
    for (PotionEffect effect : currentEffects) {
      if (negativeEffects.contains(effect.getType())) {
        context.registerPotionEffects(targetEntity);
        targetEntity.removePotionEffect(effect.getType());
      }
    }
    return SpellResult.CAST;
  }
 @Override
 public SpellResult perform(CastContext context) {
   Entity sourceEntity = context.getEntity();
   Location sourceLocation = context.getEyeLocation().clone();
   Entity targetEntity = context.getTargetEntity();
   Location targetLocation = context.getTargetLocation();
   if (targetLocation != null) {
     targetLocation = targetLocation.clone();
   }
   Vector direction = context.getDirection().normalize();
   if (sourceLocation == null) {
     return SpellResult.LOCATION_REQUIRED;
   }
   if (targetSelf) {
     targetEntity = sourceEntity;
     targetLocation = sourceLocation;
   } else if (targetEntityLocation && targetEntity != null) {
     targetLocation = targetEntity.getLocation();
   }
   if (attachBlock) {
     Block previousBlock = context.getPreviousBlock();
     if (previousBlock != null) {
       Location current = targetLocation;
       targetLocation = previousBlock.getLocation();
       context.getBrush().setTarget(current, targetLocation);
     }
   }
   if (sourceOffset != null) {
     sourceLocation = sourceLocation.add(sourceOffset);
   }
   if (targetOffset != null && targetLocation != null) {
     targetLocation = targetLocation.add(targetOffset);
   }
   if (randomSourceOffset != null) {
     sourceLocation = RandomUtils.randomizeLocation(sourceLocation, randomSourceOffset);
   }
   if (randomTargetOffset != null && targetLocation != null) {
     targetLocation = RandomUtils.randomizeLocation(targetLocation, randomTargetOffset);
   }
   if (targetDirection != null && targetLocation != null) {
     targetLocation.setDirection(targetDirection);
   }
   if (sourceDirection != null) {
     sourceLocation.setDirection(sourceDirection);
     direction = sourceDirection.clone();
   }
   if (targetDirectionOffset != null && targetLocation != null) {
     targetLocation.setDirection(targetLocation.getDirection().add(targetDirectionOffset));
   }
   if (sourceDirectionOffset != null) {
     sourceLocation.setDirection(direction.add(sourceDirectionOffset));
   }
   if (sourceDirectionSpeed != null) {
     sourceLocation = sourceLocation.add(direction.clone().multiply(sourceDirectionSpeed));
   }
   if (targetDirectionSpeed != null && targetLocation != null) {
     targetLocation = targetLocation.add(direction.clone().multiply(targetDirectionSpeed));
   }
   if (sourceAtTarget && targetLocation != null) {
     sourceLocation.setX(targetLocation.getX());
     sourceLocation.setY(targetLocation.getY());
     sourceLocation.setZ(targetLocation.getZ());
     sourceLocation.setWorld(targetLocation.getWorld());
   }
   if (persistTarget) {
     context.setTargetLocation(targetLocation);
   }
   CastContext newContext =
       createContext(context, sourceEntity, sourceLocation, targetEntity, targetLocation);
   return super.perform(newContext);
 }