Solved Potion effect not being removed.

Discussion in 'Plugin Development' started by mrdude123, Nov 22, 2015.

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

    mrdude123

    Hi. I'm using p.removePotionEffect(PotionEffectType.ABSORPTION); to remove a potion effect.
    However, the effect is not being removed. I've already tried checking for effect(s). Thanks for any help.
    Code:
    package me.thecerealkill3r.gapple;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerItemConsumeEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class Main extends JavaPlugin implements Listener{
    
        public void onEnable(){
            System.out.print("Gapple is up and running!");
              Bukkit.getPluginManager().registerEvents(this, this);
        }
       
        @EventHandler
       
        public void onEat(PlayerItemConsumeEvent e){
            Player p = e.getPlayer();
    
                if(e.getItem().getType() == Material.GOLDEN_APPLE){
                    p.removePotionEffect(PotionEffectType.ABSORPTION);
                   
               
            }
           
       
    }
    }
    
     
  2. Offline

    Xerox262

    You have to put it on a delay, the potion effect is not actually added until after the event has been handled.
     
  3. Offline

    Cerlurs

    Do you want it to remove only if they eat a gapple? Or just remove a player having the effect in general?
     
  4. Offline

    mrdude123

    Remove after the gapple has been consumed.
     
  5. Offline

    Cerlurs

    I'd suggest doing what @Xerox262 said, adding a delay.
     
    Xerox262 likes this.
  6. Offline

    Xerox262

    It's the reason your if didn't work either, they don't actually have the potion effect. If you wanted to that badly though you could cancel the event, remove the apple and just give them the other effects, but it's much easier to just delay the removal until after the event has been handled
     
  7. Offline

    mrdude123

    Already done. Thanks for the help guys.
     
Thread Status:
Not open for further replies.

Share This Page