Developer API
On this page(11)
SnHolograms exposes a public developer API for other plugins: custom Bukkit events and a service to create, control and read holograms. The API lives in the com.sn.holograms.api package inside the plugin jar. There is no separate artifact.
Only com.sn.holograms.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=SnHolograms-<version>.jar -DgroupId=com.sn \ -DartifactId=SnHolograms -Dversion=<version> -Dpackaging=jar -
Depend on it with
providedscope. Never shade it.
Quick start
Declare the dependency in your plugin.yml:
depend: [SnHolograms] # or softdepend if optionalResolve the API and create a hologram:
SnHologramsAPI api = SnHologramsProvider.get();
if (api != null) {
HologramSpec spec = HologramSpec.builder(location)
.text("&6&lShop")
.text("&7Hello, {player}")
.item("DIAMOND")
.actions("right", List.of("[message] &aWelcome!"))
.build();
api.createHologram(this, "shop", spec);
api.onClick(this, "shop", (player, id, page, line) -> openShop(player));
}Resolve the reference when you need it. Do not cache it across a SnHolograms restart.
Two kinds of hologram
- Runtime holograms are yours. You create them in code, they are never written to a file, and you address them by your plugin plus an id. Ids ignore case and may not contain
:. They never clash with other plugins or with file holograms. They are removed when your plugin disables. - File holograms belong to the server owner. The API reads them and controls them per player, but never changes their files.
Describing a hologram
A HologramSpec is the hologram file format in memory. Every key of a file under holograms/ works the same way, so the Configuration page documents both.
| Builder method | What it sets |
|---|---|
builder(Location) | The anchor (the top of the hologram). The location needs a world. |
type(String) | display (default) or armor_stand. |
enabled(boolean) | Whether the hologram is rendered. |
viewDistance(int) | Blocks within which a player sees it. |
updateInterval(int) | Ticks between refreshes of placeholder lines. 0 means never. |
pageRotation(int) | Seconds between automatic page changes. 0 means off. |
lineSpacing(double) | Blocks between two lines. |
viewRequirements(List) | Requirement lines a viewer must pass. |
look(String, Object) | One key of the look section, for example billboard or scale. |
text, item, block, head | Adds a line to the current page. |
line(Map) | Adds a line in the full file format, with per-line look, offset, motion and more. |
actions(String, List) | Click actions of one click kind on the current page. |
newPage() | Starts the next page. |
HologramSpec.fromConfig(Location, ConfigurationSection) wraps a section written in the file format instead.
A spec is checked when you use it. Anything a file would only warn about, such as an unknown key or material, throws IllegalArgumentException with every problem listed.
Master switch
API events can be disabled by the server owner with api-events.enabled: false in config.yml. The API service stays available either way.
Events
Cancellable events fire before the action. Cancelling aborts it.
| Event | Fired when | Cancel effect |
|---|---|---|
HologramClickEvent | A player clicks a clickable line, after the click cooldown | The page's click actions do not run and no click handler is called |
Notification events fire after the fact. They cannot be cancelled.
| Event | Fired when | Thread |
|---|---|---|
HologramPageChangeEvent | A viewer's page changed (click action, API, command or rotation) | Main, on the next tick |
HologramEditEvent | An in-game editor command created, changed or deleted a file hologram | Main |
HologramsLoadEvent | The file holograms were loaded at startup or after a reload | Main |
Listen like any Bukkit event:
@EventHandler
public void on(HologramClickEvent event) {
if (event.isRuntime() || !event.getHologramId().equals("spawn")) {
return;
}
if (!event.getPlayer().hasPermission("myplugin.spawn")) {
event.setCancelled(true);
}
}Event payloads are read-only. HologramPageChangeEvent is only dispatched while a listener is registered for it.
API service
Every method runs on the main thread and returns at once. A call from another thread throws IllegalStateException. A method that addresses an unknown hologram returns false, -1 or an empty result.
Runtime holograms
| Method | Returns | Notes |
|---|---|---|
createHologram(owner, id, spec) | boolean | False when you already have that id. It shows at once to players in range. |
updateHologram(owner, id, spec) | boolean | Replaces the definition in place. Viewers, overrides, handlers and attachment stay. |
removeHologram(owner, id) | boolean | Removes it for every viewer. |
removeHolograms(owner) | int | Removes all of yours. |
getHologram(owner, id) | Optional<HologramView> | A snapshot. |
getHolograms(owner) | List<HologramView> | Yours, in creation order. |
getViewers(owner, id) | List<Player> | Who sees it now. |
setViewers(owner, id, uuids) | boolean | Restricts who may see it. null means everyone in range. |
showHologram / hideHologram(owner, id, player) | boolean | Forces it on or off for one player. |
resetVisibility(owner, id, player) | boolean | Drops a show or hide of one player. |
setLineOverride(owner, id, player, page, line, text) | boolean | One player's own text on a text line. null clears it. |
clearLineOverrides(owner, id[, player]) | boolean | Clears overrides of one player or of everyone. |
getPage / setPage(owner, id, player[, page]) | int / boolean | One viewer's page, 0-based. |
teleport(owner, id, location, ticks) | boolean | Moves it. Display lines glide over the ticks. |
attachTo(owner, id, entity, offset) | boolean | Follows an entity. Removed when the entity is gone. |
detach(owner, id) | boolean | Stops following; it stays where it is. |
onClick(owner, id, handler) | boolean | Adds a HologramClickHandler. The first one makes the lines clickable. |
clearClickHandlers(owner, id) | boolean | Removes every handler. |
File holograms
| Method | Returns | Notes |
|---|---|---|
getFileHolograms() | List<HologramView> | Every loaded file hologram, in id order. |
getFileHologram(id) | Optional<HologramView> | One file hologram, id ignoring case. |
getFileHologramViewers(id) | List<Player> | Who sees it now. |
showFileHologram / hideFileHologram(id, player) | boolean | Forces it on or off for one player. |
resetFileHologramVisibility(id, player) | boolean | Drops a show or hide of one player. |
getFileHologramPage / setFileHologramPage(id, player[, page]) | int / boolean | One viewer's page, 0-based. |
Views
HologramView is a read-only snapshot: id, owner, folder, type, location, view distance, update interval, page rotation, view requirements and pages. Each PageView lists its LineView lines (type and raw content) and its click actions. A snapshot does not follow later changes; ask the API again.
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.