Skip to content

Lesson 11 of 13 · 16m

Playing Nice: Services, softdepend, and Vault

Load-order contracts, ServicesManager and Vault-style interfaces, and shade-and-relocate discipline for libraries.

Your plugin will not live alone. The average Paper server runs thirty of you, and the professional move is exposing what you do for other plugins — and consuming what they expose — without hard-requiring jars your users may not have.

Loading order as API

plugin.yml carries three ordering keys. depend: [Vault] refuses to enable unless Vault is present — a hard contract for plugins that cannot function without it. softdepend: [Vault] means "load after it if installed" — the right default for optional integrations. loadbefore is the inverse for things that must exist earlier. Ordering matters because onEnable is when you look other plugins up: a plugin that enables after you is not a Plugin instance yet while your onEnable runs.

Guard optional integrations:

Plugin vault = getServer().getPluginManager().getPlugin("Vault");
if (vault != null && vault.isEnabled()) {
    RegisteredServiceProvider<Economy> rsp =
        getServer().getServicesManager().getRegistration(Economy.class);
    if (rsp != null) this.economy = rsp.getProvider();
}

Check isEnabled(), not just non-null — a jar on disk can be disabled by the time you look.

The ServicesManager pattern

Bukkit's own integration mechanism is ServicesManager. Publish with getServer().getServicesManager().register(YourApi.class, impl, plugin, ServicePriority.Normal); consume with .load(YourApi.class). The consumer never sees your classes — only the interface you both compile against.

Vault is the canonical example worth knowing by name: a single API surface (net.milkbowl.vault, pulled through JitPack as com.github.MilkBowl:VaultAPI) that fronts every economy, permission, and chat plugin written in the last decade. When your kit plugin needs to charge 500 coins, you write economy.withdrawPlayer(player, 500) and whatever the server actually runs — EssentialsX, a custom econ, a homebrew ledger — satisfies the interface. EconomyResponse.transactionSuccess() tells you whether the charge landed.

LuckPerms exposes a real API too (net.luckperms:api on its own Maven repo): LuckPermsProvider.get() returns the provider after a Vault-style lookup, and its Node model is what real permission checks resolve to when hasPermission is too coarse.

Shading and relocating

When the dependency is a library rather than a plugin, you ship it inside your jar — "shading" — through the Shadow Gradle plugin (com.gradleup.shadow):

tasks.shadowJar {
    relocate("com.zaxxer.hikari", "org.sudosecurity.sudotools.libs.hikari")
    minimize()
}

Two rules keep you out of other plugins' stack traces:

  • compileOnly everything the server already provides — the API, Adventure, Guava.
  • relocate everything you shade. Unrelocated shaded classes collide with every other plugin that shaded a different version of the same library, and the failure is a NoSuchMethodError in someone else's jar that nobody traces back to you.

libraries: in plugin.yml is the third path — Maven coordinates Paper downloads at startup:

libraries:
  - com.zaxxer:HikariCP:5.1.0
  - org.xerial:sqlite-jdbc:3.46.1.3

Smaller jar, shared downloads, no relocation debt; the cost is a network fetch on first boot, so it fits libraries on Maven Central and fails for private artifacts behind auth. Air-gapped or firewalled servers also can't fetch — shade for those audiences, libraries: for everyone else.

One integration trap worth naming: compileOnly against the highest Vault-API version you tolerate, then guard the lookup. getPlugin("Vault") returning non-null doesn't mean the Economy service is registered — Vault ships the interfaces; the economy plugin registers the provider.

Field notes

  • Expose your own API as an interface other plugins can compile against without depending on your internals; register it through ServicesManager in onEnable.
  • An integration that throws when the optional plugin is absent is worse than no integration — null-check, degrade, log once.
  • PluginEnableEvent exists if you truly need "after X enables," but softdepend covers almost every case.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.