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

The following examples show how to use org.bukkit.entity.LivingEntity#getActivePotionEffects() . 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: CivPotionEffect.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
@Override
public HashMap<String, Double> getVariables() {
    HashMap<String, Double> returnMap = new HashMap<String, Double>();
    Object target = getTarget();
    if (!(target instanceof LivingEntity)) {
        return returnMap;
    }
    LivingEntity livingEntity = (LivingEntity) target;
    if (!livingEntity.hasPotionEffect(this.type)) {
        return returnMap;
    }
    for (PotionEffect potionEffect : livingEntity.getActivePotionEffects()) {
        if (potionEffect.getType().equals(this.type)) {
            returnMap.put("ticks", (double) potionEffect.getDuration());
            returnMap.put("level", (double) potionEffect.getAmplifier());
            break;
        }
    }
    return returnMap;
}
 
Example 2
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 3
Source File: PotionUtil.java    From AACAdditionPro with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets a {@link PotionEffect} of a {@link LivingEntity}.
 *
 * @param livingEntity the {@link LivingEntity} which should be tested
 * @param type         the {@link PotionEffectType} which should be tested for
 *
 * @return the {@link PotionEffect} with the provided {@link PotionEffectType} or null if the {@link LivingEntity}
 * doesn't have such a {@link PotionEffect}.
 */
public static PotionEffect getPotionEffect(final LivingEntity livingEntity, final PotionEffectType type)
{
    switch (ServerVersion.getActiveServerVersion()) {
        case MC188:
            for (final PotionEffect effect : livingEntity.getActivePotionEffects()) {
                if (effect.getType().equals(type)) {
                    return effect;
                }
            }
            return null;
        case MC112:
        case MC113:
        case MC114:
        case MC115:
            return livingEntity.getPotionEffect(type);
        default:
            throw new UnknownMinecraftVersion();
    }
}
 
Example 4
Source File: CombatLogTracker.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private static double getResistanceFactor(LivingEntity entity) {
  int amplifier = 0;
  for (PotionEffect effect : entity.getActivePotionEffects()) {
    if (PotionEffectType.DAMAGE_RESISTANCE.equals(effect.getType())
        && effect.getAmplifier() > amplifier) {
      amplifier = effect.getAmplifier();
    }
  }
  return 1d - (amplifier / 5d);
}
 
Example 5
Source File: CombatLogTracker.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private static double getResistanceFactor(LivingEntity entity) {
    int amplifier = 0;
    for(PotionEffect effect : entity.getActivePotionEffects()) {
        if(PotionEffectType.DAMAGE_RESISTANCE.equals(effect.getType()) && effect.getAmplifier() > amplifier) {
            amplifier = effect.getAmplifier();
        }
    }
    return 1d - (amplifier / 5d);
}
 
Example 6
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 7
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 8
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 9
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 10
Source File: CombatLogTracker.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
private static boolean hasFireResistance(LivingEntity entity) {
  for (PotionEffect effect : entity.getActivePotionEffects()) {
    if (PotionEffectType.FIRE_RESISTANCE.equals(effect.getType())) return true;
  }
  return false;
}
 
Example 11
Source File: Poisonous.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
	if (!dropPoisonedMeat) {
		return;
	}

	LivingEntity mob = event.getEntity();
	Player player = mob.getKiller();

	if (player == null) {
		return;
	}

	if (Lists.WORLDS.contains(player.getWorld().getName())) {
		return;
	}

	boolean isPoisoned = false;

	for (PotionEffect potionEffect : mob.getActivePotionEffects()) {
		if (potionEffect.getType() == PotionEffectType.POISON) {
			isPoisoned = true;
			break;
		}
	}

	if (!isPoisoned) {
		return;
	}

	int numberOfMeat = 0;
	int numberOfPotatoes = 0;

	Iterator<ItemStack> iterator = event.getDrops().iterator();

	while (iterator.hasNext()) {
		ItemStack drop = iterator.next();
		if (isMeat(drop)) {
			iterator.remove();
			numberOfMeat++;
		} else if (drop.getType() == Material.POTATO) {
			iterator.remove();
			numberOfPotatoes++;
		}
	}

	ChatWriter.logModifier(player, event, this, player.getInventory().getItemInMainHand(),
			"Entity(" + event.getEntity().getType().toString() + ")");

	if (numberOfMeat > 0) event.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, numberOfMeat));
	if (numberOfPotatoes > 0) event.getDrops().add(new ItemStack(Material.POISONOUS_POTATO, numberOfPotatoes));
}
 
Example 12
Source File: CombatLogTracker.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
private static boolean hasFireResistance(LivingEntity entity) {
    for(PotionEffect effect : entity.getActivePotionEffects()) {
        if(PotionEffectType.FIRE_RESISTANCE.equals(effect.getType())) return true;
    }
    return false;
}