[SPIGOT-5672] InventoryClickEvent called for every similar ItemStack Created: 13/Apr/20  Updated: 01/May/20  Resolved: 01/May/20

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

Type: Bug Priority: Minor
Reporter: GitGraf Assignee: Unassigned
Resolution: Done Votes: 0
Labels: API, InventoryClickEvent
Environment:

Windows 10

Java 1.8.0_202


Attachments: PNG File message_printed_5_times.png    
Version: This server is running CraftBukkit version git-Spigot-ae72bf4-183139d (MC: 1.15.2) (Implementing API version 1.15.2-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

I added the following listener to my plugin:

  @EventHandler
  public void onClick(InventoryClickEvent e) {
    e.setCancelled(true);
    e.getWhoClicked().sendMessage("You clicked on " + e.getCurrentItem());
  }

 

For the most part, this works as expected: The event is cancelled (cannot take item out of the inventory) and a message about the clicked item is displayed.

However, when I perform a fast double-click (like when collecting items to cursor) while holding shift, it seems to print the message twice (because of double-click) and then once again for every similar ItemStack in the inventory.

Example: If there are 5 diamonds in slots of the inventory, the message will be printed 7 times (2 times for the doubleclick - OK, and 5 times again for every diamond - Bug?).

If we had a chest inventory with a diamond in every slot, and we shift-double-clicked one of them, the message would be printed 29 times.

This also seems to occur when the amounts on the ItemStacks differ (Doesn't matter if it's one diamond in the slot or 64).

 

===

What I'm trying to achieve: I'm working on an Inventory API and would like to allow users to use normal clicks or shift-click. However, due to the aforementioned behaviour, I have to disallow shift-clicks as a safety measure.



 Comments   
Comment by GitGraf [ 01/May/20 ]

Well, that's a shame. I was thinking this type of behaviour could be the result of a simple oversight somewhere in Spigot Code. Since we now know that the problem is client bound, I'm guessing that this ticket will be closed ...

I'll try to implement a workaround then, like mentioned in the comment above.

Thanks for investigating!

Comment by Ugleh [ 24/Apr/20 ]

The Client is telling the Server via packets that you are picking up all of those items and moving them another slot. The server interprets that as InventoryClickEvent for each item. There is no way to differentiate that since all events fired are (in this case) MOVE_TO_OTHER_INVENTORY and SHIFT_LEFT as the click type.
Anyways as a Plugin Developer there are some simple tricks in working around this if your using this for something like a button. You can create a timeout on the button. Store the player ID and unixtimestamp as a key/value and test for it.

Comment by Black Hole [ 13/Apr/20 ]

Plugins might want to have control about which items are collected using those shift-clicking. Anyway the event is generated for each packet the client is sending, so you have to work around this vanilla behaviour.

Generated at Sat Apr 05 09:38:10 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.