> For the complete documentation index, see [llms.txt](https://zone-developement.gitbook.io/zonepractice-pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zone-developement.gitbook.io/zonepractice-pro/extra/for-developers.md). Agents can also search and read this documentation through its [MCP server](https://zone-developement.gitbook.io/zonepractice-pro/~gitbook/mcp).

# For Developers

Build addons for ZonePractice Pro with the public API.

The ZonePractice Pro API lets addons read player data, look up live fights, listen to plugin events, and add their own cosmetics and hotbar items. It consists of interfaces, enums, events and a small utility class. Internal plugin classes are not part of the API.

📚 [Javadoc](https://zonedevelopement.github.io/ZonePracticePro-Api/latest/) · 📦 [Releases](https://github.com/ZoneDevelopement/ZonePracticePro-Api/releases) · 📝 [Changelog](https://github.com/ZoneDevelopement/ZonePracticePro-Api/blob/master/CHANGELOG.md)

## Installation

The API is published on JitPack. The current version is `2.7.0`.

Gradle (Kotlin):

```kotlin
repositories {
    maven("https://jitpack.io")
}

dependencies {
    compileOnly("com.github.ZoneDevelopement:ZonePracticePro-Api:2.7.0")
}
```

Gradle (Groovy):

```groovy
repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    compileOnly 'com.github.ZoneDevelopement:ZonePracticePro-Api:2.7.0'
}
```

Maven:

```xml
<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>com.github.ZoneDevelopement</groupId>
    <artifactId>ZonePracticePro-Api</artifactId>
    <version>2.7.0</version>
    <scope>provided</scope>
  </dependency>
</dependencies>
```

Declare the dependency in `plugin.yml` so your plugin loads after ZonePractice Pro:

```yaml
depend: [ZonePracticePro]
```

Use `softdepend` instead if your addon works without ZonePractice Pro.

Do not shade the API into your jar. ZonePractice Pro provides it at runtime.

## Getting started

Check that the plugin is loaded and that the API version is high enough before you use it:

* `ZonePracticeApi.isAvailable()` returns `true` when the API is ready.
* `ZonePracticeApi.getInstance()` returns the API instance, or `null` when it is not available.
* `ZonePracticeApi.API_VERSION` is an integer that increases on every additive release. Version `2.4.0` has `API_VERSION = 3`. Check `API_VERSION >= 3` before you call methods added in 2.4.0.

`ZonePracticeReadyEvent` fires once on the main thread, after ZonePractice Pro has loaded its ladders, arenas, leaderboards and holograms. Register cosmetics categories and hotbar items in `onEnable`. Use `ZonePracticeReadyEvent` for logic that needs loaded ladders.

```java
@Override
public void onEnable() {
    if (!ZonePracticeApi.isAvailable() || ZonePracticeApi.API_VERSION < 4) {
        getLogger().warning("A ZonePractice Pro version with API 2.5.0+ is required.");
        getServer().getPluginManager().disablePlugin(this);
        return;
    }

    ZonePracticeApi api = ZonePracticeApi.getInstance();
    getServer().getPluginManager().registerEvents(new Listener() {
        @EventHandler
        public void onReady(ZonePracticeReadyEvent event) {
            getLogger().info("Ladders: " + api.getLadderNames());
        }
    }, this);
}
```

## Player data

All methods run on the main thread. Methods that return a number return `-1` when the player has no loaded profile. Methods marked `(2.4.0+)` are new in 2.4.0. Methods marked `(2.5.0+)` are new in 2.5.0.

| Method                                                                                                                        | Returns                                                                                                                                                         |
| ----------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `getPlayerDivision(player, DivisionName)`                                                                                     | The division name, or `null` if there is no loaded profile                                                                                                      |
| `getPlayerUnRankedLeft(player)`                                                                                               | Unranked matches left                                                                                                                                           |
| `getPlayerRankedLeft(player)`                                                                                                 | Ranked matches left                                                                                                                                             |
| `resetPlayerUnRanked(player)`                                                                                                 | Resets the unranked matches of the player                                                                                                                       |
| `resetPlayerRanked(player)`                                                                                                   | Resets the ranked matches of the player                                                                                                                         |
| `addPlayerUnRanked(player, amount)`                                                                                           | Adds unranked matches to the player                                                                                                                             |
| `addPlayerRanked(player, amount)`                                                                                             | Adds ranked matches to the player                                                                                                                               |
| `getElo(player, ladder)`                                                                                                      | Elo on a ladder. `-1` for an unknown or unranked-only ladder                                                                                                    |
| `getExperience(player)`                                                                                                       | Experience points                                                                                                                                               |
| `getLadderWins(player, ladder, WeightClass)`                                                                                  | Wins on a ladder for a weight class. `-1` for an unknown ladder                                                                                                 |
| `getLadderLosses(player, ladder, WeightClass)`                                                                                | Losses on a ladder for a weight class. `-1` for an unknown ladder                                                                                               |
| `getGlobalWins(player)`                                                                                                       | Unranked and ranked wins combined                                                                                                                               |
| `getLadderKills(player, ladder)` (2.4.0+)                                                                                     | Kills on a ladder. `-1` for an unknown ladder                                                                                                                   |
| `getLadderDeaths(player, ladder)` (2.4.0+)                                                                                    | Deaths on a ladder. `-1` for an unknown ladder                                                                                                                  |
| `getLadderNames()` (2.4.0+)                                                                                                   | Unmodifiable list of the enabled ladder names                                                                                                                   |
| `getWinStreak(player)` / `getBestWinStreak(player)` (2.5.0+)                                                                  | Current / best global win streak                                                                                                                                |
| `getLadderBestWinStreak(player, ladder, WeightClass)` (2.5.0+)                                                                | Best win streak on a ladder. `-1` for an unknown ladder, or `RANKED` on an unranked-only ladder                                                                 |
| `getKillStreak(player)` / `getBestKillStreak(player)` (2.5.0+)                                                                | Current / best FFA kill streak                                                                                                                                  |
| `getLadderBestKillStreak(player, ladder)` (2.5.0+)                                                                            | Best FFA kill streak on a ladder. `-1` for an unknown ladder                                                                                                    |
| `getGlobalKills(player)` (2.5.0+)                                                                                             | Kills summed over all ladders                                                                                                                                   |
| `getMatchesPlayed(player)` (2.5.0+)                                                                                           | Global wins plus losses                                                                                                                                         |
| `getFirstJoin(player)` (2.5.0+)                                                                                               | First join time in epoch milliseconds                                                                                                                           |
| `getDivisionNames(DivisionName)` (2.5.0+)                                                                                     | All division names, ordered lowest to highest                                                                                                                   |
| `getLeaderboardPosition(player, LeaderboardType, ladder)` (2.5.0+)                                                            | 1-based position on a leaderboard (`ladder` `null` = global). `-1` if the player is not listed. Leaderboards hold the top entries only and refresh periodically |
| `getPlayerDivisionProgress(player)` (2.7.0+)                                                                                  | Progress from 0 to 100 towards the next division, as the division menu shows. `100` in the highest division, `-1` if no divisions exist                         |
| `getPlayerNextDivision(player, DivisionName)` (2.7.0+)                                                                        | The next division name, or `null` in the highest division or without a loaded profile                                                                           |
| `getDivisionRequiredElo(division)` / `getDivisionRequiredExperience(division)` / `getDivisionRequiredWins(division)` (2.7.0+) | Global elo / experience / wins a division requires. `division` is its key in `divisions.yml` or a name from `getDivisionNames`. `-1` for an unknown division    |
| `getLadderIcon(ladder)` (2.7.0+)                                                                                              | A copy of the ladder icon, or `null` for an unknown ladder                                                                                                      |
| `getLadderDisplayName(ladder)` (2.7.0+)                                                                                       | The ladder display name in MiniMessage, or `null` for an unknown ladder                                                                                         |
| `getPlayerNametag(player)`                                                                                                    | The `PlayerNametag` of the player, or `null` if there is no loaded profile                                                                                      |
| `endMatch(player, endMessage)`                                                                                                | Ends the match of the player. Does nothing if the player is not in a match. `endMessage` is MiniMessage and nullable                                            |
| `openCosmeticsMenu(player)` (2.4.0+)                                                                                          | Opens the cosmetics hub                                                                                                                                         |

## Player state and lookups

`getPlayerState(player)` (2.4.0+) returns the `PlayerState` of a player. It never returns `null`. It returns `PlayerState.UNKNOWN` when the player has no loaded profile.

| `PlayerState`   | Meaning                                                     |
| --------------- | ----------------------------------------------------------- |
| `OFFLINE`       | The player is offline                                       |
| `LOBBY`         | The player is in the lobby                                  |
| `EDITOR`        | The player is editing a ladder kit                          |
| `CUSTOM_EDITOR` | The player is editing a custom kit                          |
| `QUEUE`         | The player is in a queue                                    |
| `MATCH`         | The player fights in a match                                |
| `FFA`           | The player fights in an FFA                                 |
| `EVENT`         | The player is in an event                                   |
| `SPECTATE`      | The player spectates a match, FFA or event                  |
| `STAFF_MODE`    | The player is in staff mode                                 |
| `UNKNOWN`       | No loaded profile, or a state added by a newer core version |

`PlayerState` also has `isFighting()` (true for `MATCH`, `FFA` and `EVENT`) and `isInLobby()` (true for `LOBBY` and `STAFF_MODE`).

These lookups return the object for a player, or `null` when the player is not in one. They run on the main thread.

| Method                                | Returns                                                                 |
| ------------------------------------- | ----------------------------------------------------------------------- |
| `getMatch(player)` (2.4.0+)           | The live match the player fights in. Spectated matches are not returned |
| `getSpectatingMatch(player)` (2.4.0+) | The match the player spectates                                          |
| `getMatchById(matchId)` (2.6.0+)      | A live or ended match by its id                                         |
| `getFfa(player)` (2.4.0+)             | The FFA the player fights in                                            |
| `getEvent(player)` (2.4.0+)           | The event the player is in                                              |
| `getParty(player)` (2.4.0+)           | The party the player is in                                              |
| `getQueue(player)` (2.4.0+)           | The queue the player is in                                              |

## Queues (2.7.0+)

These methods run on the main thread.

| Method                                                                                             | Returns                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `queuePlayer(player, ladder, ranked, keepInventoryOpen)`                                           | Queues the player like the queue menu does, with the usual messages. `true` if the player is queued for the ladder or a match started right away. `false` if the player is not in the lobby or a queue, is in staff mode or a party, the ladder is unknown, disabled, frozen or unranked-only for a ranked queue, or a requirement failed. Calling it again for a queued ladder changes nothing. `keepInventoryOpen` only applies with multi-queue |
| `startMatch(player1, player2, ladder, ranked, rounds, arena)` (2.12.0+, needs `API_VERSION >= 11`) | Starts a 1v1 match without a queue or a duel request and returns the `Match`. `rounds` 0 or less uses the ladder's value, `arena` `null` picks a random free arena. Ranked changes Elo. `null` if a player is not in the lobby, is in staff mode or a party, or the ladder or arena can't be used                                                                                                                                                  |
| `leaveQueue(player, ladder)`                                                                       | Removes one ladder from the queue. The queue ends with its last ladder                                                                                                                                                                                                                                                                                                                                                                             |
| `leaveAllQueues(player)`                                                                           | Ends the queue for every ladder                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `isMultiQueueAllowed(player)`                                                                      | `true` if multi-queue is enabled and the player has its permission                                                                                                                                                                                                                                                                                                                                                                                 |
| `getQueuedLadderNames(player)`                                                                     | Unmodifiable list of the queued ladder names, empty when not queued                                                                                                                                                                                                                                                                                                                                                                                |
| `isQueued(player, ladder)`                                                                         | `true` if the player is queued for the ladder                                                                                                                                                                                                                                                                                                                                                                                                      |
| `getQueuePlayerCount(ladder, ranked)` / `getQueuePlayerCount(ladder)`                              | Players queued for a ladder in one queue type / in both. `-1` for an unknown ladder                                                                                                                                                                                                                                                                                                                                                                |

## Fight objects

### Match

A match between players, with its spectators. Match and FFA also implement `Spectatable`.

* `getPlayers()` — players of the match.
* `getSpectators()` — spectators of the match.
* `getWinsNeeded()` — wins needed to win the match.
* `getLadderName()` — ladder name, or `null` if not set.
* `getLadderDisplayName()` — ladder display name, or `null` if not set.
* `getMatchId()` (2.4.0+) — unique match id.
* `getArenaName()` (2.4.0+) — name of the arena.
* `isRanked()` (2.4.0+) — whether the match is ranked.
* `getMatchType()` (2.4.0+) — `MatchType`. `BOT` for bot practice matches (2.8.0+), `UNKNOWN` for types from a newer core.
* `getDurationSeconds()` (2.4.0+) — how long the match has run.
* `getCurrentRoundNumber()` (2.4.0+) — current round, starting at 1.
* `getRoundInventories()` (2.6.0+) — inventory snapshots of every player in every finished round, sorted by round.
* `getRoundInventories(uuid)` (2.6.0+) — snapshots of one player, sorted by round.
* `getRoundInventory(uuid, round)` (2.6.0+) — one snapshot, or `null`.
* `getOriginalArenaName()` (2.11.0+) — name of the arena the match was asked for. For a match in an arena copy this is the original arena.
* `getArenaWorld()` (2.11.0+) — world of the arena.
* `getArenaBounds()` (2.11.0+) — box covering every block of the arena. The upper corner is exclusive.
* `isBuildArena()` (2.11.0+) — `true` for a build arena or an arena copy, which host one match at a time.
* `getBotBodies()` (2.11.0+) — bot bodies taking part in the match. Empty for matches without bots.

#### Round inventories

ZonePractice Pro saves each player's inventory when a round ends, or when the player dies in it. These are the inventories shown by `/matchinv`. A `RoundInventory` (2.6.0+) has `getPlayerUuid()`, `getRoundNumber()`, `getContents()`, `getArmor()`, `getHealth()`, `getHunger()` and `getPotionEffects()`. `getContents()` and `getArmor()` return copies, so changing them does not change the saved snapshot.

The snapshots of a round are available from `MatchRoundEndEvent`. All rounds are available from `MatchEndEvent`, and later through `getMatchById(matchId)`. Players who were offline when the round ended have no snapshot.

```java
@EventHandler
public void onMatchEnd(MatchEndEvent event) {
    for (RoundInventory inventory : event.getMatch().getRoundInventories()) {
        getLogger().info(inventory.getPlayerUuid() + " round " + inventory.getRoundNumber()
                + ": " + inventory.getHealth() + " health");
    }
}
```

#### Bot practice matches

For a bot practice match, `Match.getPlayers()` contains the human participant only. The opponent is a separately owned native player entity: it has no ordinary human profile and is replaced between rounds. Do not assume every match has two human players, cast a generic match to a duel, or retain an opponent entity UUID across rounds.

Bot practice publishes the cancellable `MatchStartEvent` and spectator start/end events. It does not publish the ordinary competitive `MatchEndEvent` or `MatchRoundEndEvent`. `MatchRoundStartEvent` fires for each bot practice round too. Practice outcomes do not award competitive statistics, progression, rewards or ordinary match history. `getMatchType()` returns `BOT` for a bot practice match (2.8.0+). Addons must check the match kind before applying their own competitive effects from a start or spectator event.

Bot opponents come from a bot addon. ZonePractice Pro only hosts the match: arena, kit, rounds, outcomes, isolation, sidebar and spectators. Without an addon no bot practice is available.

Results contain detached values and expire after 1200 server ticks; they are also cleared on dismissal, a new accepted fight, disconnect and plugin shutdown.

#### Bot providers (2.8.0+)

A bot addon registers one `BotProvider` with `ZonePracticeApi.getInstance().getBotRegistry().register(plugin, provider)`; only one provider can be registered at a time. All registry and provider calls happen on the main thread.

* `BotProvider#spawn(entityId, location, options)` spawns a paused body with exactly the given UUID and returns a `BotOpponent`. The core reserves the UUID as a bot identity first, so profiles, statistics and lobby handling ignore it. Throw on failure and leave nothing behind.
* `BotOpponent#tick(view)` runs once per server tick while the round is live; `pause()` is called during countdowns, at round end and after a death; `show`/`hide` manage viewers; `remove()` must be idempotent.
* `BotOptions(label, values)` carries the player's choice, for example a difficulty. The core shows `label` and passes `values` back to the provider unchanged.
* `BotRegistry#openSetup(player, options)` opens the core ladder, arena and round selection; the match then starts with `options`. `BotRegistry#start(player, setup)` starts a match from a `BotSetup` (ladder, arena or `null` for automatic, wins needed, options) and returns `null` or an error key; on failure the core tells the player why. `getLastSetup(player)` returns the setup of the player's last bot match for 1200 ticks after it ends. `reserveEntityId`/`releaseEntityId` protect bodies the addon spawns outside matches. `isBot(uuid)` tells whether an entity is a bot body.
* `BotProvider#getSetupCommand()` is offered in the result message after a bot match, plain and with the argument `rematch`; the command should start `getLastSetup(player)` again for `rematch`.
* When the provider's plugin is disabled, its active bot matches end.

### FFA

A free-for-all arena fight. It has only the `Spectatable` methods.

### Event

A game mode event. It also implements `Spectatable`.

* `getStarter()` — the starter of the event, as an `Object`.
* `getPlayers()` — players of the event.
* `getSpectators()` — spectators of the event.
* `getStartPlayerCount()` — number of players the event started with.
* `getWinner()` — the winner of the event.

### Party

A group of players.

* `getLeader()` — the party leader.
* `getMembers()` — the party members.

### Queue

A player waiting for a match.

* `getPlayer()` — the queued player.
* `getDuration()` — the queue duration.
* `isRanked()` — whether the queue is ranked.
* `getLadderName()` (2.4.0+) — the ladder the player is queued for.

### Spectatable

Shared by Match, FFA and Event.

* `getSpectators()` — the spectators.
* `addSpectator(spectator, target, teleport, message)` — adds a spectator. `teleport` moves them to `target`. `message` sends the start message.
* `removeSpectator(player)` — removes a spectator.
* `sendMessage(message, spectate)` — sends a MiniMessage message to the fight. `spectate` also sends it to spectators.

## Events

All events extend Bukkit's `Event`. Listen to them with `@EventHandler`. Events marked `(2.4.0+)` are new in 2.4.0.

| Event                             | Fires when                                                                                                                                                                                                      | Main data                                                                                                                                                           | Cancellable |
| --------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| **Match**                         |                                                                                                                                                                                                                 |                                                                                                                                                                     |             |
| `MatchStartEvent`                 | A match starts                                                                                                                                                                                                  | `getMatch()`                                                                                                                                                        | Yes         |
| `MatchEndEvent`                   | A match ends                                                                                                                                                                                                    | `getMatch()`                                                                                                                                                        | No          |
| `MatchRoundStartEvent`            | A round starts                                                                                                                                                                                                  | `getMatch()`, `getRound()`                                                                                                                                          | No          |
| `MatchRoundEndEvent`              | A round ends                                                                                                                                                                                                    | `getMatch()`, `getRound()`                                                                                                                                          | No          |
| `MatchBlockChangeEvent` (2.11.0+) | A block of a match changes: placed, broken, fluid, fire, explosion or a temporary build removed. The block may still hold its old state, so read it later in the tick. Not fired for the rollback after a match | `getMatch()`, `getBlock()`                                                                                                                                          | No          |
| **Queue**                         |                                                                                                                                                                                                                 |                                                                                                                                                                     |             |
| `QueueStartEvent`                 | A player starts queueing                                                                                                                                                                                        | `getQueue()`                                                                                                                                                        | Yes         |
| `QueueEndEvent`                   | A player leaves a queue                                                                                                                                                                                         | `getQueue()`                                                                                                                                                        | No          |
| **Event** (package `Event.Event`) |                                                                                                                                                                                                                 |                                                                                                                                                                     |             |
| `EventStartEvent`                 | An event starts                                                                                                                                                                                                 | `getEvent()`                                                                                                                                                        | Yes         |
| `EventEndEvent`                   | An event ends                                                                                                                                                                                                   | `getEvent()`                                                                                                                                                        | No          |
| **FFA**                           |                                                                                                                                                                                                                 |                                                                                                                                                                     |             |
| `FFARemovePlayerEvent`            | A player is removed from an FFA                                                                                                                                                                                 | `getFfa()`, `getPlayer()`                                                                                                                                           | No          |
| **Player**                        |                                                                                                                                                                                                                 |                                                                                                                                                                     |             |
| `NewPlayerJoin`                   | A player joins for the first time (about 2 seconds after their profile is created)                                                                                                                              | `getPlayer()`                                                                                                                                                       | No          |
| `PlayerStateChangeEvent` (2.4.0+) | The `PlayerState` of a player changes                                                                                                                                                                           | `getPlayerId()`, `getPlayer()` (nullable), `getFrom()`, `getTo()`                                                                                                   | No          |
| `PartyCreateEvent`                | A party is created                                                                                                                                                                                              | `getParty()`                                                                                                                                                        | Yes         |
| `HotbarApplyEvent` (2.4.0+)       | A hotbar layout and its addon items are applied                                                                                                                                                                 | `getPlayer()`, `getLayout()`                                                                                                                                        | No          |
| `KitAppliedEvent` (2.4.0+)        | A kit and its cosmetics are applied to a player. Listeners may change the inventory                                                                                                                             | `getPlayer()`, `getFightType()`, `getFight()`, `getLadderName()`                                                                                                    | No          |
| `EloChangeEvent` (2.4.0+)         | The elo of a player on a ladder changes                                                                                                                                                                         | `getPlayer()`, `getLadderName()`, `getOldElo()`, `getNewElo()`, `getDelta()`, `getMatch()` (nullable)                                                               | No          |
| `ZonePracticeReadyEvent` (2.4.0+) | ZonePractice Pro has loaded its data                                                                                                                                                                            | none                                                                                                                                                                | No          |
| **Fight**                         |                                                                                                                                                                                                                 |                                                                                                                                                                     |             |
| `FightDeathEvent` (2.4.0+)        | A death is confirmed, after stats are updated. Not fired for events                                                                                                                                             | `getVictim()`, `getKiller()` (nullable), `getFightType()`, `getFight()`, `getLadderName()`, `getDeathMessage()` (nullable), `hasKiller()`, `getMatch()`, `getFfa()` | No          |
| **Spectate start**                |                                                                                                                                                                                                                 |                                                                                                                                                                     |             |
| `MatchSpectateStartEvent`         | A player starts spectating a match                                                                                                                                                                              | `getPlayer()`, `getMatch()`                                                                                                                                         | Yes         |
| `FFASpectateStartEvent`           | A player starts spectating an FFA                                                                                                                                                                               | `getPlayer()`, `getFfa()`                                                                                                                                           | Yes         |
| `EventSpectateStartEvent`         | A player starts spectating an event                                                                                                                                                                             | `getPlayer()`, `getEvent()`                                                                                                                                         | Yes         |
| **Spectate end**                  |                                                                                                                                                                                                                 |                                                                                                                                                                     |             |
| `MatchSpectateEndEvent`           | A player stops spectating a match                                                                                                                                                                               | `getPlayer()`, `getMatch()`                                                                                                                                         | No          |
| `FFASpectateEndEvent`             | A player stops spectating an FFA                                                                                                                                                                                | `getPlayer()`, `getFfa()`                                                                                                                                           | No          |
| `EventSpectateEndEvent`           | A player stops spectating an event                                                                                                                                                                              | `getPlayer()`, `getEvent()`                                                                                                                                         | No          |

`SpectateStartEvent` and `SpectateEndEvent` are the base classes of the spectate events. Each subclass has its own handler list, so listen to the subclass (for example `MatchSpectateStartEvent`) to receive it.

All events are synchronous and fire on the main thread.

## Registries

### Cosmetics categories

`api.getCosmeticsRegistry()` adds buttons to the cosmetics hub. Registered categories appear below the built-in buttons, 7 per row, up to 21 in total. Extra categories are ignored and the core logs a warning. `register(plugin, category)` throws `IllegalArgumentException` for an invalid or duplicate id. `unregister(id)` and `getCategories()` are also available. Categories of a plugin are removed automatically when that plugin is disabled. Server owners can pin a category to a fixed slot with `GUIS.COSMETICS.HUB.ADDON-SLOTS` in `guis.yml`, using the category id.

```java
api.getCosmeticsRegistry().register(this, new CosmeticCategory() {
    @Override
    public String getId() {
        return "myaddon_pets";
    }

    @Override
    public ItemStack getIcon(Player player) {
        return player.hasPermission("myaddon.pets") ? new ItemStack(Material.BONE) : null;
    }

    @Override
    public void onClick(Player player) {
        player.sendMessage("Opening pets...");
    }
});
```

`getIcon` returns `null` to hide the category for a viewer. `getPriority()` is optional and defaults to `0`. Lower values come first.

### Hotbar items

`api.getHotbarItemRegistry()` adds items to the core hotbar layouts. Each item has a `HotbarLayout` and a slot from `0` to `35`. `register(plugin, item)` throws `IllegalArgumentException` for an invalid or duplicate id or a slot outside `0`-`35`. If a built-in item already uses that slot in that layout, the addon item is skipped and a warning is logged. Addon items cannot be dropped or moved, like built-in items. `refresh(player)` re-applies the addon items of the current layout. `getItemId(itemStack)` returns the id of an addon item, or `null`. Items of a plugin are removed automatically when that plugin is disabled.

```java
api.getHotbarItemRegistry().register(this, new HotbarItem() {
    @Override
    public String getId() {
        return "myaddon_stats";
    }

    @Override
    public HotbarLayout getLayout() {
        return HotbarLayout.LOBBY;
    }

    @Override
    public int getSlot() {
        return 4;
    }

    @Override
    public ItemStack getItem(Player player) {
        return new ItemStack(Material.BOOK);
    }

    @Override
    public void onUse(Player player) {
        player.sendMessage("Your stats...");
    }
});
```

`getItem` returns `null` to skip the item for a player. `onUse` runs when the player right-clicks with the item.

### Name decorations (2.5.0+)

`getNameDecorationRegistry()` returns a `NameDecorationRegistry`. A registered `NameDecorator` adds components before or after a player's name wherever ZonePractice Pro renders it. `NameLocation` is where the name is rendered:

| `NameLocation` | Where                                                                                        |
| -------------- | -------------------------------------------------------------------------------------------- |
| `NAMETAG`      | Above-head nametag                                                                           |
| `TAB`          | Tab list name                                                                                |
| `CHAT`         | Chat format name (server, party and staff chat)                                              |
| `SIDEBAR`      | Full-name sidebar placeholders such as `%player%`. `NameOnly` placeholders are not decorated |

`getPrefix(player, location)` and `getSuffix(player, location)` return a component or `null`. Decorators with a lower `getPriority()` are rendered closer to the name. `CHAT` is requested from the async chat thread, so the decorator must be thread-safe there. After the decorator output changes, call `refresh(player)` to re-render the nametag and tab name; chat and sidebar pick up changes on their own. Nametag and tab decorations need ZonePractice Pro's nametag management to be enabled. Decorators are unregistered when their plugin is disabled.

```java
ZonePracticeApi.getInstance().getNameDecorationRegistry().register(this, new NameDecorator() {
    @Override
    public String getId() {
        return "myaddon_badges";
    }

    @Override
    public Component getPrefix(Player player, NameLocation location) {
        return null;
    }

    @Override
    public Component getSuffix(Player player, NameLocation location) {
        return Component.text(" ★", NamedTextColor.GOLD);
    }
});
```

### Arena leases (2.11.0+)

`api.leaseArena(plugin, arenaName)` leases a free arena for an addon session, for example to show something to players in it. It returns an `ArenaLease`, or `null` if the arena is unknown, disabled, frozen or has no free copy. Build arenas and their copies are exclusive: no match or other lease starts in them until the lease is released. Other arenas are shared with matches. Leases are released automatically when the owner plugin is disabled. Main thread only.

* `getArenaName()` — name of the leased arena or arena copy.
* `getOriginalArenaName()` — name of the arena the lease was asked for. For a copy this is the original arena.
* `getWorld()` and `getBounds()` — world of the arena and the box covering its blocks, upper corner exclusive.
* `isBuild()` — `true` for a build arena or an arena copy.
* `isActive()` — `true` until `release()` is called or the owner plugin is disabled.
* `release()` — releases the arena. Safe to call more than once.

## Enums

| Enum                       | Values                                                                                                                              | Purpose                                                           |
| -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| `DivisionName`             | `SHORT`, `FULL`                                                                                                                     | Format of the division name                                       |
| `WeightClass`              | `UNRANKED`, `RANKED`                                                                                                                | Selects unranked or ranked stats                                  |
| `FightType`                | `MATCH`, `FFA`, `EVENT`                                                                                                             | Kind of fight a player takes part in                              |
| `MatchType`                | `DUEL`, `PARTY_FFA`, `PARTY_SPLIT`, `PARTY_VS_PARTY`, `BOT` (2.8.0+), `UNKNOWN`                                                     | Type of a match. `UNKNOWN` is for types from a newer core         |
| `PlayerState`              | `OFFLINE`, `LOBBY`, `EDITOR`, `CUSTOM_EDITOR`, `QUEUE`, `MATCH`, `FFA`, `EVENT`, `SPECTATE`, `STAFF_MODE`, `UNKNOWN`                | State of a player. See [Player state](#player-state-and-lookups)  |
| `HotbarLayout`             | `LOBBY`, `PARTY`, `MATCH_QUEUE`, `EVENT_QUEUE`, `STAFF_MODE`, `SPECTATOR_LOBBY`, `SPECTATE_MATCH`, `SPECTATE_EVENT`, `SPECTATE_FFA` | Hotbar layouts the core rebuilds                                  |
| `NameLocation` (2.5.0+)    | `NAMETAG`, `TAB`, `CHAT`, `SIDEBAR`                                                                                                 | Where a player name is rendered. See the Name decorations section |
| `LeaderboardType` (2.5.0+) | `ELO`, `WINS`, `KILLS`, `DEATHS`, `WIN_STREAK`, `BEST_WIN_STREAK`, `LOSE_STREAK`, `BEST_LOSE_STREAK`                                | Leaderboard read by `getLeaderboardPosition`                      |

## Utilities

`PlayerNametag` is a value object returned by `getPlayerNametag(player)`. It holds the nametag of a player:

* `getPrefix()` — prefix as an Adventure `Component`.
* `getColorOfName()` — name color as a `NamedTextColor`.
* `getSuffix()` — suffix as an Adventure `Component`.
* `getSortPriority()` — sort priority as an `int`.

## Versioning and releases

The API uses semantic versioning. Each additive release, which adds methods, events or enums, increases `API_VERSION` by 1. Check `API_VERSION` before you use new methods.

Each release is published on [GitHub Releases](https://github.com/ZoneDevelopement/ZonePracticePro-Api/releases) with the changelog and the `api`, `sources` and `javadoc` jars. The same version is available on JitPack. The javadoc of each version is at `https://zonedevelopement.github.io/ZonePracticePro-Api/<version>/`.
