Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Bill3621/CustomItems/llms.txt
Use this file to discover all available pages before exploring further.
EventHandler is an internal class that bridges LabAPI player events to custom item event hooks. It automatically detects when players interact with custom items and routes the events to the appropriate CustomItem event handlers.
This class is internal to the CustomItems framework. You typically don’t need to interact with it directly - it works automatically when you register custom items.
Overview
TheEventHandler class extends CustomEventsHandler from LabAPI and implements the following functionality:
- Event Detection: Checks if items involved in player events are custom items by looking them up in
CustomItems.CurrentItems - Event Routing: Calls the appropriate event hook method on the custom item instance
- Hint Display: Automatically shows hints to players when they pick up or select custom items (respects
ShowItemHints,ShowPickupHints, andShowSelectedHintssettings) - Cleanup: Clears all active custom items when the server starts waiting for players
Event Flow
When a player interacts with an item, the following occurs:- LabAPI fires a player event (e.g.,
OnPlayerUsingItem) EventHandlerchecks if the item’s serial number exists inCustomItems.CurrentItems- If found, it retrieves the corresponding
CustomIteminstance - The appropriate event hook method is called on the custom item (e.g.,
OnUsing()) - Additional behaviors like hint display are handled automatically
Handled Events
TheEventHandler intercepts and routes the following LabAPI events:
Item Usage Events
CustomItem.OnUsing() and CustomItem.OnUsed() respectively.
Item Drop Events
CustomItem.OnDropping() and CustomItem.OnDropped() respectively.
Item Pickup Events
CustomItem.OnPickingUp() and CustomItem.OnPickedUp() respectively.
Special Behavior: When a player picks up a custom item, a hint is automatically displayed showing the item’s name and description (if ShowItemHints and ShowPickupHints are both true).
Item Selection Events
CustomItem.OnSelecting(), CustomItem.OnUnselecting(), CustomItem.OnSelected(), and CustomItem.OnUnselected() as appropriate.
Special Behavior: When a player selects a custom item, a hint is automatically displayed showing the item’s name and description (if ShowItemHints and ShowSelectedHints are both true).
Server Events
CustomItems.CurrentItems dictionary to remove all tracked custom items from the previous round. Also handles test item spawning if enabled in the plugin configuration.
Internal Check Method
The handler uses an internal helper method to verify if an item is a custom item:CurrentItems tracking dictionary.
Automatic Hint Display
TheEventHandler provides two automatic hint displays:
Pickup Hint
WhenOnPlayerPickedUpItem is called:
Selection Hint
WhenOnPlayerChangedItem is called:
Test Item Spawning
If test item spawning is enabled in the plugin configuration (TestItemSpawning = true), the EventHandler will spawn an instance of the first registered custom item (ID 0) in every room when the server starts:
Event Handling Example
Here’s what happens internally when a player uses a custom item:Selection Event Flow
The selection events are more complex because they handle both the old item being unselected and the new item being selected:Integration with Your Plugin
You don’t need to manually instantiate or register theEventHandler. It’s automatically set up by the CustomItems framework when your plugin loads. Simply:
- Register your custom items using
CustomItems.Register()orCustomItems.RegisterAll() - Override the event hook methods in your
CustomItemclasses - The
EventHandlerwill automatically route events to your custom items
EventHandler detects it’s a custom item and automatically calls your OnUsed method.