Developer API
On this page(7)
SnMines exposes a public developer API for other plugins: custom Bukkit events and a read-only query service. The API lives in the com.sn.mines.api package inside the plugin jar. There is no separate artifact.
Only com.sn.mines.api is a stable, kept contract. Everything else in the jar is obfuscated and internal. Do not call it.
Getting the jar
-
Download the latest release jar.
-
Install it into your local Maven repository:
mvn install:install-file -Dfile=SnMines-<version>.jar -DgroupId=com.sn \ -DartifactId=snmines -Dversion=<version> -Dpackaging=jar -
Depend on it with
providedscope. Never shade it.
Quick start
Declare the dependency in your plugin.yml:
depend: [SnMines] # or softdepend if optionalResolve the API when you need it:
SnMinesAPI api = SnMinesProvider.get();
if (api != null) {
MineView mine = api.getMineAt(player.getLocation());
}Resolve the reference when you need it. Do not cache it across a SnMines reload.
Master switch
API events can be disabled by the server owner with api-events.enabled: false in config.yml. The query service stays available either way.
Events
Cancellable events fire before the action. Cancelling aborts it.
| Event | Fired when | Cancel effect |
|---|---|---|
MineResetEvent | A mine passed its reset checks and is about to refill. Carries the mine and the cause (MANUAL, TIMER, THRESHOLD, STARTUP). | Nothing changes. A timed reset waits for its next interval. STARTUP resets cannot be cancelled: check isCancellable(). |
MineCreateEvent | An admin is about to create a mine, after the id and region were validated. Carries the player, the id and the region. | No mine is created. The admin is told another plugin stopped it. |
MineDeleteEvent | An admin confirmed deleting a mine. Carries the player and the mine. | The mine is kept. The admin is told another plugin stopped it. |
MineRedefineEvent | An admin is about to move a mine onto a new region. Carries the player, the mine and the new region. | The mine keeps its old region. The admin is told another plugin stopped it. |
Notification events fire after the fact. They cannot be cancelled.
| Event | Fired when | Thread |
|---|---|---|
MineBlockBreakEvent | A player broke a block that counts toward an enabled mine, right before SnMines delivers its drop. Carries the player, mine, block, broken block data, drop mode and the drop list. | Main |
MineResetEndEvent | A reset that started has ended. isCompleted() is false when the fill was aborted. | Main |
MineCreatedEvent | A mine was created and saved. | Main |
MineDeletedEvent | A mine was deleted. Carries the mine as it was. | Main |
MineRedefinedEvent | A mine moved onto a new region. Carries the mine and getPrevious(), the mine on its old region. | Main |
Listen like any Bukkit event:
@EventHandler
public void on(MineResetEvent event) {
if (event.getMine().id().equals("vip") && event.isCancellable()) {
event.setCancelled(true);
}
}Event payloads are read-only, with one exception: the drop list of MineBlockBreakEvent.
Replacing mine drops
MineBlockBreakEvent#getDrops() is a mutable list, like the drops of a Bukkit death event. It starts with the drop the mine configures for that block.
- Clear it to suppress the drop.
- Clear it and add items to replace the drop.
- Add items to give them on top of it.
@EventHandler
public void on(MineBlockBreakEvent event) {
event.getDrops().clear();
event.getDrops().add(new ItemStack(Material.EMERALD, 2));
}SnMines spawns the items in the list itself, so drops.cancel-foreign never removes them. They go to the inventory when getDropMode() is INVENTORY, and fall at the block otherwise. Do not spawn items at the block yourself: drops.cancel-foreign removes those. Add them to the list instead.
The list starts empty when the block drops nothing (NONE) or the player is in creative mode. The mined counter counts the block whatever you do.
When isCompositionBlock() is false, the block is no longer in the mine's composition. Its vanilla drops still fall, and the list cannot remove them.
Query service
Every method reads in-memory state. Call them on the main thread. Every returned view is an immutable snapshot.
| Method | Returns | Notes |
|---|---|---|
getMine(id) | MineView or null | One mine, by id (case-insensitive). |
getMines() | List<MineView> | Every loaded mine, enabled or not, ordered by id. |
getMineAt(location) | MineView or null | The mine containing that block position. One index lookup, cheap to call often. |
getMineAt(block) | MineView or null | Same lookup from a block. |
isResetting(id) | boolean | Whether the mine is refilling now. Breaking inside an enabled mine is blocked meanwhile. |
getApiVersion() | String | The API contract version. |
A MineView carries the id, display name, enabled flag, world name and inclusive minX to maxZ bounds. It also holds the composition as MineBlockView entries. Each entry has a block data string and a share in hundredths of a percent (10000 is 100%). region() returns the bounds as a MineRegionView.
Versioning
Call getApiVersion() for the API contract version. It is independent of the plugin version. Additions bump the minor component. Existing members are never removed or changed. Deprecated members keep working.