Skip to Content
MineDuels

Events

Every MineDuels Bukkit event: when it fires, its fields, and whether you can cancel it.

All events are in dev.mineduels.api.event and extend MineDuelsEvent. Register them like any Bukkit event:

@EventHandler
public void onMatchStart(MatchStartEvent event) {
    MatchInfo match = event.match();
    getLogger().info("Match " + match.id() + " started: " + match.kit() + ", " + match.players().size() + " players");
}
EventFires whenCancellable
MatchStartEventA match is created, before the countdownNo
MatchEndEventA match ends, after the result is recordedNo
QueueJoinEventA player is about to join a queueYes
QueueLeaveEventA player left a queue without a matchNo
DuelRequestEventA duel request is about to be sentYes
PartyCreateEventA party was createdNo
PartyJoinEventA player joined a partyNo
PartyLeaveEventA member left a party that goes onNo
PartyDisbandEventA party was disbandedNo

Threads

MineDuels events are fired on the thread that caused them. On Paper that is the main thread. On Folia it is a region or player thread, so event.isAsynchronous() can be true. Do not assume the main thread. Change players and worlds through their schedulers. See Threads and Folia.

Do not do slow work (database, HTTP, file) in a handler. Hand it to your own executor.

MatchStartEvent

A match was created: its players are registered and about to be moved into the arena, before the countdown. Fired once per match. Every started match later fires one MatchEndEvent.

MethodReturns
match()MatchInfo snapshot: id, kit, ranked flag, sides, phase, type
@EventHandler
public void onStart(MatchStartEvent event) {
    MatchInfo m = event.match();
    for (UUID id : m.players()) {
        Player p = Bukkit.getPlayer(id);
        if (p != null) p.getScheduler().run(plugin, t -> p.sendMessage("Good luck in " + m.kit() + "!"), null);
    }
}

players() of MatchInfo lists every player of every side. type() is one of DUEL, QUEUE, PARTY_SPLIT, PARTY_FFA, PARTY_TEAMS, PARTY_DUEL, RED_ROVER, TOURNAMENT.

MatchEndEvent

A match ended, right after its result was recorded and before the players return to the lobby. Fired once per match, also for a draw, an aborted start and a server shutdown.

MethodReturns
match()The MatchInfo as it ended
matchId(), kit(), ranked()Shortcuts to the match fields
winners()The winning side's players who did not leave. Empty for a draw
losers()Players the result counts as losers. Empty for a draw. A player whose leave did not count is in neither list
draw()true when winners() is empty
reason()MatchEndReason
eloChanges()Map<UUID, Integer> of the signed change for each winner and loser in a ranked match. Empty otherwise

MatchEndReason:

ValueMeaning
SCOREA side won on score
FORFEITThe other sides forfeited
QUITThe other sides quit
TIME_LIMITThe time limit ran out. A draw
ABORTEDA player never arrived or the match could not start
SHUTDOWNThe server shut down

Only SCORE, FORFEIT and QUIT with a winner record stats.

@EventHandler
public void onEnd(MatchEndEvent event) {
    if (event.draw() || !event.ranked()) return;
    event.eloChanges().forEach((id, change) -> {
        if (change >= 20) getLogger().info(id + " gained " + change + " ELO in match " + event.matchId());
    });
}

A rewards plugin:

@EventHandler
public void onEnd(MatchEndEvent event) {
    if (event.reason() != MatchEndReason.SCORE) return;
    for (UUID winner : event.winners()) {
        economy.deposit(winner, event.ranked() ? 50 : 10);
    }
}

QueueJoinEvent

A player is about to join a queue. MineDuels' checks passed, except that a player who is queued already is still refused afterwards. Cancel it to keep everyone out of the queue. Tell the player why yourself.

MethodReturns
player()The player who joins. For a pre-made team, the leader
players()Everyone who joins: the player, and their partner for a pre-made team
kit()The kit name
ranked()Whether it is a ranked queue
teamSize()Players per side: 1 for 1v1, 2 for 2v2
@EventHandler
public void onQueue(QueueJoinEvent event) {
    if (event.ranked() && !event.player().hasPermission("myplugin.ranked")) {
        event.setCancelled(true);
        event.player().sendMessage(Component.text("Ranked needs the Verified rank.", NamedTextColor.RED));
    }
}

Close a kit for maintenance:

private static final Set<String> CLOSED = Set.of("bridge");

@EventHandler
public void onQueue(QueueJoinEvent event) {
    if (CLOSED.contains(event.kit())) {
        event.setCancelled(true);
        event.player().sendMessage(Component.text("This kit is closed right now."));
    }
}

QueueLeaveEvent

A player left a queue without a match. Each player of a pre-made team gets their own event. A match being found fires MatchStartEvent instead.

MethodReturns
player()The player's UUID. They may be offline
kit(), ranked(), teamSize()The queue
reason()LEFT or CLOSED

LEFT means /leave, the lobby item, a quit, or a change of the pre-made team's party. CLOSED means the queue closed: its kit was deleted or is no longer ranked, or no arena can host it.

DuelRequestEvent

A duel request is about to be sent, after MineDuels' own checks passed. Cancel it to send nothing. The sender's request cooldown still applies. Tell the sender why.

MethodReturns
sender(), target()The two players. For a party request, the party leaders
kit()The kit name
arena()The arena template, or null for any arena that can host the kit
rounds()The score to win (rounds, or points in bridge kits)
party()true when it is a request between two party leaders
@EventHandler
public void onDuel(DuelRequestEvent event) {
    if (event.rounds() > 5 && !event.sender().hasPermission("myplugin.longduels")) {
        event.setCancelled(true);
        event.sender().sendMessage(Component.text("Duels are limited to 5 rounds."));
    }
}

Party events

All are fired after the fact and cannot be cancelled. Each carries a PartyInfo snapshot (leader(), members(), open(), size()).

EventExtra methodsNote
PartyCreateEventparty()The new party, with just its leader
PartyJoinEventparty(), player()A player joined by an accepted invite or /party join of an open party. party() includes them
PartyLeaveEventparty(), player(), kicked()A member left, quit or was kicked. party() is without them. A leaving leader hands the lead to the next member. A leave that disbands the party fires PartyDisbandEvent instead
PartyDisbandEventparty()By the leader, or because the last member or the leader left. party() is as it was just before
@EventHandler
public void onPartyJoin(PartyJoinEvent event) {
    Player leader = Bukkit.getPlayer(event.party().leader());
    if (leader != null) {
        leader.sendMessage(Component.text("A player joined your party (" + event.party().size() + " members)."));
    }
}

Listener order and priority

Use the normal Bukkit priorities. To cancel an event, use EventPriority.NORMAL or lower and ignoreCancelled = true if you only want to react to events that other plugins left alone:

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onQueue(QueueJoinEvent event) { /* ... */ }

Events across servers

An event fires on the server that ran the code. A QueueJoinEvent fires on the server where the player used the queue, and a MatchStartEvent and MatchEndEvent fire on the server that creates and ends the match. Servers do not forward these events to each other. If you need a network-wide view, use the web API, which reads the shared database.

On this page