Question Some inventory events just don't work. At all.

  • After careful consideration and due to limited usage, we’ve made the decision to discontinue the PaperMC forums. Moving forward, we recommend using Hangar for plugin uploads, and for all other community discussions and support, please join us on Discord.

NotAHackusator

New member
Dec 10, 2024
1
0
1
Even on the highest priority and with ignoreCancelled = true, some inventory events just don't work.
The one I've tested that don't work: InventoryOpenEvent, InventoryEvent, InventoryPickupItemEvent
The one I've tested that DO work: InventoryClickEvent, InventoryDragEvent, InventoryCloseEvent

I've implemented handlers for all of these events in the same class (which ofc implements Listener). That class is registered to listen to events.
Code:

private void inventoryEvent(Inventory inventory) {
Stronghold.logger.debug(Thread.currentThread().getStackTrace()[2], inventory, inventory.getHolder());
if (inventory.getHolder() instanceof Player) {
Items.registerInventoryCheck(inventory);
}
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onInventoryClick(InventoryClickEvent event) { // works
inventoryEvent(event.getInventory());
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onInventoryPickup(InventoryPickupItemEvent event) { // doesn't work
inventoryEvent(event.getInventory());
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onInventoryEvent(InventoryEvent event) { // doesn't work
inventoryEvent(event.getInventory());
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onInventoryDrag(InventoryDragEvent event) { // works
inventoryEvent(event.getInventory());
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onInventoryOpen(InventoryOpenEvent event) { // doesn't work
inventoryEvent(event.getInventory());
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onInventoryClose(InventoryCloseEvent event) { // works
inventoryEvent(event.getInventory());
}

Thanks for the help in advance.
 
Solution
InventoryOpenEvent doesn't work on opening the player's own inventory, as far as the server is concerned the player always has their own inventory open; make sure you haven't tested if it works using that.
InventoryEvent just as many other events that have subclasses can't be listened to.
InventoryPickupItemEvent (click to see Javadoc) isn't for players.

If you have any other questions feel free to ask on our Discord, you'll likely get answers there quicker.

Nacio

Paper Triage
Staff member
Jul 11, 2022
6
1
0
1
20
Lublin, Poland
InventoryOpenEvent doesn't work on opening the player's own inventory, as far as the server is concerned the player always has their own inventory open; make sure you haven't tested if it works using that.
InventoryEvent just as many other events that have subclasses can't be listened to.
InventoryPickupItemEvent (click to see Javadoc) isn't for players.

If you have any other questions feel free to ask on our Discord, you'll likely get answers there quicker.
 
Solution