1.15.2 ItemMoveEvent

Discussion in 'Spigot Plugin Development' started by Zmars, Jan 11, 2020.

  1. Hi!
    Is there some way to cancel moving items in opened gui?
     
  2. You can set InventoryClick to canceled when the player has that GUI opened.
    Code (Java):
        e.setCancelled(true);
     
  3. like that?
    Code (Java):
        public void click (InventoryClickEvent e){
            e.setCancelled(true);
        }
     
  4. Yes, but that'll cancel inventory clicks for all inventories. You want to check if the inventory is the GUI.
     
  5. But it doesn´t work for any inventory :D
     
  6. In my plugins I check to see if the title of the open inventory is the same as the GUI's title. If it's not, I just ignore the event.
     
  7. Can i write a message to u?
     
  8. Sure, I'm glad to help
     
  9. Have you registered your listener class?
     
  10. This works for me, (if this helps please rate me :))

    Code (Text):
    @EventHandler
        public static void onInventoryClick(InventoryClickEvent e) {
            if (e.getClickedInventory() == null)
                return;

            if (e.getInventory().equals(<the name of the inventory you dont want to be touched>)) {
                if (e.getClickedInventory().equals(e.getWhoClicked().getInventory())) {
                    e.setCancelled(true);
                }

                e.setCancelled(true);
    }}}