MineDuelsApi
Bukkit ServicesManager API for matches, queues, parties, stats, leaderboards and history.
MineDuelsApi api = Bukkit.getServicesManager().load(MineDuelsApi.class);
if (api != null && !api.inMatch(player.getUniqueId())) {
api.elo(player.getUniqueId(), "nodebuff")
.ifPresent(elo -> player.sendMessage("NoDebuff ELO: " + elo));
}The same data is available over HTTP through the web API.
Methods
Live state, answered at once from memory:
| Method | Returns |
|---|---|
inMatch(UUID) | Whether the player is in a running match on this server |
queued(UUID) | Optional<QueueInfo> (global queue on cross-server lobbies) |
elo(UUID, kit) | OptionalInt ELO from the loaded profile. Empty for offline players |
partyOf(UUID) | Optional<PartyInfo> |
kits() | Sorted kit names |
matchOf(UUID) | Optional<MatchInfo> |
runningMatches() | List<MatchInfo>, every match running on this server |
queues() | List<QueueCount>, the queues of this server that have players waiting |
parties() | List<PartyInfo>, every party on this server |
draining() | Whether this server is draining |
Stored data, read from the database off the calling thread. These return a CompletableFuture:
| Method | Returns |
|---|---|
stats(UUID) | CompletableFuture<Optional<PlayerStats>>, stored stats of any player, online or not |
statsByName(String) | The same, found by last known name (case-insensitive) |
top(kit, limit) | CompletableFuture<List<LeaderboardRow>>. The kit name "overall" gives the overall board. limit is capped at 100 |
history(UUID, offset, limit) | CompletableFuture<List<MatchHistoryEntry>>, finished matches, newest first. limit is capped at 100 |
The new methods are default methods, so plugins compiled against an older API jar keep working. On a MineDuels older than this version they return empty results.
Never block a game thread on a future
The database futures complete on a small pool of their own. Do not call get() or join() on a server thread. Chain the work and go back to the server thread to touch players or worlds:
api.stats(player.getUniqueId()).thenAccept(optional -> {
optional.ifPresent(stats -> Bukkit.getScheduler().runTask(plugin, () ->
player.sendMessage("Streak: " + stats.streak() + ", best " + stats.bestStreak())));
});On Folia use player.getScheduler().run(...) instead of the Bukkit scheduler.
When the pool is full or the database fails the future completes exceptionally. Always handle it:
api.top("nodebuff", 10)
.thenAccept(rows -> rows.forEach(r -> plugin.getLogger().info(r.rank() + ". " + r.name() + " " + r.elo())))
.exceptionally(error -> {
plugin.getLogger().warning("Could not read the leaderboard: " + error.getMessage());
return null;
});Snapshot types
All are immutable records.
| Record | Fields |
|---|---|
QueueInfo | kit(), ranked(), teamSize() (1 or 2) |
QueueCount | kit(), ranked(), teamSize(), waiting() |
PartyInfo | leader(), members(), open(), size() |
MatchInfo | id(), kit(), ranked(), sides() (a list of UUID lists), phase(), type(), players() |
PlayerStats | uuid(), name(), streak(), bestStreak(), kits() |
KitStatsInfo | kit(), elo(), wins(), losses(), streak(), bestStreak(), unrankedWins(), unrankedLosses(), games() |
LeaderboardRow | rank(), uuid(), name(), elo(), wins(), losses() |
MatchHistoryEntry | id(), endedAt(), kit(), ranked(), durationSeconds(), reason(), winnerSide(), scores(), players() |
MatchHistoryEntry.Participant | uuid(), name(), side(), outcome() (WIN, LOSS, DRAW, NONE), eloAfter(), eloChange() |
ELO, wins and losses are ranked. Unranked games are counted in unrankedWins and unrankedLosses. winnerSide is -1 for a draw.
Examples
Show every kit the player has played when they run a command:
api.stats(player.getUniqueId()).thenAccept(optional -> {
PlayerStats stats = optional.orElse(null);
if (stats == null) return;
for (KitStatsInfo kit : stats.kits()) {
plugin.getLogger().info(stats.name() + " " + kit.kit() + " " + kit.elo() + " ELO " + kit.wins() + "W " + kit.losses() + "L");
}
});Look up an offline player by name:
api.statsByName("Notch").thenAccept(found -> plugin.getLogger().info(
found.map(s -> s.name() + " has played " + s.kits().size() + " kits").orElse("Notch is not known")));A scoreboard line with the player's rank in a kit's top 100:
api.top("nodebuff", 100).thenAccept(rows -> {
UUID id = player.getUniqueId();
String text = rows.stream().filter(r -> r.uuid().equals(id)).findFirst()
.map(r -> "#" + r.rank() + " in NoDebuff").orElse("Not in the top 100");
Bukkit.getScheduler().runTask(plugin, () -> player.sendActionBar(Component.text(text)));
});The last three matches of a player:
api.history(player.getUniqueId(), 0, 3).thenAccept(list -> {
for (MatchHistoryEntry m : list) {
var me = m.players().stream().filter(p -> p.uuid().equals(player.getUniqueId())).findFirst().orElse(null);
if (me != null) plugin.getLogger().info(m.kit() + ": " + me.outcome() + " (" + me.eloChange() + ")");
}
});Count players waiting to play across this server:
int waiting = api.queues().stream().mapToInt(QueueCount::waiting).sum();
int fighting = api.runningMatches().stream().mapToInt(m -> m.players().size()).sum();Hold a restart while matches run:
if (api.draining() && api.runningMatches().isEmpty()) {
// safe to stop this server
}All methods are safe from any thread and return immutable snapshots.