Search in sources :

Example 26 with LivingEntity

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

the class MageTrigger method execute.

public void execute(Mage mage, double damage) {
    if (minDamage > 0 && damage < minDamage)
        return;
    if (maxDamage > 0 && damage > maxDamage)
        return;
    LivingEntity li = mage.getLivingEntity();
    if (minHealth > 0 && (li == null || li.getHealth() < minHealth))
        return;
    if (maxHealth > 0 && (li == null || li.getHealth() > maxHealth))
        return;
    if (minHealthPercentage > 0 && (li == null || li.getHealth() * 100 / li.getMaxHealth() < minHealthPercentage))
        return;
    if (maxHealthPercentage > 0 && (li == null || li.getHealth() * 100 / li.getMaxHealth() > maxHealthPercentage))
        return;
    if (spells != null && !spells.isEmpty()) {
        String deathSpell = RandomUtils.weightedRandom(spells);
        cast(mage, deathSpell);
    }
    if (commands != null) {
        Entity topDamager = mage.getTopDamager();
        Entity killer = mage.getLastDamager();
        Collection<Entity> damagers = mage.getDamagers();
        Location location = mage.getLocation();
        for (String command : commands) {
            if (command.contains("@killer")) {
                if (killer == null)
                    continue;
                command = command.replace("@killer", killer.getName());
            }
            if (command.contains("@damager")) {
                if (topDamager == null)
                    continue;
                command = command.replace("@damager", topDamager.getName());
            }
            boolean allDamagers = command.contains("@damagers");
            if (allDamagers && damagers == null) {
                continue;
            }
            command = command.replace("@name", mage.getName()).replace("@world", location.getWorld().getName()).replace("@x", Double.toString(location.getX())).replace("@y", Double.toString(location.getY())).replace("@z", Double.toString(location.getZ()));
            if (allDamagers) {
                for (Entity damager : damagers) {
                    String damagerCommand = command.replace("@damagers", damager.getName());
                    mage.getController().getPlugin().getServer().dispatchCommand(Bukkit.getConsoleSender(), damagerCommand);
                }
            } else {
                mage.getController().getPlugin().getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
            }
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Location(org.bukkit.Location)

Example 27 with LivingEntity

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

the class Mage method setLocation.

@Override
public void setLocation(Location location) {
    LivingEntity entity = getLivingEntity();
    if (entity != null && location != null) {
        entity.teleport(location);
        return;
    }
    this.location = location;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity)

Example 28 with LivingEntity

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

the class Mage method updatePassiveEffects.

protected void updatePassiveEffects() {
    protection.clear();
    strength.clear();
    weakness.clear();
    attributes.clear();
    spMultiplier = 1;
    cooldownReduction = 0;
    costReduction = 0;
    consumeReduction = 0;
    List<PotionEffectType> currentEffects = new ArrayList<>(effectivePotionEffects.keySet());
    LivingEntity entity = getLivingEntity();
    effectivePotionEffects.clear();
    addPassiveEffects(properties, true);
    if (activeClass != null) {
        addPassiveEffects(activeClass, true);
        spMultiplier = (float) (spMultiplier * activeClass.getDouble("sp_multiplier", 1.0));
    }
    if (activeWand != null && !activeWand.isPassive()) {
        addPassiveEffects(activeWand, false);
        effectivePotionEffects.putAll(activeWand.getPotionEffects());
    }
    // Don't add these together so things stay balanced!
    if (offhandWand != null && !offhandWand.isPassive()) {
        addPassiveEffects(offhandWand, false);
        effectivePotionEffects.putAll(offhandWand.getPotionEffects());
        spMultiplier *= offhandWand.getSPMultiplier();
    }
    for (Wand armorWand : activeArmor.values()) {
        if (armorWand != null) {
            addPassiveEffects(armorWand, false);
            effectivePotionEffects.putAll(armorWand.getPotionEffects());
        }
    }
    if (entity != null) {
        for (PotionEffectType effectType : currentEffects) {
            if (!effectivePotionEffects.containsKey(effectType)) {
                entity.removePotionEffect(effectType);
            }
        }
        for (Map.Entry<PotionEffectType, Integer> effects : effectivePotionEffects.entrySet()) {
            PotionEffect effect = new PotionEffect(effects.getKey(), Integer.MAX_VALUE, effects.getValue(), true, false);
            CompatibilityUtils.applyPotionEffect(entity, effect);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) ArrayList(java.util.ArrayList) Wand(com.elmakers.mine.bukkit.wand.Wand) LostWand(com.elmakers.mine.bukkit.api.wand.LostWand) Map(java.util.Map) HashMap(java.util.HashMap)

Example 29 with LivingEntity

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

the class Mage method setTarget.

private void setTarget(Entity target) {
    if (entityData != null && !entityData.shouldFocusOnDamager())
        return;
    LivingEntity li = getLivingEntity();
    if (li != null && li instanceof Creature && target instanceof LivingEntity) {
        Creature creature = ((Creature) li);
        if (creature.getTarget() != target) {
            sendDebugMessage("Now targeting " + target.getName(), 6);
        }
        creature.setTarget((LivingEntity) target);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Creature(org.bukkit.entity.Creature)

Example 30 with LivingEntity

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

the class SourceLocation method getLocation.

@Nullable
public Location getLocation(CastContext context) {
    Mage mage;
    Location eyeLocation;
    Location feetLocation;
    if (isSource) {
        mage = context.getMage();
        eyeLocation = context.getEyeLocation();
        feetLocation = context.getLocation();
    } else {
        Entity targetEntity = context.getTargetEntity();
        if (targetEntity == null) {
            mage = null;
            feetLocation = context.getTargetLocation();
            eyeLocation = context.getTargetLocation();
        } else {
            mage = context.getController().getRegisteredMage(targetEntity);
            feetLocation = targetEntity.getLocation();
            eyeLocation = targetEntity instanceof LivingEntity ? ((LivingEntity) targetEntity).getEyeLocation() : targetEntity.getLocation();
        }
    }
    if (mage == null && (locationType == LocationType.CAST || locationType == LocationType.WAND)) {
        locationType = LocationType.EYES;
    }
    Location location = null;
    switch(locationType) {
        case CAST:
            if (isSource) {
                location = context.getCastLocation();
            } else {
                location = mage.getCastLocation();
            }
            break;
        case EYES:
            location = eyeLocation;
            break;
        case FEET:
            location = feetLocation;
            break;
        case WAND:
            if (isSource) {
                location = context.getWandLocation();
            } else {
                location = mage.getWandLocation();
            }
            break;
        case BODY:
            if (eyeLocation != null && feetLocation != null) {
                location = eyeLocation.clone().add(feetLocation).multiply(0.5);
            }
            break;
        case HIT:
            location = context.getTargetLocation();
            break;
        case BLOCK:
            if (feetLocation != null) {
                location = feetLocation.getBlock().getLocation();
            }
            break;
    }
    if (location == null) {
        location = feetLocation;
    }
    Location targetLocation = isSource ? context.getTargetLocation() : context.getLocation();
    if (orientToTarget && targetLocation != null && location != null) {
        Vector direction = targetLocation.toVector().subtract(location.toVector()).normalize();
        if (MathUtils.isFinite(direction.getX()) && MathUtils.isFinite(direction.getY()) && MathUtils.isFinite(direction.getZ())) {
            location.setDirection(direction);
        }
    }
    return location;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) Nullable(javax.annotation.Nullable)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)324 Entity (org.bukkit.entity.Entity)170 Player (org.bukkit.entity.Player)123 Location (org.bukkit.Location)72 EventHandler (org.bukkit.event.EventHandler)64 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