Skip to content

Event API

EmakiAttribute exposes Bukkit events that external plugins can listen to in order to intercept or modify key steps. Event classes are provided by the public API module EmakiAttributeApi, live in the emaki.jiuwu.craft.attribute.api package, and use the standard HandlerList boilerplate.

EventWhen it firesCancellableMutable
EmakiAttributeDamageEventAfter attribute damage is calculated, before it is appliedYessetFinalDamage
PlayerResourceConsumeEventBefore a custom resource is consumedYessetAmount

See Damage Event API for the full EmakiAttributeDamageEvent reference. This page documents the resource consume event.

PlayerResourceConsumeEvent

Fires before a custom resource (such as mana or rage managed by EmakiAttribute) is actually deducted. Use it to intercept consumption, change the consumed amount, or react to resource state.

Event behavior

  • It is cancellable. If cancelled, the consume call returns false and the resource is not deducted.
  • The amount can be changed with setAmount. After the event, the value is re-validated against the current balance; if the new amount exceeds the balance, the consumption is aborted.
  • Fired on the main thread; asynchronous paths skip the event.

Main methods

MethodReturnDescription
getPlayer()PlayerPlayer whose resource is consumed.
getResourceId()StringResource id.
getCurrentValue()doubleCurrent value before consumption.
getCurrentMax()doubleCurrent maximum.
getAmount()doubleAmount to consume unless changed or cancelled.
setAmount(double)voidChange the consumed amount; re-validated against balance after the event.
isCancelled()booleanWhether the event is cancelled.
setCancelled(boolean)voidCancel or restore the event.

Example

java
@EventHandler
public void onResourceConsume(PlayerResourceConsumeEvent event) {
    // Halve mana cost
    if (event.getResourceId().equals("mana")) {
        event.setAmount(event.getAmount() * 0.5);
    }

    // Block when the balance is not enough
    if (event.getCurrentValue() < event.getAmount()) {
        event.setCancelled(true);
    }
}

Notes

  • If the changed amount exceeds the current balance, EmakiAttribute aborts the consumption.
  • When cancelled, the originating consume call returns false; the caller should handle the failure branch.
  • Do not run heavy work in the listener; the event runs on the main thread.