[SPIGOT-6008] Opening an inventory from within an InventoryClickEvent triggers a player interaction Created: 18/Jul/20  Updated: 19/Jul/20  Resolved: 18/Jul/20

Status: Closed
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Pyves Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: 1.16.1, InventoryClickEvent

Version: git-Spigot-d4cbb64-2361cb8 (MC: 1.16.1)
Guidelines Read: Yes

 Description   

Programmatically opening an inventory from within an InventoryClickEvent listener causes a player interaction (i.e. as if the player right or left clicked without any inventory open). This only seems to happen if you click on an item in the existing inventory rather than an empty slot (i.e. InventoryAction of type PICKUP_*).

Here is a simple piece of code to reproduce the behaviour:

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
	Inventory inventory = Bukkit.createInventory(null, 18, "some title");
	inventory.setItem(0, new ItemStack(Material.DIAMOND_SWORD));
	((Player) event.getWhoClicked()).openInventory(inventory);
}

Simply open your usual player inventory. Click on any item you're carrying. A player interaction will be triggered.

Opening inventories like this from within InventoryClickEvents is common amongst plugins that implement their own custom GUI, for example with paginated or multi-layered inventories. As an example, this is causing issues in Advanced Achievements (https://github.com/PyvesB/AdvancedAchievements/issues/783).

Note that this worked fine with all Minecraft versions from 1.15 all the way back to at least 1.7, and only started happening in Spigot 1.16 builds.

Thanks for reading.



 Comments   
Comment by md_5 [ 19/Jul/20 ]

>why is no PlayerInteractEvent being fired by Spigot in this case, contrarily to SPIGOT-5974?'

Because eg you're not aimed at air

Comment by Pyves [ 19/Jul/20 ]

So, is there no way at all to handle this behaviour, whether it be in Spigot or in plugins? Also, I'm still not fully on board with the explanations: if it is a client thing and if there is a PacketPlayInArmAnimation packet sent back to the server as claimed by SPIGOT-5974, why is no PlayerInteractEvent being fired by Spigot in this case, contrarily to SPIGOT-5974?

Comment by md_5 [ 19/Jul/20 ]

Yes, the client swinging its hand is a client thing and not caused by or fixable by Spigot (as the duplicated ticket shows)

Comment by Pyves [ 19/Jul/20 ]

"the event is click air" is still unclear. The only event that the title of the ticket refers to is "InventoryClickEvent". As mentioned in the description, it's a PICKUP_ALL/PICKUP_HALF/etc. event, not click air.

As explained, there is a player interaction (i.e. arm swinging, fist waving, using, use item in hand, describe it however you like), but no PlayerInteractEvent. I carefully omitted talking about any other Spigot events, as I can't observe any relevant ones.

Comment by md_5 [ 19/Jul/20 ]

Literally the title of your ticket is 'Opening an inventory from within an InventoryClickEvent triggers a* player interaction*'

Comment by Pyves [ 19/Jul/20 ]

Could you please clarify "the event is click air"? If you're referring to a PlayerInteractEvent, unlike SPIGOT-5974, I do not observe any PlayerInteractEvents as a result of the player interactions/arm swinging described here.

Comment by md_5 [ 18/Jul/20 ]

Seems like a duplicate to me.

If the client is swinging their arm and the event is click air, it's a duplicate.

Comment by Pyves [ 18/Jul/20 ]

No, this is probably not a duplicate. The other issue, which I had read before opening this one, involves programmatically canceling events when dropping items, which is not at all the issue at hand here. Users take time to report and properly document bugs like I did here, and I've got the bitter feeling it was not even read. Closing just because they're both about InventoryClickEvents seems rash and premature.

Comment by Black Hole [ 18/Jul/20 ]

Duplicate of SPIGOT-5974

Generated at Tue Apr 15 09:41:34 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.