Skip to content

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.

EventWhen it firesCancellableMutable
EmakiItemCreateEventAfter a custom item is created, before it is returnedNosetResult
ItemRepairEventBefore repair cost and durability restoreYessetRestoreAmount
ItemSetBonusChangeEventAfter the active set piece count changesNoRead-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. Passing null is 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

MethodReturnDescription
getId()StringItem definition id.
getAmount()intResolved amount.
getPlayer()PlayerTarget player. The current creation flow passes no player, so this is always null; listeners must null-check it.
getResult()ItemStackResult item (may already be replaced by a listener).
setResult(ItemStack)voidReplace 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

MethodReturnDescription
getPlayer()PlayerPlayer performing the repair.
getEquipment()ItemStackEquipment being repaired.
getItemId()StringEmakiItem definition id.
getSource()StringRepair source (such as material or economy).
getCurrentDamage()intCurrent damage before repair.
getMaxDamage()intMaximum damage.
getRestoreAmount()intDurability to restore unless changed or cancelled.
setRestoreAmount(int)voidChange the restored durability; a value of 0 or less suppresses the repair.
isCancelled()booleanWhether the event is cancelled.
setCancelled(boolean)voidCancel 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

MethodReturnDescription
getPlayer()PlayerPlayer whose set state changed.
getSetId()StringSet id.
getOldActiveCount()intActive piece count before the change.
getNewActiveCount()intActive piece count after the change.
getTotalPieces()intTotal pieces in the set.
getActiveThresholds()List<Integer>Active tier piece requirements (immutable list).
getTrigger()StringSource 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

  • EmakiItemCreateEvent cannot be cancelled; to prevent item creation, handle it at the caller level.
  • getActiveThresholds() on ItemSetBonusChangeEvent returns an immutable list; do not try to modify it.