Checking player has potion effect not working?

Discussion in 'Plugin Development' started by belven000, Jul 20, 2014.

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

    belven000

    I'm just try to prevent giving players the same potion effect 2x but neither of the methods I've tried have worked.

    Here's the whole method:
    Code:java
    1. @Override
    2. public boolean PerformAbility(Player playerToHeal)
    3. {
    4. PotionEffect pe = new PotionEffect(PotionEffectType.HEALTH_BOOST,
    5. functions.SecondsToTicks(Amplifier() + 30), Amplifier(), true);
    6.  
    7. if (!onCooldown
    8. && (!containsEffect(PotionEffectType.HEALTH_BOOST, playerToHeal) || !playerToHeal
    9. .getActivePotionEffects().contains(pe)))
    10. {
    11. playerToHeal.addPotionEffect(pe, false);
    12.  
    13. currentClass.classOwner.sendMessage("You boosted "
    14. + playerToHeal.getName() + "s max health");
    15. currentClass.setAbilityOnCoolDown(this, true);
    16. return true;
    17. }
    18. return false;
    19. }
    20.  
    21. public boolean containsEffect(PotionEffectType pet, Player playerToHeal)
    22. {
    23. for (PotionEffect pe : playerToHeal.getActivePotionEffects())
    24. {
    25. if (pe.getType().equals(pet))
    26. {
    27. return true;
    28. }
    29. }
    30. return false;
    31. }
    32.  
    33.  


    For some reason neither containsEffect() or !playerToHeal .getActivePotionEffects().contains(pe) are working?

    Any ideas?
     
  2. Offline

    jeussa

    When checking if a player has a certain potioneffect, you can simply use:

    Code:java
    1. player.hasPotionEffect(PotionEffectType.YOUR_TYPE);
     
  3. Offline

    belven000

    jeussa thanks, just wonder why my methods didn't work, anyone know?
     
Thread Status:
Not open for further replies.

Share This Page