Search in sources :

Example 61 with LivingEntity

use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.

the class FlingSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    int height = 0;
    Block playerBlock = getLocation().getBlock();
    LivingEntity entity = mage.getLivingEntity();
    if (entity == null) {
        return SpellResult.LIVING_ENTITY_REQUIRED;
    }
    int maxSpeedAtElevation = parameters.getInt("cruising_altitude", defaultMaxSpeedAtElevation);
    double minMagnitude = parameters.getDouble("min_speed", defaultMinMagnitude);
    double maxMagnitude = parameters.getDouble("max_speed", defaultMaxMagnitude);
    safetyLength = parameters.getLong("safety", safetyLength);
    while (height < maxSpeedAtElevation && playerBlock.getType() == Material.AIR) {
        playerBlock = playerBlock.getRelative(BlockFace.DOWN);
        height++;
    }
    double heightModifier = maxSpeedAtElevation > 0 ? ((double) height / maxSpeedAtElevation) : 1;
    double magnitude = (minMagnitude + ((maxMagnitude - minMagnitude) * heightModifier));
    Vector velocity = getDirection();
    if (mage.getLocation().getBlockY() >= 256) {
        velocity.setY(0);
    }
    velocity.multiply(magnitude);
    registerVelocity(entity);
    registerMoved(entity);
    SafetyUtils.setVelocity(entity, velocity);
    if (safetyLength > 0) {
        mage.registerEvent(SpellEventType.PLAYER_DAMAGE, this);
    }
    lastFling = System.currentTimeMillis();
    registerForUndo();
    return SpellResult.CAST;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Block(org.bukkit.block.Block) Vector(org.bukkit.util.Vector)

Example 62 with LivingEntity

use of org.bukkit.entity.LivingEntity 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)

Example 63 with LivingEntity

use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.

the class GrowSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Target target = getTarget();
    if (!target.hasEntity()) {
        return SpellResult.NO_TARGET;
    }
    Entity targetEntity = target.getEntity();
    if (controller.isElemental(targetEntity)) {
        double elementalSize = controller.getElementalScale(targetEntity);
        elementalSize *= 1.2;
        controller.setElementalScale(targetEntity, elementalSize);
        return SpellResult.CAST;
    }
    if (!(targetEntity instanceof LivingEntity))
        return SpellResult.NO_TARGET;
    LivingEntity li = (LivingEntity) targetEntity;
    if (li instanceof Ageable && !((Ageable) li).isAdult() && !(li instanceof Player)) {
        registerModified(li);
        ((Ageable) li).setAdult();
    } else if (li instanceof Zombie) {
        registerModified(li);
        Zombie zombie = (Zombie) li;
        if (!zombie.isBaby()) {
            UndoList spawnedList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(li);
            Location targetLocation = li.getLocation();
            li.remove();
            Entity giant = targetLocation.getWorld().spawnEntity(targetLocation, EntityType.GIANT);
            registerForUndo(giant);
            if (spawnedList != null) {
                spawnedList.add(giant);
            }
        } else {
            ((Zombie) li).setBaby(false);
        }
    } else if (li instanceof PigZombie && ((PigZombie) li).isBaby()) {
        registerModified(li);
        ((PigZombie) li).setBaby(false);
    } else if (li instanceof Slime) {
        registerModified(li);
        Slime slime = (Slime) li;
        slime.setSize(slime.getSize() + 1);
    } else {
        return SpellResult.NO_TARGET;
    }
    registerForUndo();
    return SpellResult.CAST;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Target(com.elmakers.mine.bukkit.utility.Target) Player(org.bukkit.entity.Player) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Zombie(org.bukkit.entity.Zombie) PigZombie(org.bukkit.entity.PigZombie) PigZombie(org.bukkit.entity.PigZombie) Ageable(org.bukkit.entity.Ageable) Slime(org.bukkit.entity.Slime) Location(org.bukkit.Location)

Example 64 with LivingEntity

use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.

the class CastContext method messageTargets.

@Override
public void messageTargets(String messageKey) {
    Mage mage = getMage();
    if (mage.isStealth())
        return;
    Collection<Entity> targets = getTargetedEntities();
    if (targets == null || targets.isEmpty())
        return;
    MageController controller = getController();
    LivingEntity sourceEntity = mage.getLivingEntity();
    String playerMessage = getMessage(messageKey);
    if (playerMessage.length() > 0) {
        playerMessage = playerMessage.replace("$spell", spell.getName());
        for (Entity target : targets) {
            UUID targetUUID = target.getUniqueId();
            if (target instanceof Player && target != sourceEntity && !targetMessagesSent.contains(targetUUID)) {
                targetMessagesSent.add(targetUUID);
                Mage targetMage = controller.getRegisteredMage(target);
                if (targetMage != null) {
                    targetMage.sendMessage(playerMessage);
                }
            }
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Player(org.bukkit.entity.Player) EffectPlayer(com.elmakers.mine.bukkit.api.effect.EffectPlayer) Mage(com.elmakers.mine.bukkit.api.magic.Mage) UUID(java.util.UUID)

Example 65 with LivingEntity

use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.

the class AggroAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Entity target = context.getTargetEntity();
    if (!(target instanceof Creature)) {
        return SpellResult.NO_TARGET;
    }
    LivingEntity source = context.getLivingEntity();
    if (source == null) {
        return SpellResult.NO_TARGET;
    }
    Creature creatureTarget = (Creature) target;
    LivingEntity current = creatureTarget.getTarget();
    if (source == current) {
        return SpellResult.NO_ACTION;
    }
    ((Creature) target).setTarget(source);
    return SpellResult.CAST;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Creature(org.bukkit.entity.Creature)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)322 Entity (org.bukkit.entity.Entity)169 Player (org.bukkit.entity.Player)121 Location (org.bukkit.Location)71 EventHandler (org.bukkit.event.EventHandler)63 Vector (org.bukkit.util.Vector)60 ItemStack (org.bukkit.inventory.ItemStack)47 ArrayList (java.util.ArrayList)41 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)37 PotionEffect (org.bukkit.potion.PotionEffect)34 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)30 Block (org.bukkit.block.Block)24 Mage (com.elmakers.mine.bukkit.api.magic.Mage)22 Projectile (org.bukkit.entity.Projectile)20 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)18 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)17 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)16 Target (com.elmakers.mine.bukkit.utility.Target)15 World (org.bukkit.World)14 Creature (org.bukkit.entity.Creature)14