InventoryClickEvent: Shift-click duplicates item

Discussion in 'Plugin Development' started by Wbjpen, Nov 11, 2014.

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

    Wbjpen

    So I'm trying to cancel InventoryClickEvent when you click on a item with a specific lore. When I shift-click it in the inventory, it duplicates the item and puts it in the inventory. It's not a ghost, I assure you (I can make a beacon from it)

    Code:
            if(p instanceof Player)
            {
                if(e.getView().getTopInventory().getType().equals(InventoryType.PLAYER))
                {
                    if(e.getCurrentItem().hasItemMeta())
                    {
                        if(e.getCurrentItem().getItemMeta().getDisplayName().contains("§e§lBind: "))
                        {
                            if(e.getSlot() >= 0 && e.getSlot() <= 8)
                            {
                                e.setCancelled(true);
                                p.updateInventory();
                                p.closeInventory();
                                e.setResult(Result.DENY);
                            }
                        }
                    }
                }
    }
    When I take out the getSlot, getDisplayName and hasItemMeta lines, it works fine, but it'll just cancel every InventoryClickEvent event.
     
  2. Offline

    guitargun

    Wbjpen set the cursor to air and then cancel it. this should prevent a duplicate.
     
  3. Offline

    Wbjpen

    I added e.setCursor(new ItemStack(Material.AIR));
    That didn't work.
     
Thread Status:
Not open for further replies.

Share This Page