Java Code Examples for org.bukkit.entity.LivingEntity#removePotionEffect()

The following examples show how to use org.bukkit.entity.LivingEntity#removePotionEffect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EffPoison.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void execute(final Event e) {
	for (final LivingEntity le : entites.getArray(e)) {
		if (!cure) {
			Timespan dur;
			int d = (int) (duration != null && (dur = duration.getSingle(e)) != null ? 
					(dur.getTicks_i() >= Integer.MAX_VALUE ? Integer.MAX_VALUE : dur.getTicks_i()) : DEFAULT_DURATION);
			if (le.hasPotionEffect(PotionEffectType.POISON)) {
				for (final PotionEffect pe : le.getActivePotionEffects()) {
					if (pe.getType() != PotionEffectType.POISON)
						continue;
					d += pe.getDuration();
				}
			}
			le.addPotionEffect(new PotionEffect(PotionEffectType.POISON, d, 0), true);
		} else {
			le.removePotionEffect(PotionEffectType.POISON);
		}
	}
}
 
Example 2
Source File: PotionEffectSerializer.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Remove any current PotionEffects from a LivingEntity then add the given effects.
 *
 * @param code   The PotionEffects to add.
 * @param entity The entity to set the PotionEffects.
 *
 * @deprecated Magic numbers.
 */
@Deprecated
public static void setPotionEffects(String code, LivingEntity entity) {
    if (entity.getActivePotionEffects() != null && !entity.getActivePotionEffects().isEmpty()) {
        for (PotionEffect effect : entity.getActivePotionEffects()) {
            entity.removePotionEffect(effect.getType());
        }
    }

    addPotionEffects(code, entity);
}
 
Example 3
Source File: PotionEffectSerializer.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Remove any PotionEffects the entity currently has, then apply the new effects.
 *
 * @param effects The PotionEffects to apply.
 * @param entity The entity to apply the effects to.
 */
public static void setPotionEffects(JsonArray effects, LivingEntity entity) {
    if (entity.getActivePotionEffects() != null && !entity.getActivePotionEffects().isEmpty()) {
        for (PotionEffect effect : entity.getActivePotionEffects()) {
            entity.removePotionEffect(effect.getType());
        }
    }

    addPotionEffects(effects, entity);
}
 
Example 4
Source File: PotionEffectSerializer.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Remove any current PotionEffects from a LivingEntity then add the given effects.
 *
 * @param code   The PotionEffects to add.
 * @param entity The entity to set the PotionEffects.
 *
 * @deprecated Magic numbers.
 */
@Deprecated
public static void setPotionEffects(String code, LivingEntity entity) {
    if (entity.getActivePotionEffects() != null && !entity.getActivePotionEffects().isEmpty()) {
        for (PotionEffect effect : entity.getActivePotionEffects()) {
            entity.removePotionEffect(effect.getType());
        }
    }

    addPotionEffects(code, entity);
}
 
Example 5
Source File: PotionEffectSerializer.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Remove any PotionEffects the entity currently has, then apply the new effects.
 *
 * @param effects The PotionEffects to apply.
 * @param entity The entity to apply the effects to.
 */
public static void setPotionEffects(JsonArray effects, LivingEntity entity) {
    if (entity.getActivePotionEffects() != null && !entity.getActivePotionEffects().isEmpty()) {
        for (PotionEffect effect : entity.getActivePotionEffects()) {
            entity.removePotionEffect(effect.getType());
        }
    }

    addPotionEffects(effects, entity);
}
 
Example 6
Source File: PotionEffectApplier.java    From EliteMobs with GNU General Public License v3.0 2 votes vote down vote up
private void eventPotionEffectApplier(HashMap<PotionEffect, List<String>> potionEffects, Player
        player, LivingEntity livingEntity) {

    for (PotionEffect potionEffect : potionEffects.keySet()) {

        if (potionEffects.get(potionEffect).size() > 0) {

            if (potionEffects.get(potionEffect).get(0).equalsIgnoreCase(SELF)) {

                player.removePotionEffect(potionEffect.getType());
                player.addPotionEffect(potionEffect);

                if (potionEffects.get(potionEffect).size() > 1) {

                    if (potionEffects.get(potionEffect).get(1).equalsIgnoreCase(CONTINUOUS)) {

                        player.removePotionEffect(potionEffect.getType());

                    }

                }


            } else if (potionEffects.get(potionEffect).get(0).equalsIgnoreCase(TARGET)) {

                livingEntity.removePotionEffect(potionEffect.getType());
                livingEntity.addPotionEffect(potionEffect);

            }

        } else {

            //legacy config settings where there are no tags
            if (offensivePotionEffects.contains(potionEffect.getType())) {

                livingEntity.removePotionEffect(potionEffect.getType());
                livingEntity.addPotionEffect(potionEffect);

            }

        }

    }

}