Making more advanced item
To create a right-click event for a custom item, implement the rightClick
method from the CustomItem
interface. This method uses the PlayerInteractEvent
parameter to manage the player's interaction and offers control over the event through options like cancellation.
Here's a breakdown of how it works:
PlayerInteractEvent: The
event
argument provides vital control, allowing you to customize interactions. You can use this to check which action triggered the event and modify or cancel it based on your needs.UUID Handling: The
uuid
argument is crucial if theCustomItemData
has thewithUUID
option enabled. It ensures unique identification for each item, allowing for specific behaviors for individual items. IfwithUUID
is not enabled,uuid
will be null.
In the example above, when a player right-clicks with the custom item, they will receive a "Right click!" message. To ensure your item's behavior is executed, make sure prior events haven't cancelled it unless intentionally desired. Register your item properly in main class.
Last updated