Search in sources :

Example 31 with Target

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

the class TargetingSpell method findTarget.

protected Target findTarget(CastContext context) {
    Location source = getEyeLocation();
    TargetType targetType = targeting.getTargetType();
    boolean isBlock = targetType == TargetType.BLOCK || targetType == TargetType.SELECT;
    if (!isBlock && targetEntity != null) {
        return targeting.overrideTarget(context, new Target(source, targetEntity));
    }
    if (targetType != TargetType.SELF && targetLocation != null) {
        return targeting.overrideTarget(context, new Target(source, targetLocation.getBlock()));
    }
    Target target = targeting.target(context, getMaxRange());
    return targeting.getResult() == Targeting.TargetingResult.MISS && !allowMaxRange ? new Target(source) : target;
}
Also used : Target(com.elmakers.mine.bukkit.utility.Target) TargetType(com.elmakers.mine.bukkit.api.spell.TargetType) Location(org.bukkit.Location)

Example 32 with Target

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

the class TargetingSpell method processBlockEffects.

protected Target processBlockEffects() {
    Target target = targeting.getTarget();
    Target originalTarget = target;
    final Block block = target.getBlock();
    Double backfireAmount = currentCast.getReflective(block);
    if (backfireAmount != null) {
        if (random.nextDouble() < backfireAmount) {
            final Entity mageEntity = mage.getEntity();
            final Location location = getLocation();
            final Location originLocation = block.getLocation();
            Vector direction = location.getDirection();
            originLocation.setDirection(direction.multiply(-1));
            this.location = originLocation;
            backfire();
            final Collection<com.elmakers.mine.bukkit.api.effect.EffectPlayer> effects = getEffects("cast");
            if (effects.size() > 0) {
                Bukkit.getScheduler().runTaskLater(controller.getPlugin(), new Runnable() {

                    @Override
                    public void run() {
                        for (com.elmakers.mine.bukkit.api.effect.EffectPlayer player : effects) {
                            player.setMaterial(getEffectMaterial());
                            player.setColor(mage.getEffectColor());
                            player.start(originLocation, null, location, mageEntity);
                        }
                    }
                }, 5L);
            }
            target = new Target(getEyeLocation(), mageEntity);
        }
    }
    if (targetBreakables > 0 && originalTarget.isValid() && block != null && currentCast.isBreakable(block)) {
        targeting.breakBlock(currentCast, block, targetBreakables);
    }
    return target;
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Target(com.elmakers.mine.bukkit.utility.Target) Block(org.bukkit.block.Block) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 33 with Target

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

the class TargetingSpell method getTarget.

protected Target getTarget(CastContext context) {
    Target target = findTarget(context);
    if (instantBlockEffects) {
        target = processBlockEffects();
    }
    if (originAtTarget && target.isValid()) {
        Location previous = this.location;
        if (previous == null && mage != null) {
            previous = mage.getLocation();
        }
        location = target.getLocation().clone();
        if (previous != null) {
            location.setPitch(previous.getPitch());
            location.setYaw(previous.getYaw());
        }
    }
    Entity targetEntity = target != null ? target.getEntity() : null;
    Location targetLocation = target != null ? target.getLocation() : null;
    context.setTargetLocation(targetLocation);
    context.setTargetEntity(targetEntity);
    return target;
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Target(com.elmakers.mine.bukkit.utility.Target) Location(org.bukkit.Location)

Example 34 with Target

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

the class TargetingSpell method getMessage.

@Override
public String getMessage(String messageKey, String def) {
    String message = super.getMessage(messageKey, def);
    // Escape targeting parameters
    String useTargetName = null;
    if (currentCast != null) {
        useTargetName = currentCast.getTargetName();
    }
    if (useTargetName == null) {
        Target target = targeting.getTarget();
        if (target != null) {
            if (target.hasEntity() && getTargetType() != TargetType.BLOCK) {
                useTargetName = controller.getEntityDisplayName(target.getEntity());
            } else if (target.isValid() && getTargetType() != TargetType.OTHER_ENTITY && getTargetType() != TargetType.ANY_ENTITY) {
                MaterialAndData material = target.getTargetedMaterial();
                if (material != null) {
                    useTargetName = material.getName();
                }
            }
        }
    }
    if (useTargetName == null) {
        message = message.replace("$target", "Nothing");
    } else {
        message = message.replace("$target", useTargetName);
    }
    return message;
}
Also used : Target(com.elmakers.mine.bukkit.utility.Target) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData)

Example 35 with Target

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

the class TargetingSpell method getEffectMaterial.

@Nullable
@Override
public com.elmakers.mine.bukkit.api.block.MaterialAndData getEffectMaterial() {
    Target target = targeting.getTarget();
    if (target != null && target.isValid()) {
        Block block = target.getBlock();
        MaterialAndData targetMaterial = new MaterialAndData(block);
        if (targetMaterial.getMaterial() == Material.AIR) {
            targetMaterial.setMaterial(DEFAULT_EFFECT_MATERIAL);
        }
        return targetMaterial;
    }
    return super.getEffectMaterial();
}
Also used : Target(com.elmakers.mine.bukkit.utility.Target) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) Block(org.bukkit.block.Block) Nullable(javax.annotation.Nullable)

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