[Urgent] PotionEffectType.SPEED 2?

Discussion in 'Spigot Plugin Development' started by Blares, Jul 2, 2018.

  1. I need to check if a player has potioneffecttype.speed but wheres speed2 theres a difference between speed and speed 2 so... need some help -cheers blares.
     
  2. If I understand you need to check speed level ? (If player has speed 1|2|3...) ?
     
  3. Yes i need to be able to check speed 1 , 2 , and 3 hence making fly checks. Im checking if the player doesnt have speed measure -0.2709875385598468 which is the max double. please reply quicky.
     
  4. Assuming you also have the PotionEffect object, you should be able to use PotionEffect#getAmplifier()
     
  5. I haven't tested but I think it will work

    Code (Text):
    for(PotionEffect effects : player.getActivePotionEffects()) {          
        if(effects.getType() == PotionEffectType.SPEED) {              
            int speed_level = effects.getAmplifier();
            break;              
        }else continue;  
    }
     
  6. FrostedSnowman

    Resource Staff

    Code (Java):
    private boolean hasEffect(Player player, PotionEffectType type, int fixedAmplifier) {
         return player.getActivePotionEffects().stream()
              .filter(effect -> effect.getType().getName().equals(type.getName())
              .anyMatch(effect -> effect.getAmplifier() == fixedAmplifier - 1);
    }
    wrote this off the top of my head. basically, dont use the normal amplifiers. 1 will be level 1, 2 will be level 2, etc.