zRivals Duels logozRivals Duels

Developer API

The Bukkit events zRivals Duels fires and the small read API other plugins can use.

Other plugins can follow duels without touching zRivals Duels internals. There are three Bukkit events, all in cc.arrowtan.zrivalsduels.api.event, and a read API for MMR, rank and whether a player is in a duel. Everything is called on the main server thread.

SeasonForge uses these events on its own from 1.0.0-6. The /battlepass hook zrivals ... lines you may have added to duel.win-commands and duel.loss-commands can be removed.

Events

DuelStartEvent

Fired when the countdown is over and the fight begins.

MethodReturns
getDuelId()The duel id, a random UUID as a string, the same one the end event carries
getPlayers()List<Player>, the two fighters
getKitId()The kit file name
getArenaId()The arena name, or fight-here for a Fight here duel
isRanked()true for a ranked duel

A duel that is cancelled before the countdown ends, for example because a player left during setup or moved too far apart for Fight here, fires no events at all.

DuelEndEvent

Fired when any duel that reached the countdown ends, for every reason, a server stop included.

MethodReturns
getDuelId()The duel id
getWinner()UUID of the winner. null for TIME_LIMIT, ADMIN and SHUTDOWN
getPlayers()List<UUID>, both players. They may be offline by now
getKitId()The kit file name
getArenaId()The arena name, or fight-here
isRanked()true for a ranked duel
getEndReason()One of the reasons below, as a string
End reasonWhen
DEATHA player died
DISCONNECTA player left the server during the countdown or fight
LEFT_BOUNDSA player left the boundaries with boundary-action: FORFEIT
FORFEITA player used /duel forfeit
TIME_LIMITduel.max-duration-seconds ran out
ADMINStaff ended it with /duel admin end
SHUTDOWNThe server or the plugin stopped during the duel

MmrChangeEvent

Fired for each player whose MMR changed after a ranked duel, before the DuelEndEvent of that duel. The new value is already saved, so reading it back through the API gives the new MMR.

MethodReturns
getPlayerId()UUID of the player
getOldMmr(), getNewMmr()MMR before and after the duel
getOldRankId(), getNewRankId()Rank ids as written in ranks.yml, not the display names

Unranked duels and ranked duels with no winner change no MMR, so they fire no MmrChangeEvent.

Read API

if (ZRivalsAPI.isAvailable()) {
    ZRivalsAPI api = ZRivalsAPI.get();
    int mmr = api.mmr(uuid);
    String rank = api.rankId(uuid);
    boolean busy = api.isInDuel(uuid);
}
MethodReturns
ZRivalsAPI.isAvailable()true while zRivals Duels is enabled
ZRivalsAPI.get()The API. Throws IllegalStateException when zRivals Duels is not enabled
mmr(UUID)The player's current MMR
rankId(UUID)The id of the rank that MMR falls in, from ranks.yml
isInDuel(UUID)true from the start of a duel until the player is restored

ZRivalsAPI is in cc.arrowtan.zrivalsduels.api. Values come from the cache of online players, so ask about players who are online. For an offline player mmr returns the starting MMR.

Example

Add zRivals Duels as a soft dependency so it loads first when it is installed:

softdepend: [zRivalsDuels]

Then listen to the events like any other Bukkit event:

import cc.arrowtan.zrivalsduels.api.event.DuelEndEvent;
import cc.arrowtan.zrivalsduels.api.event.MmrChangeEvent;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

public final class DuelListener implements Listener {

    @EventHandler
    public void onDuelEnd(DuelEndEvent event) {
        if (event.getWinner() == null) {
            return;
        }
        String winner = Bukkit.getOfflinePlayer(event.getWinner()).getName();
        Bukkit.getLogger().info(winner + " won a " + event.getKitId() + " duel in " + event.getArenaId()
                + " (" + event.getEndReason() + ")");
    }

    @EventHandler
    public void onMmrChange(MmrChangeEvent event) {
        if (!event.getOldRankId().equals(event.getNewRankId())) {
            Bukkit.getLogger().info(event.getPlayerId() + " is now " + event.getNewRankId());
        }
    }
}

Register it in onEnable only when zRivals Duels is there, so your plugin still loads without it:

if (getServer().getPluginManager().isPluginEnabled("zRivalsDuels")) {
    getServer().getPluginManager().registerEvents(new DuelListener(), this);
}

The API is not on a public Maven repository. Compile against the zRivals Duels jar as a provided dependency, and ask in the Discord if you need help.

On this page