EffectiveClickable

Behaviour that dispatches left/right-click interactions on custom items.

A shared module bridges Bukkit interact/attack events into registered Data handlers, matching the clicked stack by namespaced key (falling back to material). EventsCallOptions carries the click context.

Two ways to register:

  • EffectiveItem.addClickHandler — matches only that custom item (by key);

  • addClickHandler directly with a plain, non-custom stack — since it has no key, matching falls back to org.bukkit.Material, so the handler fires for every stack of that material (e.g. hook all sticks). Handy when you want behaviour on a vanilla material, not a custom item.

Click mapping:

  • Click.LEFT — left-click on air/block and attacking an entity (the attacked entity is in EventsCallOptions.clickedEntity).

  • Click.RIGHT — right-click on air/block/entity.

Callback result:

  • EffectiveAbstractInteract.Result.CANCEL_EVENT cancels the underlying Bukkit event (suppresses the vanilla action — block placement, container open, attack, …).

  • EffectiveAbstractInteract.Result.ALLOW_EVENT lets the vanilla action proceed.

addClickHandler(Click.RIGHT, { e ->
e.player.sendMessage("used ${'$'}{e.item.type}")
EffectiveAbstractInteract.Result.CANCEL_EVENT
})

Types

Link copied to clipboard
object Companion
Link copied to clipboard
data class Data(val target: EffectiveAbstractInteract.Target.Item, val click: EffectiveAbstractInteract.Click, val callback: InteractCallback, val cooldownData: EffectiveAbstractInteract.CooldownData<EffectiveClickable.EventsCallOptions>?, val ifRightClickOpenContainer: Boolean = false) : EffectiveAbstractInteract.Data<EffectiveClickable.EventsCallOptions>

A registered click handler: which item, which Click, the callback and optional cooldown.

Link copied to clipboard
data class EventsCallOptions(val player: Player, val target: EffectiveAbstractInteract.Target.Item, val click: EffectiveAbstractInteract.Click, val hand: EquipmentSlot, val clickedBlock: Block?, val blockFace: BlockFace?, val clickedEntity: Entity?) : EffectiveAbstractInteract.EventsCallOptions<EffectiveAbstractInteract.Target.Item>

Context passed to an InteractCallback: the player, the clicked item, the click type and hand, plus the clicked block/face/entity when applicable.