Search in sources :

Example 11 with Target

use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.

the class PlaceSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Target attachToBlock = getTarget();
    if (!attachToBlock.isValid())
        return SpellResult.NO_TARGET;
    Block placeBlock = getPreviousBlock();
    if (placeBlock == null)
        return SpellResult.NO_TARGET;
    if (!hasBuildPermission(placeBlock)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    MaterialBrush buildWith = getBrush();
    buildWith.setTarget(attachToBlock.getLocation(), placeBlock.getLocation());
    buildWith.update(mage, placeBlock.getLocation());
    registerForUndo(placeBlock);
    buildWith.modify(placeBlock);
    registerForUndo();
    return SpellResult.CAST;
}
Also used : Target(com.elmakers.mine.bukkit.utility.Target) MaterialBrush(com.elmakers.mine.bukkit.api.block.MaterialBrush) Block(org.bukkit.block.Block)

Example 12 with Target

use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.

the class PotionEffectSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Target target = getTarget();
    if (!target.hasTarget()) {
        return SpellResult.NO_TARGET;
    }
    List<LivingEntity> targetEntities = new ArrayList<>();
    Entity targetedEntity = target.getEntity();
    if (target.hasEntity() && targetedEntity instanceof LivingEntity) {
        targetEntities.add((LivingEntity) targetedEntity);
    }
    int radius = parameters.getInt("radius", 0);
    radius = (int) (mage.getRadiusMultiplier() * radius);
    if (radius > 0) {
        List<Entity> entities = CompatibilityUtils.getNearbyEntities(target.getLocation(), radius, radius, radius);
        for (Entity entity : entities) {
            if (entity instanceof LivingEntity && entity != targetedEntity && entity != mage.getEntity()) {
                targetEntities.add((LivingEntity) entity);
            }
        }
    }
    if (targetEntities.size() == 0) {
        return SpellResult.NO_TARGET;
    }
    int fallProtection = parameters.getInt("fall_protection", 0);
    Integer duration = null;
    if (parameters.contains("duration")) {
        duration = parameters.getInt("duration");
    }
    Collection<PotionEffect> effects = getPotionEffects(parameters, duration);
    for (LivingEntity targetEntity : targetEntities) {
        Mage targetMage = controller.isMage(targetEntity) ? controller.getMage(targetEntity) : null;
        if (targetMage != null && fallProtection > 0) {
            targetMage.enableFallProtection(fallProtection);
        }
        if (targetEntity != mage.getEntity()) {
            // Check for superprotected mages
            if (targetMage != null) {
                // Check for protected players
                if (isSuperProtected(targetMage)) {
                    continue;
                }
                if (parameters.getBoolean("deactivate_target_mage")) {
                    targetMage.deactivateAllSpells(true, false);
                }
            }
        }
        if (targetEntity instanceof Player && parameters.getBoolean("feed", false)) {
            Player p = (Player) targetEntity;
            p.setExhaustion(0);
            p.setFoodLevel(20);
        }
        if (parameters.getBoolean("cure", false)) {
            Collection<PotionEffect> currentEffects = targetEntity.getActivePotionEffects();
            for (PotionEffect effect : currentEffects) {
                if (negativeEffects.contains(effect.getType())) {
                    targetEntity.removePotionEffect(effect.getType());
                }
            }
        }
        if (parameters.contains("heal")) {
            registerModified(targetEntity);
            double health = targetEntity.getHealth() + parameters.getDouble("heal");
            targetEntity.setHealth(Math.min(health, targetEntity.getMaxHealth()));
        } else if (parameters.contains("heal_percentage")) {
            registerModified(targetEntity);
            double health = targetEntity.getHealth() + targetEntity.getMaxHealth() * parameters.getDouble("heal_percentage");
            targetEntity.setHealth(Math.min(health, targetEntity.getMaxHealth()));
        } else if (parameters.contains("damage")) {
            registerModified(targetEntity);
            CompatibilityUtils.magicDamage(targetEntity, parameters.getDouble("damage") * mage.getDamageMultiplier(), mage.getEntity());
        } else {
            registerPotionEffects(targetEntity);
        }
        if (parameters.contains("fire")) {
            registerModified(targetEntity);
            targetEntity.setFireTicks(parameters.getInt("fire"));
        }
        CompatibilityUtils.applyPotionEffects(targetEntity, effects);
        if (parameters.contains("remove_effects")) {
            List<String> removeKeys = parameters.getStringList("remove_effects");
            for (String removeKey : removeKeys) {
                PotionEffectType removeType = PotionEffectType.getByName(removeKey);
                targetEntity.removePotionEffect(removeType);
            }
        }
    }
    registerForUndo();
    return SpellResult.CAST;
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) ArrayList(java.util.ArrayList) LivingEntity(org.bukkit.entity.LivingEntity) Target(com.elmakers.mine.bukkit.utility.Target) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 13 with Target

use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.

the class LightningSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Target target = getTarget();
    if (target == null || !target.isValid()) {
        return SpellResult.NO_TARGET;
    }
    Block targetBlock = target.getBlock();
    if (!hasBuildPermission(targetBlock)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    CoverAction cover = new CoverAction();
    cover.addAction(new LightningAction());
    ActionHandler handler = new ActionHandler();
    handler.loadAction(cover);
    handler.initialize(this, parameters);
    registerForUndo();
    return handler.start(getCurrentCast(), parameters);
}
Also used : Target(com.elmakers.mine.bukkit.utility.Target) CoverAction(com.elmakers.mine.bukkit.action.builtin.CoverAction) LightningAction(com.elmakers.mine.bukkit.action.builtin.LightningAction) Block(org.bukkit.block.Block) ActionHandler(com.elmakers.mine.bukkit.action.ActionHandler)

Example 14 with Target

use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.

the class MusicSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Target target = getTarget();
    if (!target.hasTarget()) {
        return SpellResult.NO_TARGET;
    }
    Location location = target.getLocation();
    location.getWorld().playEffect(location, Effect.RECORD_PLAY, RECORDS[random.nextInt(RECORDS.length)].getId());
    return SpellResult.CAST;
}
Also used : Target(com.elmakers.mine.bukkit.utility.Target) Location(org.bukkit.Location)

Example 15 with Target

use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.

the class ForceSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    effectColor = mage.getEffectColor();
    if (effectColor == null) {
        effectColor = Color.fromRGB(Integer.parseInt(parameters.getString("effect_color", "FF0000"), 16));
    }
    if (targetEntity != null) {
        Location location = getLocation();
        World targetWorld = targetEntity.getWorld();
        if (!targetEntity.isValid() || targetEntity.isDead()) {
            releaseTarget();
        } else if (targetWorld == null || location == null || !targetWorld.getName().equals(location.getWorld().getName())) {
            releaseTarget();
        } else if (location.distanceSquared(targetEntity.getLocation()) > getMaxRangeSquared()) {
            releaseTarget();
        }
        // Check for protected Mages
        if (targetEntity != null && controller.isMage(targetEntity)) {
            Mage targetMage = controller.getMage(targetEntity);
            // Check for protected players (admins, generally...)
            if (isSuperProtected(targetMage)) {
                releaseTarget();
            }
        }
    }
    if (targetEntity == null) {
        Target target = getTarget();
        if (!target.hasEntity() || !(target.getEntity() instanceof LivingEntity)) {
            return SpellResult.NO_TARGET;
        }
        releaseTarget();
        LivingEntity checkTarget = (LivingEntity) target.getEntity();
        // Check for protected Mages
        if (checkTarget != null && controller.isMage(checkTarget)) {
            Mage targetMage = controller.getMage(checkTarget);
            // Check for protected players
            if (isSuperProtected(targetMage)) {
                return SpellResult.NO_TARGET;
            }
        }
        selectTarget(checkTarget);
        activate();
        return SpellResult.TARGET_SELECTED;
    }
    double multiplier = parameters.getDouble("size", 1);
    int magnitude = parameters.getInt("entity_force", DEFAULT_MAGNITUDE);
    forceEntity(targetEntity, multiplier, magnitude);
    return SpellResult.CAST;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Target(com.elmakers.mine.bukkit.utility.Target) Mage(com.elmakers.mine.bukkit.api.magic.Mage) World(org.bukkit.World) Location(org.bukkit.Location)

Aggregations

Target (com.elmakers.mine.bukkit.utility.Target)44 Entity (org.bukkit.entity.Entity)24 Location (org.bukkit.Location)20 Block (org.bukkit.block.Block)20 LivingEntity (org.bukkit.entity.LivingEntity)17 Player (org.bukkit.entity.Player)14 Mage (com.elmakers.mine.bukkit.api.magic.Mage)13 ArrayList (java.util.ArrayList)9 Vector (org.bukkit.util.Vector)7 MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)5 ActionHandler (com.elmakers.mine.bukkit.action.ActionHandler)4 CoverAction (com.elmakers.mine.bukkit.action.builtin.CoverAction)4 ItemStack (org.bukkit.inventory.ItemStack)4 MaterialBrush (com.elmakers.mine.bukkit.api.block.MaterialBrush)3 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)3 Material (org.bukkit.Material)3 Ageable (org.bukkit.entity.Ageable)3 SpellResult (com.elmakers.mine.bukkit.api.spell.SpellResult)2 ConstructionType (com.elmakers.mine.bukkit.block.ConstructionType)2 World (org.bukkit.World)2