Skip to content

InvUI v2.0.0-alpha.24

Pre-release
Pre-release

Choose a tag to compare

@NichtStudioCode NichtStudioCode released this 21 Dec 12:25
· 11 commits to ver/2.x since this release

Bukkit inventory events

When embedded in a Gui, InvUI now fires Bukkit's InventoryClickEvent and InventoryDragEvent for VirtualInventory and ReferencingInventory. This works the following way:

  1. For single clicks, if the clicked inventory is a ReferencingInventory to the viewer's player inventory (e.g. the default lower GUI), an InventoryClickEvent is fired with a view matching the player's current open view, which is a view with a top inventory of 0 slots, and the player inventory as the bottom inventory. Note that even if the referencing inventory is embedded in the upper GUI, the click event is still fired with a slot translated to the lower inventory.
  2. For single clicks, if the clicked inventory is anything else (e.g. a VirtualInventory or a ReferencingInventory to something else), an InventoryClickEvent is fired with a custom view that does not match the player's current open view. Instead, this custom view uses an adapter Inventory that delegates to the InvUI inventory as the top inventory. The lower inventory of the view is always the player's inventory.
  3. For item drags, if all slots are within a ReferencingInventory to the viewer's player inventory (e.g. the default lower GUI), an InventoryDragEvent is fired with a view matching the player's current open view. This behavior is similar to (1).
  4. For item drags, if there are slots from other inventories involved, an InventoryDragEvent is fired with a custom view that does not match the player's current open view. Instead, this custom view uses an adapter Inventory to a CompositeInventory that combines all the inventories involved in the drag action, except ReferencingInventory to the viewer's player inventory, for which the view's lower inventory will be used. Like (2), the adapter inventory then delegates to the InvUI inventories. The InventoryDragEvent is fired with an expected outcome of the drag action, not taking into account any custom InvUI-inventory logic like update handlers. Additionally, while cancelling the InventoryDragEvent will work as expected, changing the new cursor with InventoryDragEvent#setCursor is ignored by InvUI.

The above logic is intended to not break too many assumptions made by plugins, such as the player's inventory always being the lower inventory in a view, while still isolating InvUI's gui components.

This functionality is currently enabled by default. Bukkit inventory event firing can be disabled per-plugin via InvUI.getInstance().setFireBukkitInventoryEvents(false) or globally by setting the system property invui.fireBukkitInventoryEvents to false (-Dinvui.fireBukkitInventoryEvents=false). Depending on feedback, this may be changed to be opt-in instead.

New features

  • Bukkit inventory events
  • Experimental support for Folia

Changes

  • Removed ItemPreUpdateEvent#setNewItem and ItemUpdateEvent#getNewItem, ItemUpdateEvent#getPreviousItem now always return copies. This removes the functionality to change the new item amount and have this reflected in the source, as that did not work properly in some cases. Cancelling the event is still possible.
  • The constructor of ReferencingInventory is now private. Use the static factory functions instead.
  • InvUI's InventoryClickEvent now includes an InventoryAction, which represents the normal outcome of the event.

Fixes

  • Fixed Inventory#removeFirst and Inventory#removeFirstSimilar returning 0 instead of the amount of removed items when the entire amount was removed.