Skip to Content
MineDuels

Developer overview

What other plugins can use: the Bukkit service, the events, and the web API.

MineDuels gives other plugins and external tools three ways to work with it.

WayUse it forPage
MineDuelsApi, a Bukkit serviceReading live match, queue and party state, and stored stats, leaderboards and history, from another pluginMineDuelsApi
Bukkit events in dev.mineduels.api.eventReacting to matches, queues, parties and duels, and cancelling queue joins and duel requestsEvents
The HTTP web APIDashboards, Discord bots, deploy scripts and anything outside the serverWeb API

The Java API is read-only. A plugin cannot start a match or change a player's ELO through it. The events can be cancelled where the page says so.

Quick start

  1. Add the API jar as a dependency.
  2. Declare depend: [MineDuels] (or softdepend) in your plugin.yml.
  3. Load the service when your plugin enables:
public final class MyPlugin extends JavaPlugin implements Listener {

    private MineDuelsApi duels;

    @Override
    public void onEnable() {
        duels = Bukkit.getServicesManager().load(MineDuelsApi.class);
        if (duels == null) {
            getLogger().warning("MineDuels is not running; the duel features are off.");
            return;
        }
        getServer().getPluginManager().registerEvents(this, this);
    }

    @EventHandler
    public void onMatchEnd(MatchEndEvent event) {
        getLogger().info("Match " + event.matchId() + " (" + event.kit() + ") ended: " + event.reason());
    }
}

load returns null when MineDuels is missing or disabled, so always check it. The service is registered while MineDuels is enabled and removed when it disables.

A small complete plugin

A plugin that tells a player their NoDebuff ELO and cancels ranked queue joins for players with a flag:

@EventHandler
public void onQueueJoin(QueueJoinEvent event) {
    if (event.ranked() && event.player().hasPermission("myplugin.noranked")) {
        event.setCancelled(true);
        event.player().sendMessage(Component.text("You may not play ranked.", NamedTextColor.RED));
    }
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!(sender instanceof Player player) || duels == null) return false;
    duels.elo(player.getUniqueId(), "nodebuff").ifPresentOrElse(
        elo -> player.sendMessage("Your NoDebuff ELO is " + elo),
        () -> player.sendMessage("Your profile is not loaded yet."));
    return true;
}

Where things run

  • The service methods are safe from any thread. See Threads and Folia.
  • Events fire on the thread that caused them, which on Folia is a region or player thread.
  • On a cross-server network the service describes the server your plugin runs on. For the whole network use the web API, which reads the shared database.

Versions

The API follows the plugin version, for example MineDuels-API-0.10.0.jar goes with MineDuels 0.10.0. New methods are added as default methods, so a plugin built against an older API jar keeps working. Changes that break callers are listed in the release notes.

Also see Build from source and Testing with bots.

On this page