Cancelling Drop Item From Inventory Slot

Discussion in 'Plugin Development' started by sharp237, Sep 29, 2012.

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

    sharp237

    How can I cancel a player dropping an item from a specific inventory slot? I need to stop a player dropping an item from inventory slot 8 and when its cancelled the item should return to slot 8 and not to the first slot.

    Is this possible?
     
  2. Offline

    Hertz

  3. Offline

    sharp237

    I know I need to use PlayerDropItemEvent, but how do I only cancel it if they drop an item from a specific inventory slot? And also I have noticed that when you cancel a PlayerDropItemEvent it will return the item to the far left slot on your hot bar, and not the inventory slot it was dropped from. How do I return it to the inventory slot it was dropped from?

    -=- bump -=-

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  4. Offline

    sharp237

    -=- bump -=-
     
  5. Offline

    The_Coder

  6. Offline

    sharp237

  7. Offline

    The_Coder

    Try it I don't know
     
  8. Offline

    sharp237

    Okay, I tried it, and it only stops a player clicking on items that are in their inventory. They can still use Q to drop it.
     
  9. Offline

    Deathmarine

    Code:java
    1.  
    2.  
    3. @EventHandler
    4. public void onItemDrop(PlayerDropItemEvent e){
    5. if(e.getPlayer().getInventory().getItem(8).getType().equals(e.getItemDrop().getItemStack().getType())){
    6. e.setCancelled(true);
    7. }
    8. }
    9.  

    I'm not sure if "type" is the check you want to preform but it works.

    Also fyi out of bounds item slots (not on a slot) is identified as slot -999 so if needs be you can cancel the drop from drag and drop in the inventory or selection in inventory by checking if the slot is -999.
     
  10. Offline

    sharp237

    Thanks :)
     
Thread Status:
Not open for further replies.

Share This Page