Cancelling InventoryClickEvent - not working anymore

Discussion in 'Plugin Development' started by Door Knob, Dec 22, 2013.

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

    Door Knob

    Hi there. Before the update, I used to be able to cancel an InventoryClickEvent, and not have the item picked up by the cursor... It's kind of hard to explain, but this makes it so the player can't drag items from inventory to inventory, just click on it. Here's the code snippet that made it work before. It doesn't cancel the item dragging anymore.

    Code:java
    1. @EventHandler
    2. public void onClickInv(InventoryClickEvent e){
    3. if(quick_drugs){
    4. Player p = (Player)e.getWhoClicked();
    5. Inventory inv = e.getView().getTopInventory();
    6. Inventory binv = e.getView().getBottomInventory();
    7. ItemStack is = e.getCurrentItem();
    8. int s = e.getRawSlot();
    9. if(inv.getName().equals(window_title)){
    10. if(is != null){
    11. if(s == 2){ // cocaine
    12. if(p.getInventory().containsAtLeast(new ItemStack(Material.EMERALD), cocaine_price)){
    13. e.setCancelled(true);
    14. ItemStack remove = new ItemStack(Material.EMERALD, cocaine_price);
    15. if(p.getGameMode() != GameMode.CREATIVE)
    16. p.getInventory().removeItem(remove);
    17. p.getInventory().addItem(is);
    18. for(int i = 0; i < binv.getSize(); i++){
    19. ItemStack iss = binv.getItem(i);
    20. if(iss != null){
    21. if(iss.getType() == Material.getMaterial(cocaine_id)
    22. && iss.getDurability() == cocaine_data){
    23. setLore(iss, null);
    24. }
    25. }
    26. }
    27. p.updateInventory();
    28. }
    29. //... more code blah blah not important
    30.  


    Everything else works, except for e.setCancelled(true);
     
  2. Offline

    LazyLemons

    InventoryClickEvent cancelling was bugged client-side, until 1.7.3. Update and you should be good.
     
  3. Offline

    Door Knob

    Wow, thanks a lot.
     
Thread Status:
Not open for further replies.

Share This Page