Solved InventoryClickEvent problem

Discussion in 'Plugin Development' started by sQuetch, Apr 3, 2021.

  1. Offline

    sQuetch

    Hey everyone,
    I am struggling with the InventoryClickEvent problem, or more precisely, I do not know what to do to cancel the event when I click on an item in my inventory.
    I mean, it works, but not like with custom equipment (for example a chest).

    Code:
    Code:
        @EventHandler(priority = EventPriority.NORMAL)
        public void onInventoryClick(InventoryClickEvent e) {
            if(e.getClick().equals(ClickType.LEFT)) {
                if(e.getInventory().getType().equals(InventoryType.PLAYER)) {
                    e.setCancelled(true);
                }
            }
            if(e.getClick().equals(ClickType.RIGHT)) {
                if(e.getInventory().getType().equals(InventoryType.PLAYER)) {
                    e.setCancelled(true);
                }
            }
        }
    Video:


    I hope I explained my problem well :eek:
    Thank you in advance!
     
  2. Offline

    Newdel

    You are checking and cancelling every InventoryClickEvent.
    When you create a GUI or chest, give it a name and check if the clicked inventory name is equals the specified inventory name
     
  3. Offline

    sQuetch

    Wow, it was so easy... thank you so much!
     
    Newdel likes this.

Share This Page