Solved Removing all potion effects?

Discussion in 'Plugin Development' started by RoboticPlayer, Oct 25, 2015.

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

    RoboticPlayer

    Sorry if the title is a little misleading, I do not mean that I want to remove all potion effects. In fact, it is the exact opposite. I am trying to remove only certain potion effects that the player has, but for some reason it is removing all of them. Here is what I have:
    Code:
    for (PotionEffect pe : p.getActivePotionEffects()) {
        PotionEffectType pt = pe.getType();
            if (pt == PotionEffectType.ABSORPTION || pt == PotionEffectType.DAMAGE_RESISTANCE
                || pt == PotionEffectType.FAST_DIGGING || pt == PotionEffectType.FIRE_RESISTANCE
                || pt == PotionEffectType.HEALTH_BOOST || pt == PotionEffectType.INCREASE_DAMAGE
                || pt == PotionEffectType.INVISIBILITY || pt == PotionEffectType.JUMP
                || pt == PotionEffectType.NIGHT_VISION || pt == PotionEffectType.REGENERATION
                || pt == PotionEffectType.SATURATION || pt == PotionEffectType.SPEED
                || pt == PotionEffectType.WATER_BREATHING)
            continue;
        p.removePotionEffect(pt);
    }
    I would think that this would only remove potion effects that weren't the ones I specified, but it is removing all of them. Anyone know what I am doing wrong?
     
  2. Offline

    567legodude

    @henderry2019 Maybe I'm missing something, but I don't see it. Why don't you try checking the ones you do want to remove instead of the ones you don't.
     
  3. Offline

    teej107

    @henderry2019 Just remove the ones you want. It won't make a difference if they had it or not to begin with.
     
  4. Offline

    Maxx_Qc

    Code:
            for(PotionEffect p : player.getActivePotionEffects())
            {   
                PotionEffectType pt = p.getType();
                if(pt == PotionEffectType.FIRE_RESISTANCE)
                {
                    player.removePotionEffect(pt);
                }
            }
     
  5. Offline

    teej107

    @Maxx_Qc You are seriously over complicating things
     
  6. Offline

    Maxx_Qc

    Why is that?
     
  7. Offline

    Xerox262

    Because you're checking to see if the player has the potion effect, doing something like
    Code:
    player.removePotionEffect(PotionEffectType.FIRE_RESISTANCE);
    works the same as
    Because it doesn't do anything if the player does not have the potion active.
     
    Maxx_Qc likes this.
  8. Offline

    teej107

    1. You are iterating over the player's active potion effects
    2. You are checking to see if a player has a potion effect
    3. You are then removing the potion effect
    You can skip steps 1 and 2.
     
    Maxx_Qc likes this.
  9. Offline

    RoboticPlayer

    I'm just going to remove the effects individually.
     
Thread Status:
Not open for further replies.

Share This Page