Interface EnchantmentEffectHandler
Implement this interface to define custom behavior for your enchantments. Each method corresponds to a specific game event type and receives a context object with relevant data.
Typed Callbacks vs Event Bus:
You can handle effects through either typed callbacks (this interface) or
the EnchantmentEventBus. Both paths fire through the same dispatch
spine, so choose based on your preference:
- Typed callbacks: Type-safe, compile-time checked, easier for simple effects
- Event bus: Decoupled, allows multiple listeners, better for complex interactions
Cancellation:
Contexts that support cancellation implement Cancellable.
Call EffectContext.tryCancel() to cancel the underlying Bukkit event.
Cancellation propagates through both typed callbacks and event bus listeners.
Threading:
Handlers execute inline with the library's dispatch flow. Keep them light,
avoid blocking work, and reschedule anything expensive through your own
scheduler usage.
Example Implementation:
public class LifeStealHandler implements EnchantmentEffectHandler {
@Override
public void onEntityDamageByEntity(@NotNull CombatContext context) {
if (!context.isAttack()) return;
double scaledValue = context.getScaledValue();
Player attacker = (Player) context.getAttacker();
LivingEntity victim = context.getVictim();
// Heal attacker based on scaled value
double healAmount = context.getFinalDamage() * scaledValue * 0.1;
attacker.heal(healAmount);
}
}
- Since:
- 0.1.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleanisCancelled(@NotNull Object context) Checks if the given context has been cancelled.default voidonArmorTick(@NotNull TickContext context) Called periodically while an armor item is equipped.default voidonBlockBreak(@NotNull ToolContext context) Called after a block is broken.default voidonBlockBreakPre(@NotNull ToolContext context) Called before a block break is confirmed (pre-event).default voidonBlockInteract(@NotNull InteractionContext context) Called when a player interacts with a block (right-click, left-click).default voidonBlockPlace(@NotNull ToolContext context) Called when a player places a block.default voidonBowShoot(@NotNull WeaponContext context) Called when a bow or crossbow is fired.default voidonDurabilityDamage(@NotNull ItemContext context) Called when an item takes durability damage.default voidonEntityDamage(@NotNull CombatContext context) Called when an entity takes damage from any source.default voidonEntityDamageByEntity(@NotNull CombatContext context) Called when an entity damages another entity (attack context).default voidonEntityInteract(@NotNull InteractionContext context) Called when a player interacts with an entity (right-click).default voidonFishingAction(@NotNull FishingContext context) Called when fishing rod actions occur (cast, reel, bite).default voidonHeldTick(@NotNull TickContext context) Called periodically while an item is held in the main or off hand.default voidonItemConsume(@NotNull ConsumableContext context) Called when a player consumes an item (food, potion).default voidonItemDrop(@NotNull ItemContext context) Called when an item is dropped.default voidonItemPickup(@NotNull ItemContext context) Called when an item is picked up.default voidonItemUsed(@NotNull ItemContext context) Called when an item is used (interacted with).default voidonProjectileHit(@NotNull ProjectileContext context) Called when a projectile hits a block or entity.default voidonProjectileLaunch(@NotNull ProjectileContext context) Called when a projectile is launched (arrow, trident, etc.).default voidonShieldBlock(@NotNull CombatContext context) Called when a player successfully blocks with a shield.default voidonTridentThrow(@NotNull WeaponContext context) Called when a trident is thrown.default booleanAttempts to cancel the given context if it supports cancellation.
-
Method Details
-
onEntityDamageByEntity
Called when an entity damages another entity (attack context).Fires for melee attacks, projectile hits, and other damage sources where an attacker can be identified.
- Parameters:
context- the combat context with attacker, victim, and damage data- Since:
- 0.1.0
-
onEntityDamage
Called when an entity takes damage from any source.Fires for all damage events, including environmental damage where there may be no attacker. Check
CombatContext.getAttacker()to determine if there is an attacking entity.- Parameters:
context- the combat context with victim and damage data- Since:
- 0.1.0
-
onShieldBlock
Called when a player successfully blocks with a shield.- Parameters:
context- the combat context with defender and damage data- Since:
- 0.1.0
-
onBlockBreak
Called after a block is broken.The drops list in the context can be modified to change what items are dropped from the broken block.
- Parameters:
context- the tool context with player, tool, and block data- Since:
- 0.1.0
-
onBlockBreakPre
Called before a block break is confirmed (pre-event).Use this to cancel unbreakable blocks or apply pre-break effects. Cancelling here prevents the block from being broken.
- Parameters:
context- the tool context with player, tool, and block data- Since:
- 0.1.0
-
onBlockPlace
Called when a player places a block.- Parameters:
context- the tool context with player, tool, and block data- Since:
- 0.1.0
-
onBlockInteract
Called when a player interacts with a block (right-click, left-click).- Parameters:
context- the interaction context with player and block data- Since:
- 0.1.0
-
onEntityInteract
Called when a player interacts with an entity (right-click).- Parameters:
context- the interaction context with player and entity data- Since:
- 0.1.0
-
onProjectileLaunch
Called when a projectile is launched (arrow, trident, etc.).Modify velocity, gravity, or pierce level through the context.
- Parameters:
context- the projectile context with projectile and shooter data- Since:
- 0.1.0
-
onProjectileHit
Called when a projectile hits a block or entity.- Parameters:
context- the projectile context with hit data- Since:
- 0.1.0
-
onFishingAction
Called when fishing rod actions occur (cast, reel, bite).Modify wait time and lure speed through the context.
- Parameters:
context- the fishing context with player and hook data- Since:
- 0.1.0
-
onHeldTick
Called periodically while an item is held in the main or off hand.- Parameters:
context- the tick context with player and item data- Since:
- 0.1.0
-
onArmorTick
Called periodically while an armor item is equipped.- Parameters:
context- the tick context with player and item data- Since:
- 0.1.0
-
onItemUsed
Called when an item is used (interacted with).- Parameters:
context- the item context with usage data- Since:
- 0.1.0
-
onDurabilityDamage
Called when an item takes durability damage.Modify the damage amount through the context.
- Parameters:
context- the item context with durability data- Since:
- 0.1.0
-
onItemConsume
Called when a player consumes an item (food, potion).Modify food level, saturation, and health restoration through the context.
- Parameters:
context- the consumable context with consumption data- Since:
- 0.1.0
-
onBowShoot
Called when a bow or crossbow is fired.Modify force and critical hit status through the context.
- Parameters:
context- the weapon context with bow and projectile data- Since:
- 0.1.0
-
onTridentThrow
Called when a trident is thrown.Modify force and pierce level through the context.
- Parameters:
context- the weapon context with trident and projectile data- Since:
- 0.1.0
-
onItemDrop
Called when an item is dropped.- Parameters:
context- the item context with drop data- Since:
- 0.1.0
-
onItemPickup
Called when an item is picked up.- Parameters:
context- the item context with pickup data- Since:
- 0.1.0
-
tryCancel
Attempts to cancel the given context if it supports cancellation.Convenience method for handler implementations.
- Parameters:
context- the context object to cancel- Returns:
- true if cancellation was successful, false if not cancellable
- Since:
- 0.1.0
-
isCancelled
Checks if the given context has been cancelled.Convenience method for handler implementations.
- Parameters:
context- the context object to check- Returns:
- true if the context is cancellable and cancelled
- Since:
- 0.1.0
-