When holding an interactable item (I tested with a trident), and then right-clicking an entity (eg. a Pig), plugins receive:
- 2 events for interacting with the entity (main and off hand)
- 1 event for interacting with the item (either RIGHT_CLICK_AIR, or RIGHT_CLICK_BLOCK, depending on whether a block is reachable for the interaction)
However, when first right clicking an interactable block (eg. a chest) while holding the trident in hand, and then right-clicking an entity, plugins only receive the 2 entity interaction events. The PlayerInteractEvent for the item interaction is omitted.
I assume the cause of this is that CraftBukkit caches the interaction result for the chest interaction inside PlayerInteractManager (fields 'firedInteract' and 'interactResult'). The cached result of that is then used during the later entity interaction (inside PlayerConnectionManager).
The problem with that is that the chest interaction and the later entity interaction in this test scenario have nothing to do with each other (the entity interaction can happen quite some time later). If a plugin wants to prevent the item interaction when a player right-clicks an entity (my usecase), the plugin may miss some events depending on the player's previous actions and the state of that interaction result cache.
Example plugin (simply logs interact events): https://pastebin.com/LYARYWDZ