This page describes how to create and register hooks.
A hook is a set of instructions to be executed when an inventory event is performed for a specific inventory.
Hooks are represented by the generic Hook functional interface. The following code illustrates how to create a hook.
Hooks can be applied on the following events:
FastInventoryBeforeOpenEvent
: Called before opening an inventory.
FastInventoryAfterOpenEvent
: Called after an inventory has been opened.
FastInventoryClickEvent
: Called when a player clicks on an item.
FastInventoryCloseEvent
: Called when an inventory is closed.
Hooks are registered specifically for an inventory in its inventory descriptor by redefining the addHooks(HookManager manager)
method.
The HookManager
interface provides the addHook(hookId, eventClass, hook)
method to register a new hook.
In CraftVentory, we do not rely on Bukkit events. Indeed, we prefer using hooks which are registered and executed specifically for an inventory instead of events which are executed for all inventories.