Remove item from inventory on PlayerDropItemEvent

Discussion in 'Plugin Development' started by dcgamingentral, Aug 19, 2013.

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

    dcgamingentral

    Hi,

    If a player drops an item I would like to stop the item dropping and remove the item from their inventory. I have coded this but it does not work.

    Code:
       
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onPlayerDropItem(PlayerDropItemEvent event) {
            event.setCancelled(true);
            event.getPlayer().getInventory().remove(event.getItemDrop().getItemStack());
        }
     
  2. Try using these two methods: https://github.com/blackwolf12333/G...33/grieflog/commands/CommandHandler.java#L230
     
  3. Offline

    dcgamingentral

  4. That is what you are trying to do ... |-(
     
  5. Offline

    dcgamingentral

    I need it to remove the item the player is dropping which might just be one item
     
  6. You already did this in your code: event.getItemDrop().getItemStack() ...
    Also an ItemStack can be just one...
     
  7. Offline

    dcgamingentral

    I said in the post that it did not work
     
  8. Okay, try this:
    Code:
    event.getPlayer().getInventory().remove(event.getItemDrop().getItemStack().clone().setAmount(1));
     
  9. Offline

    dcgamingentral

    That doesn't work either
     
Thread Status:
Not open for further replies.

Share This Page