Get a livingentities potioneffect level

Discussion in 'Plugin Development' started by Danteland, Jan 7, 2015.

Thread Status:
Not open for further replies.
  1. Offline


    Hi, I know that you are able to get if an entity has a potion effect. But is it possible to get the level of the potion effect as well?
  2. Offline


    You'd need to start with LivingEntity.getActivePotionEffects() and find the one you're looking for, from there you can use PotionEffect.getAmplifier().
  3. Offline


    Thank you!

    Thanks I tried looking in to it but I'm quite new to programming so collections isn't something im very familiar with. would you be very kind and help me. This is the code i tried. It doesn't work though.
    I'm trying to set the entity's potion effect amplifier to one higher from what it is.

        if(event.getEntity() instanceof LivingEntity) {
             LivingEntity ent = (LivingEntity) event.getEntity();
             PotionEffectType pe = potionId.get(arId).getEffectType();
             if(!ent.getActivePotionEffects().isEmpty()) {
               PotionEffect po = ent.getActivePotionEffects().iterator().next();
               while(po.getType() != pe) {
                   po = ent.getActivePotionEffects().iterator().next();
               ent.addPotionEffect(pe.createEffect(300, po.getAmplifier() + 1));
             } else {
               ent.addPotionEffect(pe.createEffect(300, 0));
    Last edited by a moderator: Jan 7, 2015
Thread Status:
Not open for further replies.

Share This Page