Event API
EmakiItem exposes Bukkit events that external plugins can listen to in order to intercept, modify, or record item flows. Event classes live in the emaki.jiuwu.craft.item.api.event package and use the standard HandlerList boilerplate.
| Event | When it fires | Cancellable | Mutable |
|---|---|---|---|
EmakiItemCreateEvent | After a custom item is created, before it is returned | No | setResult |
ItemRepairEvent | Before repair cost and durability restore | Yes | setRestoreAmount |
ItemSetBonusChangeEvent | After the active set piece count changes | No | Read-only |
EmakiItemCreateEvent
Fires after a custom item has been created but before it is returned to the caller. The event cannot be cancelled, but the final item can be replaced with setResult.
Event behavior
- Not cancellable, but the result can be replaced with
setResult. Passingnullis ignored. - Fires when the item is created but not yet returned to the caller.
- Fires only while global main-thread ownership holds; otherwise creation returns the item directly without firing the event.
Main methods
| Method | Return | Description |
|---|---|---|
getId() | String | Item definition id. |
getAmount() | int | Resolved amount. |
getPlayer() | Player | Target player. The current creation flow passes no player, so this is always null; listeners must null-check it. |
getResult() | ItemStack | Result item (may already be replaced by a listener). |
setResult(ItemStack) | void | Replace the item returned to the caller; passing null is ignored. |
Example
java
@EventHandler
public void onItemCreate(EmakiItemCreateEvent event) {
// Append custom NBT or lore to a specific item
if (event.getId().equals("starter_sword")) {
ItemStack result = event.getResult();
// ... modify result ...
event.setResult(result);
}
}ItemRepairEvent
Fires before the repair cost is charged and the durability is restored.
Event behavior
- It is cancellable. If cancelled, no cost is charged and no repair happens.
- The restored durability can be changed with
setRestoreAmount. A value of 0 or less suppresses the repair. - Fires only while the current thread owns that player entity; otherwise the repair proceeds uncancelled with the original restore amount.
- Both material and currency repair fire it; use
getSource()to distinguish them.
Main methods
| Method | Return | Description |
|---|---|---|
getPlayer() | Player | Player performing the repair. |
getEquipment() | ItemStack | Equipment being repaired. |
getItemId() | String | EmakiItem definition id. |
getSource() | String | Repair source (such as material or economy). |
getCurrentDamage() | int | Current damage before repair. |
getMaxDamage() | int | Maximum damage. |
getRestoreAmount() | int | Durability to restore unless changed or cancelled. |
setRestoreAmount(int) | void | Change the restored durability; a value of 0 or less suppresses the repair. |
isCancelled() | boolean | Whether the event is cancelled. |
setCancelled(boolean) | void | Cancel or restore the event. |
Example
java
@EventHandler
public void onItemRepair(ItemRepairEvent event) {
// Double the restore amount for economy repairs
if (event.getSource().equals("economy")) {
event.setRestoreAmount(event.getRestoreAmount() * 2);
}
}Method naming
The setter for the restored amount is setRestoreAmount(int) with the matching getter getRestoreAmount(), not setRepairAmount.
ItemSetBonusChangeEvent
An informational event fired after the active set piece count actually changes. It only fires when the active count changes (edge-triggered).
Event behavior
- Not cancellable; purely informational.
- The set bonus has already been applied; the event lets external plugins observe the change.
- Fires only when the active count actually changes and the current thread owns that player entity; otherwise state is still updated but no event is sent.
- Fires once per changed set ID.
Main methods
| Method | Return | Description |
|---|---|---|
getPlayer() | Player | Player whose set state changed. |
getSetId() | String | Set id. |
getOldActiveCount() | int | Active piece count before the change. |
getNewActiveCount() | int | Active piece count after the change. |
getTotalPieces() | int | Total pieces in the set. |
getActiveThresholds() | List<Integer> | Active tier piece requirements (immutable list). |
getTrigger() | String | Source that triggered the refresh. |
Example
java
@EventHandler
public void onSetBonusChange(ItemSetBonusChangeEvent event) {
if (event.getNewActiveCount() > event.getOldActiveCount()) {
event.getPlayer().sendMessage("Set activated: " + event.getSetId()
+ " (" + event.getNewActiveCount() + "/" + event.getTotalPieces() + ")");
}
}Notes
EmakiItemCreateEventcannot be cancelled; to prevent item creation, handle it at the caller level.getActiveThresholds()onItemSetBonusChangeEventreturns an immutable list; do not try to modify it.