PlayerPickupItemEvent not working

Discussion in 'Plugin Development' started by Luflexed, Mar 15, 2015.

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

    Luflexed

    I've been coding a ffa core and I coded it so when you pick up a nether star you should get regeneration 4 for 4 seconds, but it dosen't give you it.

    Here is the code:
    Code:
    package me.Alex.LegacyCore;
    
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerPickupItemEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class Regen implements Listener {
       
        @EventHandler
        public void onDeath(PlayerDeathEvent e){
            e.getDrops().clear();
            e.getDrops().add(new ItemStack(Material.NETHER_STAR, 1));
        }
       
        @EventHandler
        public void onPickup(PlayerPickupItemEvent e){
            Player p = e.getPlayer();
            if(p.getInventory().contains(Material.NETHER_STAR)){
                ItemStack m = new ItemStack(Material.NETHER_STAR, 1);
                p.getInventory().removeItem(m);
                p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 4, 4));
            }
        }
    }
    Please help.

    Edit: I have also tried doing:
    Code:
    if(e.getType() == new ItemStack(Material.NETHER_STAR)){
    But that did not work either.

    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
  2. e.getItem().getItemStack().getType()
    then cancel the event and remove the item from world
     
  3. Offline

    Luflexed

    Thanks for the advice @FisheyLP, it worked!
     
Thread Status:
Not open for further replies.

Share This Page