Developer API and Bukkit Events
CraftingEngine provides a clean, modular public API module (craftingengine-api) enabling third-party plugins to initiate processes, register custom action/condition providers, listen to crafting lifecycle events, and query active workstations.
1. Maven and Gradle Coordinates
Add the CraftingEngine API dependency to your project:
Gradle (Kotlin DSL - build.gradle.kts)
repositories { maven("https://repo.codemc.io/repository/maven-releases/")}
dependencies { compileOnly("dev.darkblade.craftingengine:craftingengine-api:2.8.0")}Maven (pom.xml)
<dependency> <groupId>dev.darkblade.craftingengine</groupId> <artifactId>craftingengine-api</artifactId> <version>2.8.0</version> <scope>provided</scope></dependency>2. Accessing the Service API
Obtain the singleton CraftingEngineAPI instance via Bukkit’s ServicesManager or direct entry point:
import dev.darkblade.craftingengine.api.CraftingEngineAPI;import org.bukkit.Bukkit;
public class MyPluginIntegration { private CraftingEngineAPI api;
public void onEnable() { this.api = Bukkit.getServicesManager().load(CraftingEngineAPI.class); if (this.api == null) { // Fallback or handle missing plugin } }}3. Bukkit Lifecycle Events
CraftingEngine dispatches asynchronous and synchronous Bukkit events throughout the crafting lifecycle:
| Event Class | Cancellable | Timing / Trigger |
|---|---|---|
ProcessPreStartEvent | Yes | Dispatched before materials are consumed. Allows cancelling crafts. |
ProcessStartedEvent | No | Dispatched immediately after materials are consumed and stages begin. |
StageTransitionEvent | No | Dispatched when a process moves from one stage to another. |
ProcessCompletedEvent | No | Dispatched when all stages succeed and outputs are generated. |
ProcessFailedEvent | No | Dispatched when a process fails, aborts, or is abandoned. |
Example: Event Listener
import dev.darkblade.craftingengine.api.event.ProcessPreStartEvent;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;
public class CraftingListener implements Listener {
@EventHandler public void onProcessPreStart(ProcessPreStartEvent event) { if (event.getRecipeId().equals("infernal_blade") && !event.getPlayer().hasPermission("myplugin.master")) { event.setCancelled(true); event.setCancelReason("You have not mastered Infernal Forging!"); } }}4. Registering Custom Actions and Conditions
You can extend blueprint functionality by registering custom Java condition or action handlers with the RegistryManager:
api.getRegistryManager().registerAction("custom_teleport", (context, args) -> { Player player = context.getPlayer(); Location target = parseLocation(args); player.teleport(target);});Next Steps
- Process Blueprints - Learn how custom actions are invoked from YAML.
- Diagnostics & Flight Recorder - Inspect API telemetry and process runtime traces.