Solved Item Drop Event

Discussion in 'Plugin Development' started by njb_said, Mar 8, 2013.

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

    njb_said

    Im trying to make bowls not drop but drop at the same time.
    I have insta soup. Im trying to make the bowl after souping just disappear not drop on the ground or go somewhere in inventory.
    Code:
        @EventHandler
        public void onItemDrop (PlayerDropItemEvent e) {
            Player p = e.getPlayer();
            if (Util.isIngame(p)) {
                Item drop = e.getItemDrop();
                if (drop.getItemStack().getTypeId() == 281) {
                    drop.getItemStack().setAmount(0);
                } else {
                e.setCancelled(true);
                }
            }
        }
    Hope this makes sense :p
    (This is for my kitpvp plugin)

    Ive tried many ways cancelling and setting amount to 0
    Setting item stack to air
    Setting item that drops to air
    Setting item in hand to air
     
    FlaveDrake likes this.
  2. Offline

    Burnett1

    So you want to remove the bowl after they eat the soup?
     
  3. Offline

    njb_said

    no when they goto drop the bowl it just disappears not when they eat the soup.
     
  4. Offline

    Codisimus

    You are looking for the ItemSpawnEvent.

    EDIT:
    When an ItemStack is dropped, an Item Entity is spawned.
     
  5. Offline

    Burnett1

    You can try this it will remove all the empty bowls in the inventory, ill try change it to remove just the one dropped.
    Code:
        @EventHandler
        public void onItemDrop (PlayerDropItemEvent e) {
            Player p = e.getPlayer();
           
                Item drop = e.getItemDrop();
                if (drop.getItemStack().getTypeId() == 281) {
                    e.setCancelled(true);
                    p.getInventory().remove(281);   
                } else {
                e.setCancelled(true);
                }
           
        }
     
  6. Offline

    Codisimus

    Not Tested*

    Code:
    @EventHandler
    public void onItemSpawn(ItemSpawnEvent event) {
        e.setCancelled(event.getEntity().getItemStack().getType() == Material.BOWL);
    }
     
  7. Offline

    Burnett1

    Tested and works. Remember to register events.


    Code:
        @EventHandler
        public void onItemSpawn(ItemSpawnEvent event) {
            boolean n = event.getEntity().getItemStack().getType() == Material.BOWL;
                if(n == true){
                    event.getEntity().remove();
                   
                }   
        }
     
  8. Offline

    njb_said

    Thanks works now :)
     
  9. Wouldn't ItemSpawnEvent also trigger when mobs die, blocks are destroyed and more importantly when chests are destroyed and their contents spits out... so that means you'll just prevent spawning of ANY bowl, not just by player dropping.

    If you want only by player dropping go back to your initial event and use setCancelled() there... but in reverse, I don't know why you canceled it when you drop anything but item 281 (which I assume it's bowl ?) so basically you were allowing bowl drop, just with amount 0, which may get very glitched.
     
  10. Offline

    Codisimus

    Digi I just assumed he would want to get rid of any empty bowl that was dropped.
     
Thread Status:
Not open for further replies.

Share This Page