Search in sources :

Example 41 with PotionEffect

use of org.bukkit.potion.PotionEffect in project MagicPlugin by elBukkit.

the class CureAction method perform.

@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;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) PotionEffect(org.bukkit.potion.PotionEffect)

Example 42 with PotionEffect

use of org.bukkit.potion.PotionEffect in project Spirits by xNuminousx.

the class Infest method infestEntities.

public void infestEntities(Entity entity) {
    if (new Random().nextInt(effectInt) == 0) {
        if (entity instanceof Player) {
            Player ePlayer = (Player) entity;
            BendingPlayer bEntity = BendingPlayer.getBendingPlayer(ePlayer);
            if (bEntity.hasElement(Element.getElement("DarkSpirit")) && healDarkSpirits) {
                LivingEntity le = (LivingEntity) entity;
                le.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 120, 1));
                ParticleEffect.HEART.display(entity.getLocation().add(0, 2, 0), 0, 0, 0, 0, 1);
            }
        } else if (entity instanceof Monster) {
            LivingEntity le = (LivingEntity) entity;
            le.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 120, 1));
            ParticleEffect.ANGRY_VILLAGER.display(entity.getLocation().add(0, 1, 0), 0, 0, 0, 0, 1);
        } else if (entity instanceof LivingEntity && damageEntities) {
            DamageHandler.damageEntity(entity, damage, this);
            ParticleEffect.PORTAL.display(entity.getLocation().add(0, 1, 0), 0, 0, 0, 1.5F, 5);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) BendingPlayer(com.projectkorra.projectkorra.BendingPlayer) BendingPlayer(com.projectkorra.projectkorra.BendingPlayer) Player(org.bukkit.entity.Player) Random(java.util.Random) PotionEffect(org.bukkit.potion.PotionEffect) Monster(org.bukkit.entity.Monster)

Example 43 with PotionEffect

use of org.bukkit.potion.PotionEffect in project Spirits by xNuminousx.

the class Fuse method fuse.

public void fuse(Entity target) {
    isFusing = true;
    player.setGameMode(GameMode.SPECTATOR);
    player.setSpectatorTarget(target);
    if (new Random().nextInt(5) == 0) {
        Methods.playSpiritParticles(bPlayer, player.getLocation().add(0, 1, 0), 0.5F, 0.5F, 0.5F, 0.2F, 5);
    }
    if (target instanceof Player) {
        enableAvatarState = true;
        if (System.currentTimeMillis() > time + dangerDelay) {
            if (new Random().nextInt(10) == 0) {
                DamageHandler.damageEntity(target, 1, this);
                ParticleEffect.MAGIC_CRIT.display(target.getLocation().add(0, 1, 0), 0, 0, 0, 0.2F, 10);
            }
        }
    } else if (target instanceof LivingEntity) {
        if (!enableNPCMerge) {
            defuse();
            remove();
            return;
        }
        if (System.currentTimeMillis() > time + dangerDelay) {
            if (new Random().nextInt(10) == 0) {
                DamageHandler.damageEntity(target, 1, this);
                ParticleEffect.MAGIC_CRIT.display(target.getLocation().add(0, 1, 0), 0, 0, 0, 0.2F, 10);
            }
        }
        LivingEntity le = (LivingEntity) target;
        le.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, potDuration * 24, 2));
        le.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, potDuration * 24, 1));
        le.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, potDuration * 24, 2));
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) BendingPlayer(com.projectkorra.projectkorra.BendingPlayer) Player(org.bukkit.entity.Player) Random(java.util.Random) PotionEffect(org.bukkit.potion.PotionEffect)

Example 44 with PotionEffect

use of org.bukkit.potion.PotionEffect in project MagicPlugin by elBukkit.

the class CitizensTrait method updateEntity.

protected void updateEntity() {
    Entity entity = null;
    try {
        entity = npc.getEntity();
    } catch (Exception ignored) {
    }
    LivingEntity li = entity instanceof LivingEntity ? (LivingEntity) entity : null;
    if (li != null) {
        if (invisible) {
            li.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1));
        } else {
            li.removePotionEffect(PotionEffectType.INVISIBILITY);
        }
        if (hatItem != null) {
            li.getEquipment().setHelmet(hatItem);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) PotionEffect(org.bukkit.potion.PotionEffect)

Example 45 with PotionEffect

use of org.bukkit.potion.PotionEffect 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)

Aggregations

PotionEffect (org.bukkit.potion.PotionEffect)224 Player (org.bukkit.entity.Player)61 PotionEffectType (org.bukkit.potion.PotionEffectType)39 Location (org.bukkit.Location)37 LivingEntity (org.bukkit.entity.LivingEntity)37 EventHandler (org.bukkit.event.EventHandler)36 ItemStack (org.bukkit.inventory.ItemStack)34 ArrayList (java.util.ArrayList)31 Entity (org.bukkit.entity.Entity)23 PotionMeta (org.bukkit.inventory.meta.PotionMeta)18 Vector (org.bukkit.util.Vector)16 Random (java.util.Random)14 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)11 ItemMeta (org.bukkit.inventory.meta.ItemMeta)10 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)9 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)9 Material (org.bukkit.Material)7 Enchantment (org.bukkit.enchantments.Enchantment)7 Projectile (org.bukkit.entity.Projectile)7 PotionData (org.bukkit.potion.PotionData)7