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.
| Event | When it fires | Cancellable | Mutable |
|---|---|---|---|
EmakiAttributeDamageEvent | After attribute damage is calculated, before it is applied | Yes | setFinalDamage |
PlayerResourceConsumeEvent | Before a custom resource is consumed | Yes | setAmount |
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
falseand 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
| Method | Return | Description |
|---|---|---|
getPlayer() | Player | Player whose resource is consumed. |
getResourceId() | String | Resource id. |
getCurrentValue() | double | Current value before consumption. |
getCurrentMax() | double | Current maximum. |
getAmount() | double | Amount to consume unless changed or cancelled. |
setAmount(double) | void | Change the consumed amount; re-validated against balance after the event. |
isCancelled() | boolean | Whether the event is cancelled. |
setCancelled(boolean) | void | Cancel 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.