ItemStack changing its amount.

Discussion in 'Plugin Development' started by elementalgodz11, Apr 14, 2014.

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

    elementalgodz11

    So I'm trying to write a fix for dropping items {

    when you drop an item, if the event is cancelled, it will set it to the first empty in your hotbar; I am trying to keep it in the current slot.

    I have managed to do so sufficiently, but when I retrieve the item, the ItemStack size is always 1;

    What could I do to fix this?

    Here's my code:
    Code:java
    1. @EventHandler(priority = EventPriority.HIGH)
    2. public void onDrop(PlayerDropItemEvent event) {
    3.  
    4. if (plugin.getConfig().getBoolean("Fixes.Drop")) {
    5.  
    6. Player player = event.getPlayer();
    7.  
    8. final Item item = event.getItemDrop();
    9. ItemStack itemStack = item.getItemStack();
    10.  
    11. if (event.isCancelled()) {
    12.  
    13. event.setCancelled(false);
    14.  
    15. item.remove();
    16.  
    17. ItemStack droppedItem = itemStack.clone();
    18.  
    19. player.setItemInHand(droppedItem);
    20.  
    21. }
    22.  
    23. }
    24.  
    25. }



    Thanks.
     
Thread Status:
Not open for further replies.

Share This Page