For developers: BK-Tops API
BK-Tops API (JitPack) — Guide & Examples
Section titled “BK-Tops API (JitPack) — Guide & Examples”This document explains how to consume the BK‑Tops API module from JitPack and shows practical usage examples.
What is it?
Section titled “What is it?”The api module exposes a minimal, implementation‑agnostic API to interact with BK‑Tops from other Bukkit/Paper plugins. You can:
- Access a loaded
Topby id - Iterate all registered tops
- Find which top a player is currently on
- Register/unregister custom tops
- Request a top to restart/rebuild
Core entry points:
TopAPI— main interfaceTopAPIProvider— static accessor and lifecycle guard for the singleton instance
Getting the API from JitPack
Section titled “Getting the API from JitPack”BK‑Tops is built on JDK 21 and published for consumption via JitPack.
Add JitPack to your repositories and depend on the API artifact.
Gradle (Kotlin DSL)
Section titled “Gradle (Kotlin DSL)”repositories { maven("https://jitpack.io")}
dependencies { // Replace the version with a Git tag (recommended) or commit hash from this repo // Examples: 1.0.0, 1.0.0-SNAPSHOT compileOnly("com.github.Blakube-Team:BK-Tops:Tag")}Gradle (Groovy)
Section titled “Gradle (Groovy)”repositories { maven { url 'https://jitpack.io' }}
dependencies { // Use a Git tag or commit hash as the version compileOnly 'com.github.Blakube-Team:BK-Tops:Tag'}<repositories> <repository> <id>jitpack.io</id> <url>https://jitpack.io</url> </repository></repositories>
<dependencies> <dependency> <groupId>com.github.Blakube-Team</groupId> <artifactId>BK-Tops</artifactId> <version>Tag</version> </dependency></dependencies>Notes
: Use a Git tag from this repository for stable builds, or a commit SHA for pinning. - Scope: Prefer
compileOnly/provided— the server will provide BK‑Tops at runtime. - Java version: Your plugin should target Java 17+ runtime on modern Paper, but this API is compiled with toolchain Java 21.
Quick Start
Section titled “Quick Start”- Declare a soft/hard dependency in your
plugin.ymlto ensure BK‑Tops loads before your plugin if you require the API at startup:
depend: [BK-Tops] # hard dependency (your plugin won’t load without BK‑Tops)# orsoftdepend: [BK-Tops] # soft dependency (you must handle API absence)- Access the API safely:
import com.blakube.bktops.api.TopAPI;import com.blakube.bktops.api.TopAPIProvider;
public final class MyPlugin extends JavaPlugin { @Override public void onEnable() { if (!TopAPIProvider.isAvailable()) { getLogger().warning("BK-Tops API not available. Is the plugin installed and enabled?"); // Decide: either disable or continue in degraded mode return; }
TopAPI api = TopAPIProvider.getInstance(); // use the API ... }}API Overview
Section titled “API Overview”TopAPI (from api/src/main/java/com/blakube/bktops/api/TopAPI.java):
public interface TopAPI { @Nullable Top getTop(@NotNull String id); @NotNull Collection<Top> getAllTops(); Optional<Top> getTopByPlayer(@NotNull Player player);
boolean restartTop(@NotNull String topId); void registerTop(@NotNull Top top); void unregisterTop(@NotNull String topId);}Key model types in the API module you may also use:
com.blakube.bktops.api.top.Topcom.blakube.bktops.api.top.TopEntrycom.blakube.bktops.api.timed.TimedTopandResetSchedulecom.blakube.bktops.api.queue.*for processing queue primitivescom.blakube.bktops.api.event.*for listening to domain events
Common Tasks — Code Examples
Section titled “Common Tasks — Code Examples”1) Get a top by id and iterate entries
Section titled “1) Get a top by id and iterate entries”TopAPI api = TopAPIProvider.getInstance();Top top = api.getTop("kills");if (top != null) { for (TopEntry entry : top.getEntries()) { getLogger().info(entry.getName() + ": " + entry.getValue()); }}2) List all registered tops
Section titled “2) List all registered tops”TopAPI api = TopAPIProvider.getInstance();for (Top top : api.getAllTops()) { getLogger().info("Top: " + top.getId());}3) Check if a player is currently on any top
Section titled “3) Check if a player is currently on any top”TopAPI api = TopAPIProvider.getInstance();api.getTopByPlayer(player).ifPresent(playerTop -> { player.sendMessage("You are on the top: " + playerTop.getId());});4) Restart a top’s processing
Section titled “4) Restart a top’s processing”boolean accepted = TopAPIProvider.getInstance().restartTop("kills");if (!accepted) { getLogger().warning("Top restart request was not accepted (unknown id or busy).");}5) Register and unregister a custom top
Section titled “5) Register and unregister a custom top”If you implement your own Top (or TimedTop), you can register/unregister it dynamically:
Top myTop = /* your Top implementation */;TopAPI api = TopAPIProvider.getInstance();api.registerTop(myTop);// ... laterapi.unregisterTop(myTop.getId());Listening to API Events
Section titled “Listening to API Events”The API exposes Bukkit events under com.blakube.bktops.api.event.* that you can listen to in your plugin.
Example: react to player position updates in a top
import com.blakube.bktops.api.event.top.TopPositionUpdateEvent;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;
public final class TopEventsListener implements Listener { @EventHandler public void onTopUpdate(TopPositionUpdateEvent e) { String topId = e.getTopId(); UUID playerId = e.getPlayerId(); int newPosition = e.getNewPosition(); // Your logic here }}Example: react to scheduled resets for timed tops
import com.blakube.bktops.api.event.top.TimedTopResetEvent;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;
public final class TimedTopListener implements Listener { @EventHandler public void onTimedReset(TimedTopResetEvent e) { getLogger().info("Timed top reset: " + e.getTopId() + " scope=" + e.getScope()); }}Don’t forget to register your listener in onEnable:
getServer().getPluginManager().registerEvents(new TopEventsListener(), this);Best Practices & Notes
Section titled “Best Practices & Notes”-
Initialization
- Use
TopAPIProvider.isAvailable()before callinggetInstance()if BK‑Tops might be missing. - Declare
depend/softdependonBK-Topsinplugin.ymlto control load order.
- Use
-
Classpath
- Use
compileOnly/providedfor the API dependency. Do not shade the BK‑Tops plugin itself.
- Use
-
Versioning via JitPack
- Prefer Git tags for reproducible builds, e.g.
1.0.0. - For bleeding‑edge, you may use a commit SHA or a branch with
-SNAPSHOTif enabled.
- Prefer Git tags for reproducible builds, e.g.
-
Java & Paper API
- The API declares a
compileOnlydependency onio.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT. Your plugin should target a compatible Paper/Spigot version.
- The API declares a
Troubleshooting
Section titled “Troubleshooting”-
“TopAPI not initialized yet! Is BK‑Tops plugin loaded?”
- Cause: You called
TopAPIProvider.getInstance()before BK‑Tops finished enabling, or BK‑Tops isn’t installed. - Fix: Add
depend: [BK-Tops]or checkTopAPIProvider.isAvailable()before accessing.
- Cause: You called
-
“TopAPI already initialized!” during
setInstance- This is internal to BK‑Tops. If you see it, ensure you are not repackaging or loading multiple copies.
License
Section titled “License”BK‑Tops is distributed under the terms of the LICENSE file in the repository.