Get length of potion effects

Discussion in 'Plugin Development' started by Elimnator, Jun 14, 2014.

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

    Elimnator

    How can I get the length of potion effects players have applied to them?
     
  2. Offline

    jthort

  3. Offline

    Elimnator

    jthort
    Thats how you get the length of an effect, but how do I get the effect from an entity?
     
  4. Offline

    jthort

    You asked how can i get the length of the potion effects

    Do you mean you want the type of effect the entity has?
     
  5. Offline

    Elimnator

    jthort
    I mean get the potion effect from an entity, then check its duration.
     
  6. Offline

    Elimnator

    Can anyone help?

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  7. Offline

    AoH_Ruthless

    Elimnator
    Don't bump your post more than once per 24 hours.

    You can loop through a player's active potion effects. Not sure about regular entities though.
    Code:java
    1. Collection<PotionEffect> effects = p.getActivePotionEffects();
    2. for (PotionEffect e : effects) {
    3. e.getDuration();
    4. }
     
  8. Offline

    unrealdesign

    You can look in the API can't you? You want to know how to get potion effects from an entity. You should know only LivingEntities can have potion effects. Didn't know that? Then you can just use Player for example.

    Google: Bukkit Player. Find the API. ctrl+f for "Potion" and look till you find something that gets what you want. You'll notice: getActivePotionEffects() in the API under inherited from LivingEntity. This will tell you that you can't get potion effects from and Entity because only Living Entities can have potion effects.

    So in your case you can't get them from any entity. You have to check if they are a LivingEntity, and if they are you can use the method getActivePotionEffects().

    Good luck!
     
    AoH_Ruthless likes this.
Thread Status:
Not open for further replies.

Share This Page