Event API
EmakiForge exposes Bukkit events that external plugins can listen to in order to intercept or record the forging flow. Event classes live in the emaki.jiuwu.craft.forge.api.event package and use the standard HandlerList boilerplate.
| Event | When it fires | Cancellable | Mutable |
|---|---|---|---|
ForgeStartEvent | Just before asynchronous forge execution begins | Yes | Read-only |
ForgeCompletedEvent | After a forge attempt has fully completed | No | Read-only |
ForgeStartEvent
Fires just before asynchronous forge execution begins. This is the only cancellation point that runs on the main thread before the asynchronous chain starts.
Event behavior
- It is cancellable. If cancelled, the forge flow does not start.
successRateis read-only: the success rate is decided by configuration and JavaScript rules, so the event does not expose a setter.- Fired on the main thread; asynchronous paths skip the event.
Main methods
| Method | Return | Description |
|---|---|---|
getPlayer() | Player | Player performing the forge. |
getRecipeId() | String | Forge recipe id. |
isFirstCraft() | boolean | Whether this is the first craft of the recipe. |
getSuccessRate() | double | Configured recipe success rate (0-100), read-only. |
isCancelled() | boolean | Whether the event is cancelled. |
setCancelled(boolean) | void | Cancel or restore the event. |
Example
java
@EventHandler
public void onForgeStart(ForgeStartEvent event) {
// Restrict a recipe to its first craft only
if (!event.isFirstCraft() && event.getRecipeId().equals("legendary_blade")) {
event.setCancelled(true);
}
}ForgeCompletedEvent
Fires after a forge attempt has fully completed. Both success and failure fire the event; use isSuccess() to tell them apart. Unexpected errors do not fire it.
Event behavior
- Not cancellable; purely informational.
- Fired on the main thread.
Main methods
| Method | Return | Description |
|---|---|---|
getPlayer() | Player | Player who performed the attempt. |
getRecipeId() | String | Forge recipe id. |
isSuccess() | boolean | Whether the attempt succeeded. |
getResultItem() | ItemStack | Result item, null on failure. |
getQuality() | String | Resolved quality tier id, may be empty. |
getMultiplier() | double | Resolved quality multiplier. |
Example
java
@EventHandler
public void onForgeCompleted(ForgeCompletedEvent event) {
if (event.isSuccess()) {
getLogger().info(event.getPlayer().getName()
+ " forged successfully with quality " + event.getQuality());
}
}Notes
- On failure
getResultItem()returns null; check for null before reading it. getQuality()may be an empty string or null depending on whether the recipe uses the quality system.