[Tutorial] Cancel ItemDrop the right way

Discussion in 'Resources' started by FisheyLP, Apr 1, 2014.

?

Did that help you?

  1. Yes

    3 vote(s)
    50.0%
  2. No

    3 vote(s)
    50.0%
Thread Status:
Not open for further replies.
  1. You tried to cancel the PlayerDropItemEvent with only e.setCancelled(true);, and it didn't worked, too if you used player.updateInventory(); ? Then i can say you a small but good working code that works perfectly :D
    Code:Java
    1.  
    2. @EventHandler
    3. public void onDrop(PlayerDropItemEvent event) {
    4. Player p = event.getPlayer();
    5. event.setCancelled(true);
    6. p.getInventory().setContents(p.getInventory().getContents());
    7. p.getInventory().setArmorContents(p.getInventory().getArmorContents());
    8. }
    9.  

    It just cancels the dropevent and give the player each item he had in his inventory back. I hope that helped you :)
    (Dont forget to register the events in onEnable() and implement Listener in your class)
     
  2. Offline

    EnderPilot105

  3. Offline

    Garris0n

    This doesn't even make sense...
     
    glen3b, LegitJava, RawCode and 6 others like this.
  4. Offline

    MisterErwin

    I guess those methods send the Inventory Packets to the client, same as updateInventory() did...
     
  5. Offline

    Garris0n

    Neither using updateInventory() nor setting their inventory to...their inventory is going to change much of anything about the event.
     
  6. thats not true, if you just use setCancelled it dont updates the inventory and it is buggy, the same with updateInventory . my code works without any bugs too if it makes nonsense to give them their own inventory contents but it works well :D
     
  7. Offline

    Garris0n

    I don't recall having experienced such a thing. Could you explain what you mean by "it dont updates the inventory"?
     
  8. Offline

    97WaterPolo

    Garris0n
    I have experienced this glitch before, it creates a ghost item that doesn't really go away on player.updateInvrntory (). I believe it was fixed in 1.7.4 update so it doesn't really effect it anymore?
     
  9. Offline

    Garris0n

    That was a glitch that, from what I tested, only affected setting the cursor in the inventory. I am not aware of any issues with dropping items.
     
  10. Offline

    iiHeroo

    I had an issue of this, but the thing was, it reappeared if I clicked an item in my inventory or after some time, so now you'll be doubling of what you dropped...
     
  11. with "it dont updates the inventory" i mean, when you drop a item, its away until you drop another item because then the inventory gets again updated
     
  12. Offline

    RawCode

    you shoud update only specific slot, not entire inventory.

    this "tutorial" is about invalid coding about using methods without any clue about what methods actually does.
     
    Garris0n likes this.
  13. Offline

    Borlea

    I think it was recently fixed in one of the 1.7.x patches
    If you cancelled anything that would remove items in your inventory, it wouldn't remove the item. but it wouldn't update the inventory. If you placed a dirt block and cancelled the event it wouldn't appear in your inventory if you cancelled the event, but it is still in your inventory
     
Thread Status:
Not open for further replies.

Share This Page