Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-4407

It appears that inventoryClick event occasionally fails to fire.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: Minor Minor
    • None
    • None
    • General Plugin Development

    •  INFO This server is running CraftBukkit version git-Spigot-f6a273b-68588da (MC: 1.13.1) (Implementing API version 1.13.1-R0.1-SNAPSHOT)
    • Yes

      While working on a plugin I have noticed that sometimes the inventory click event fails to fire when placing objects in slots.

      I am attempting to prevent a player from placing items on specific slots in an inventory.

      I was quite sure my code was correct so I added a debug message and did notice that the event didn't seem to fire occasionally and I can not track down why.

       

      I have attached some debug code to make reproducing the issue easier.

      public class TradeListener implements Listener {	Shop plugin;
      	static int clickCount = -1;
      	static int foundCount = 0;
      	static Inventory testInv;
      	
      	public TradeListener(Shop shop) {
      		this.plugin = shop;
      		testInv = Bukkit.createInventory(null, 27, "TestInv");
      		
      	}	@EventHandler 
      	public static void onSneak(PlayerToggleSneakEvent e)
      	{
      		if(e.getPlayer().isOp() && e.getPlayer().getName().equalsIgnoreCase("dNiym") && !e.getPlayer().isSneaking()) {
      			clickCount = 0;
      			foundCount = 0;
      			e.getPlayer().sendMessage("Opening inventory and clearing stats");
      			e.getPlayer().openInventory(testInv);
      		}
      		
      	}
      	
      	@EventHandler
      	public static void onInventoryClick(InventoryClickEvent e)
      	{
      		
      		clickCount++;
      		if(e.getClickedInventory().getName().equalsIgnoreCase(testInv.getName())) {
      			foundCount++;
      			e.setCancelled(true);
      			e.getWhoClicked().sendMessage("CANCELLED -> Click Count: " + clickCount + " - Found Count: " + foundCount + " name was: " + e.getClickedInventory().getName());
      			return;
      		}
      		e.getWhoClicked().sendMessage("ALLOWED -> Click Count: " + clickCount + " - Found Count: " + foundCount + " name was: " + e.getClickedInventory().getName());
      		
      		
      	}
      }
      

      You should be able to drop this in and register it as a listener and reproduce the bug.  For some reason it seems the middle row seems most affected as if you pick up a stack of items and right click to drop them in the slots they'll eventually go in despite they should be cancelled.   The second debug message *ALLOWED only appears if you click on the lower inventory as the event should only cancel on the UPPER inventory.   The allowed message never appears on the upper inventory click which leads me to believe that the event isn't firing thus not being cancelled.

       

       

      I have not been able to get the items out of the inventory only add them which makes me think the event isn't always firing on the right click drop.   No errors in the console when this happens.

       

      I have uploaded a video of this issue happening here: https://vimeo.com/292987616

            Unassigned Unassigned
            whoolieshop Shane Martin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: