# Developer API

Add GlacierHub as a dependency, read the 13 feature APIs and listen to its 9 events.

The API ships inside the plugin JAR. Server owners install one plugin; there's no separate API plugin to keep in sync.

Only `dev.glacierlabs.glacierhub.api` and its subpackages are supported. Everything else in the JAR is internal and can change between releases.

## Add the dependency

Use the same artifact you put on the server, in `provided` scope:

```xml
<dependency>
    <groupId>dev.glacierlabs</groupId>
    <artifactId>GlacierHub</artifactId>
    <version>2.0.1</version>
    <scope>provided</scope>
</dependency>
```

Do not shade GlacierHub into your plugin. Bukkit's service lookup relies on both plugins using the API classes from GlacierHub's classloader.

In `plugin.yml`, use a hard dependency if you can't run without it:

```yaml
depend: [GlacierHub]
```

Use `softdepend: [GlacierHub]` when the integration is optional, and keep the GlacierHub imports in a separate class that you only load after checking:

```java
if (getServer().getPluginManager().isPluginEnabled("GlacierHub")) {
    glacierHubIntegration = new GlacierHubIntegration();
}
```

The class split matters. If GlacierHub isn't installed, its classes don't exist, and an `Optional` can't stop the JVM from loading a class that references them.

## Get the API

```java
private GlacierHubApi glacierHub;

@Override
public void onEnable() {
    glacierHub = GlacierHubProvider.get();
}
```

`GlacierHubProvider.getIfPresent()` returns an `Optional` for the short window where the plugin exists but its service isn't registered yet.

Feature getters are empty while their module is disabled:

```java
glacierHub.getSpawnApi().ifPresent(spawn -> spawn.teleport(player));
```

If you keep a feature handle, check `isAvailable()` before using it again. A disabled feature returns `false` and throws `FeatureUnavailableException` on use.

> [!IMPORTANT]
> Call every API method from the main server thread. On Folia, use the thread that owns the player you pass in.

## Feature APIs

| Module | Getter | Methods |
| --- | --- | --- |
| `spawn` | `getSpawnApi()` | `getSpawnPoint()`, `teleport(Player)` |
| `navigator` | `getNavigatorApi()` | `open(Player)`, `connect(Player, String server)` |
| `scoreboard` | `getScoreboardApi()` | `isVisible`, `show`, `hide`, `toggle`, `refresh` |
| `tab` | `getTabApi()` | `refresh(Player)` |
| `customitems` | `getCustomItemsApi()` | `giveItems`, `isCustomItem(Player, ItemStack)`, `removeItems` |
| `points` | `getPointsApi()` | `getBalance`, `deposit`, `withdraw`, `setBalance` |
| `cosmetics` | `getCosmeticsApi()` | `getSelectedCosmeticName(Player, CosmeticSlot)`, `openMenu` |
| `maintenance` | `getMaintenanceApi()` | `isEnabled()`, `setEnabled(boolean)` |
| `voterewards` | `getVoteRewardsApi()` | `getTotalVotes()`, `getVotePartyGoal()` |
| `shop` | `getShopApi()` | `hasPurchased(UUID, String entryId)` |
| `friends` | `getFriendsApi()` | `getFriends(UUID)`, `areFriends(UUID, UUID)` |
| `parkour` | `getParkourApi()` | `getCourseIds()`, `getBestTimeMillis(UUID, String)` |
| `rewards` | `getRewardsApi()` | `getStreak(UUID)` |

`CosmeticSlot` is one of `HAT`, `WING`, `PARTICLE`, `PET`, `GADGET` or `EFFECT`.

The remaining modules (`core`, `chatformat`, `utilities`, `protections`, `social`, `customgui`, `queue`, `announcer`, `leaderboards`) have no feature API and only appear in module info.

### Points example

```java
glacierHub.getPointsApi().ifPresent(points -> {
    UUID id = player.getUniqueId();
    if (points.withdraw(id, 250)) {
        player.sendMessage("Bought for 250 Points. " + points.getBalance(id) + " left.");
    } else {
        player.sendMessage("Not enough Points.");
    }
});
```

`withdraw` returns `false` instead of going negative.

## Module info

```java
glacierHub.isModuleEnabled(ModuleIds.PARKOUR);
glacierHub.getModule(ModuleIds.QUEUE).map(ModuleInfo::getDisplayName);
```

`getModules()` and `getModule(String)` return immutable snapshots. Ask again when you need the current state. Module IDs are constants in `ModuleIds`.

The API doesn't expose module enable/disable controls, managers, listeners or config files.

## Events

All events are synchronous. They fire on the thread that handled the action: the main thread on Paper, the player's region thread on Folia.

| Event | Fired when | Getters |
| --- | --- | --- |
| `GlacierHubModuleEnabledEvent` | A module is turned on at runtime | `getModule()` |
| `GlacierHubModuleDisabledEvent` | A module is turned off at runtime | `getModule()` |
| `GlacierHubPrivateMessageEvent` | A player sends a private message | `getSender()`, `getRecipient()`, `getMessage()` |
| `GlacierHubPlayerReportEvent` | A player reports another player | `getReporter()`, `getTarget()`, `getReason()` |
| `GlacierHubFriendshipChangedEvent` | Two players become or stop being friends | `getFirstPlayerId()`, `getSecondPlayerId()`, `isAdded()` |
| `GlacierHubMaintenanceToggledEvent` | Maintenance is switched with the command | `getActorName()`, `isEnabled()` |
| `GlacierHubPlayerVotedEvent` | A vote comes in | `getPlayerName()`, `getServiceName()`, `getTotalVotes()` |
| `GlacierHubVotePartyTriggeredEvent` | The Vote Party goal is reached | `getGoal()` |
| `GlacierHubShopPurchaseEvent` | A player buys something in the shop | `getPlayer()`, `getEntryId()`, `getPrice()` |

```java
@EventHandler
public void onModuleEnabled(GlacierHubModuleEnabledEvent event) {
    if (ModuleIds.SPAWN.equals(event.getModule().getId())) {
        getLogger().info("GlacierHub's spawn module was enabled");
    }
}
```

Module events aren't fired for modules loaded at startup or stopped at shutdown.

## Versioning

The plugin version and the API version are separate. Read them with `getPluginVersion()` and `getApiVersion()`.

- **Major**: existing integrations need source changes.
- **Minor**: new backward-compatible methods.
- **Patch**: documentation or behaviour fixes.

## Javadocs

```text
mvn clean javadoc:javadoc
```

Open `target/site/apidocs/index.html`. The generated site contains only the supported API packages.
