Developer API
On this page(8)
SnTexturePack exposes a public developer API for other plugins: custom Bukkit events, a query service for the furniture placed in the world, and the items of the pack (including the colored GUI background of any stack). The API lives in the com.sn.texturepack.api package inside the plugin jar. There is no separate artifact.
SnTexturePack only draws things. A piece of furniture does nothing when clicked. Your plugin gives it behavior: it listens to the furniture events and turns pieces through the API. A prize wheel, a menu that opens on click or a lid that opens are all built this way.
Only com.sn.texturepack.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=SnTexturePack-<version>.jar -DgroupId=com.sn \ -DartifactId=SnTexturePack -Dversion=<version> -Dpackaging=jar -
Depend on it with
providedscope. Never shade it.
Quick start
Declare the dependency in your plugin.yml:
depend: [SnTexturePack] # or softdepend if optionalResolve the API when you need it:
SnTexturePackAPI api = SnTexturePackProvider.get();
if (api != null) {
// use the api
}Resolve the reference when you need it. Do not cache it across a SnTexturePack disable.
Master switch
The server owner can disable API events with api-events.enabled: false in config.yml. The cancellable events then never cancel, so placing and breaking proceed. The query service stays available either way.
Events
Cancellable events fire before the action, after protection plugins allowed it. Cancelling aborts it.
| Event | Fired when | Cancel effect |
|---|---|---|
FurniturePlaceEvent | A player is about to place a piece from its item. Carries the furniture type, the block and the facing. | Nothing is spawned and the item stays in the hand. |
FurnitureBreakEvent | A player hits a placed piece to break it. Fires while the piece turns too. | The piece stays where it is. |
Notification events fire after the fact. They cannot be cancelled.
| Event | Fired when | Thread |
|---|---|---|
FurnitureInteractEvent | A player right-clicked a placed piece with the main hand. | Main thread |
Listen like any Bukkit event:
@EventHandler
public void on(FurnitureInteractEvent event) {
PlacedFurnitureView piece = event.getFurniture();
if (piece.id().equals("sntp:lucky_wheel")) {
// your behavior here
}
}Event payloads are read-only. To forget a piece that is really gone, listen to FurnitureBreakEvent at MONITOR with ignoreCancelled = true.
Query service
Every method touches entities or the loaded content. Call them on the main thread.
| Method | Returns | Notes |
|---|---|---|
getFurnitureTypeIds() | List<String> | Every furniture id, sorted. |
getFurnitureType(id) | FurnitureTypeView or null | Id, material, custom model data, item model, placements and overlay. A bare id gets the pack namespace. |
getFurniture(Entity) | PlacedFurnitureView or null | The piece an entity belongs to: its display, hitbox or overlay. |
getFurniture(UUID displayId) | PlacedFurnitureView or null | The piece of a display id. Null when gone or not loaded. |
getFurnitureAt(Location) | PlacedFurnitureView or null | The piece standing in a block. |
getFurnitureNear(Location, radius) | List<PlacedFurnitureView> | Every piece around a point, nearest first. Loaded chunks only. |
setRotation(displayId, axis, degrees) | boolean | Sets an angle at once. False when missing or turning. |
getRotation(displayId, axis) | double | The saved angle, from 0 to 360. Kept across restarts. |
isRotating(displayId) | boolean | Whether the piece turns right now. |
createItem(itemId, amount) | ItemStack or null | A new stack of any pack item. |
getItemId(ItemStack) | String or null | The pack id of a stack. |
getBlockData(ItemStack) | BlockData or null | The exact block state a pack block item places (a new copy). Null for any other stack, or while custom blocks are off. Fill an area with it (setBlockData(data, false)) and recognise the blocks by comparing getBlockData(). Since API 1.3.0. |
setGuiBackground(ItemStack, Color) | boolean | Puts a colored square behind any stack in inventories, vanilla items included. null removes it. False on air or below Paper 1.21.4. Since API 1.1.0. |
getGuiBackground(ItemStack) | Color or null | The square's color of a stack. Since API 1.1.0. |
setGuiBackgroundRainbow(ItemStack, boolean) | boolean | A square that keeps cycling through every color, animated by the client. Removes a fixed color, and setting a color removes it. Since API 1.2.0. |
isGuiBackgroundRainbow(ItemStack) | boolean | Whether a stack shows the cycling square. Since API 1.2.0. |
getApiVersion() | String | The API contract version. |
PlacedFurnitureView carries the furniture id, the display id, the hitbox id, the overlay id, the block and the facing. The display id is the identity of a piece. Store it to find the piece again after a restart.
Turning a piece
| Method | Returns | Notes |
|---|---|---|
rotate(displayId, axis, degrees, ticks, easing) | CompletableFuture<Boolean> | Turns a piece smoothly for every player who sees it. Completes on the main thread. |
- Axis:
ROLLturns about the forward axis, clockwise as seen from the front.YAWturns clockwise as seen from above.PITCHtips the top forward. - Degrees: relative to the current angle, any size. Negative turns the other way.
- Easing:
LINEAR,EASE_OUT(fast, then slows to a stop) orEASE_IN_OUT. - Result:
truewhen the piece reached its final angle.falsewhen refused (no such piece, already turning) or when the piece was removed mid-turn. - Length: a turn too fast to draw is made longer, so wait for the future, not for
ticks. - Overlay: the overlay never turns. Use it for a pointer over a wheel.
When a piece's chunk unloads or the server stops mid-turn, the piece jumps to its final angle and the future completes with true. A reward given on completion is never lost.
A prize wheel on top of the API:
UUID wheel = event.getFurniture().displayId();
int segment = pickPrize(); // your logic
double degrees = 5 * 360 + angleThatShows(segment, api.getRotation(wheel, FurnitureAxis.ROLL));
api.rotate(wheel, FurnitureAxis.ROLL, degrees, 100, RotationEasing.EASE_OUT)
.thenAccept(done -> { if (done) givePrize(player, segment); });Clients 1.17 to 1.19.3 have no display entities. They see the piece still, without its scale.
Coloring menu buttons
ItemStack yes = new ItemStack(Material.LIME_DYE);
api.setGuiBackground(yes, Color.fromRGB(0x55FF55)); // green square behind it
ItemStack no = new ItemStack(Material.RED_DYE);
api.setGuiBackground(no, Color.fromRGB(0xFF5555)); // red square behind it
inventory.setItem(11, yes);
inventory.setItem(15, no);No code needed for a menu built with SnLib 1.46.0 or newer: put custom-model-data-flags: [true] and custom-model-data-colors: ["#55FF55"] on the item in the menu yml ([false, true] for the cycling square).
The color is stored on the stack, so set it before you put the stack in the menu. Clients 1.21.4 and newer draw it when the pack was built with gui-background.enabled (the default). Older clients see the plain item. A colored stack does not stack with an uncolored one.
Versioning
The current API version is 1.3.0 (1.1.0 added setGuiBackground and getGuiBackground, 1.2.0 setGuiBackgroundRainbow and isGuiBackgroundRainbow, 1.3.0 getBlockData). 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.