Solved Getting potion effects on an entity

Discussion in 'Plugin Development' started by LordPyrak, Dec 7, 2013.

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

    LordPyrak

    I'm working on a plugin that involves sheep that have infinite invisibility potions on them. I want to be able to cancel a shear event, but only if the sheep has an invisibility effect. I've searched high and low to find a method to get potion effects, but no avail. Is there anyway to do this, and if not, how would I do this using Metadata? (I'm new to java).
     
  2. Hey, you might want to use .hasPotionEffect
    if(Entity.hasPotionEffect(PotionEffectType.YOUR_POTION_EFFECT)){
    }
    EDIT: some code that might help you,
    Code:java
    1. @EventHandler
    2. public void onShearSheep(PlayerShearEntityEvent e){
    3. if(e.getEntity().getType() == EntityType.SHEEP && ((LivingEntity) e.getEntity()).hasPotionEffect(PotionEffectType.INVISIBILITY)){
    4. //Your sheep is invisible!
    5. e.setCancelled(true);
    6. }
    7. }

    forgot to tag you ;) LordPyrak
     
    LordPyrak likes this.
  3. Offline

    LordPyrak

    I just realized I was trying to use Entity instead of LivingEntity, lol.
    Thanks much! :)
     
  4. Offline

    LordPyrak

    Nope, soon my server will be full of ghostly sheep :D
     
Thread Status:
Not open for further replies.

Share This Page