Developer API
On this page(5)
SnDiscordLink exposes a public developer API for other plugins: a read-only query service that tells you which Minecraft accounts are linked to Discord. The API lives in the com.sn.discordlink.api package inside the plugin jar. There is no separate artifact.
Only com.sn.discordlink.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=SnDiscordLink-<version>.jar -DgroupId=com.sn \ -DartifactId=SnDiscordLink -Dversion=<version> -Dpackaging=jar -
Depend on it with
providedscope. Never shade it.
Quick start
Declare the dependency in your plugin.yml:
depend: [SnDiscordLink] # or softdepend if optionalResolve the API when you need it:
SnDiscordLinkAPI api = SnDiscordLinkProvider.get();
if (api != null) {
boolean linked = api.isLinked(player.getUniqueId());
}Resolve the reference when you need it. Do not cache it across a SnDiscordLink reload.
SnDiscordLink registers the service a moment after it enables, once its database tables exist. A plugin that enables right after it may get null at first, so resolve the API when you use it, not only in onEnable.
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. The current API fires no events.
Query service
Synchronous methods read the in-memory cache. Call them on the main thread.
| Method | Returns | Notes |
|---|---|---|
isLinked(UUID) | boolean | True when the link is cached. The cache holds online players only. |
getLink(UUID) | DiscordLinkView or null | The cached link of an online player. |
getLinkedCount() | long | Linked accounts across the network, as of the last periodic count. |
getApiVersion() | String | The API contract version. |
The cache of a player fills right after they join. For that moment, isLinked returns false even for a linked account. Confirm a false with fetchLinked before you deny anything.
Asynchronous methods read the shared database. They work for offline players and on any server of the network.
| Method | Returns | Notes |
|---|---|---|
fetchLinked(UUID) | CompletableFuture<Boolean> | True when the account is linked. |
fetchLink(UUID) | CompletableFuture<Optional<DiscordLinkView>> | The link, or empty when the account is not linked. |
CompletableFuture results complete on an async thread. Hop back to the main thread before touching the Bukkit API.
DiscordLinkView is an immutable snapshot with these fields:
| Field | Type | Meaning |
|---|---|---|
uuid() | UUID | The Minecraft account. |
discordId() | long | The Discord user id. |
discordName() | String or null | The Discord username, once the bot saw the member. |
minecraftName() | String or null | The last known Minecraft name. |
linkedAt() | long | Epoch millis of the link. |
boosting() | boolean | Whether the member boosts the Discord server. |
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.