# 📡 Events

## Events

Every event below lives under `com.phoenixplugins.phoenixduels.api.events` and is listened to like any other Bukkit event. See [Examples](examples.md) for working listeners.

> **Danger:**
The API is only available for the premium version of the plugin.

## Match Lifecycle

These fire in the order they are listed. Every one of them extends `MatchEvent` and exposes `getMatch()`.

<table data-full-width="true"><thead><tr><th width="250">Event</th><th width="110">Cancellable</th><th>Fired when</th></tr></thead><tbody><tr><td>MatchCreateEvent</td><td>Yes</td><td>A match object has been built but no players have been moved yet. Cancelling stops the match from ever running.</td></tr><tr><td>MatchPreStartEvent</td><td>Yes</td><td>Just before players are teleported in, while every start requirement is being checked. See the note below on cancelling with a reason.</td></tr><tr><td>MatchStartEvent</td><td>Yes</td><td>The match is about to begin.</td></tr><tr><td>MatchPhaseStartEvent</td><td>No</td><td>The match moves from one state to another. Exposes <code>getOldState()</code> and <code>getNewState()</code>.</td></tr><tr><td>MatchPreEndEvent</td><td>No</td><td>The match has been decided but has not been cleaned up yet, so match data is still readable.</td></tr><tr><td>MatchEndEvent</td><td>No</td><td>The match is over. <code>getConnectedPlayers()</code> returns everyone still online at that point.</td></tr></tbody></table>

`MatchPhaseStartEvent` reports one of six states: `NOT_STARTED`, `ROUND_START`, `ROUND_IN_PROGRESS`, `POST_ROUND`, `ROUND_END` and `FINISHED`.

> **Info:**
`MatchPreStartEvent` also has `setCancelledReason(String)`. Using it instead of `setCancelled(true)` cancels the match **and** shows your own message to the players, which is how the CombatLogX hook explains that someone is in combat.

## Players in a Match

These extend `MatchPlayerEvent`, so they expose both `getMatch()` and `getPlayer()`. None of them are cancellable.

<table data-full-width="true"><thead><tr><th width="270">Event</th><th>Fired when</th></tr></thead><tbody><tr><td>MatchPlayerKillEvent</td><td>A player kills someone. <code>getVictim()</code> returns who died.</td></tr><tr><td>MatchPlayerDeathEvent</td><td>A player dies. <code>getKiller()</code> may be null. <code>setDeathMessage(String[])</code> replaces the broadcast with your own text.</td></tr><tr><td>MatchPlayerLeaveEvent</td><td>A player leaves the match. <code>isGuest()</code> tells you whether they were a spectator rather than a participant.</td></tr><tr><td>MatchSpectatorJoinEvent</td><td>Someone starts spectating the match.</td></tr><tr><td>MatchSpectatorLeaveEvent</td><td>Someone stops spectating the match.</td></tr></tbody></table>

## Elo

<table data-full-width="true"><thead><tr><th width="290">Event</th><th>Fired when</th></tr></thead><tbody><tr><td>MatchPlayerChangeEloEvent</td><td>A match changes a player's rating in one mode. Exposes <code>getPlayer()</code>, <code>getOldElo()</code>, <code>getNewElo()</code> and <code>getMatch()</code>.</td></tr><tr><td>PlayerGlobalEloChangeEvent</td><td>A player's <a href="../features/elo.md">global elo</a> changes, including through the admin commands. Exposes <code>getPlayer()</code>, <code>getOldElo()</code> and <code>getNewElo()</code>.</td></tr></tbody></table>

Both give you an `OfflinePlayer`, because a rating can change while the player is not connected.

## Queue

<table data-full-width="true"><thead><tr><th width="290">Event</th><th>Fired when</th></tr></thead><tbody><tr><td>ProfileQueueStartEvent</td><td>A player or party enters the matchmaking queue.</td></tr><tr><td>ProfileQueueStopEvent</td><td>A player or party leaves it, whether by finding a match or by cancelling.</td></tr></tbody></table>

Both expose `getProfile()` for what was queued for, and `getParticipants()` for who queued. Neither is cancellable.

## Party

These extend `PartyEvent` and expose `getParty()`. None of them are cancellable.

<table data-full-width="true"><thead><tr><th width="310">Event</th><th>Fired when</th></tr></thead><tbody><tr><td>PartyCreatedEvent</td><td>A party is created.</td></tr><tr><td>PartyDisbandEvent</td><td>A party is disbanded. Carries the list of participants it had.</td></tr><tr><td>PartyParticipantAddedEvent</td><td>A participant joins the party. Exposes <code>getParticipant()</code>.</td></tr><tr><td>PartyParticipantAcceptedEvent</td><td>A participant accepts their invitation. Exposes <code>getParticipant()</code>.</td></tr><tr><td>PartyParticipantRemovedEvent</td><td>A participant leaves or is kicked. Exposes <code>getParticipant()</code>.</td></tr><tr><td>PartyLeaderChangedEvent</td><td>Leadership passes to someone else. Exposes <code>getOldLeaderUniqueId()</code> and <code>getNewLeaderUniqueId()</code>.</td></tr></tbody></table>

## Add-ons

<table data-full-width="true"><thead><tr><th width="250">Event</th><th>Fired when</th></tr></thead><tbody><tr><td>RematchWindowEvent</td><td>A rematch window opens for a player at the end of a match. Exposes <code>getPlayer()</code> and <code>getDurationSeconds()</code>. Requires the <a href="../add-ons/rematch-requeue/README.md">Rematch &#x26; Requeue</a> add-on.</td></tr></tbody></table>

## Cancellable events

Only three events can be cancelled, and all three cancel a match before it runs: MatchCreateEvent, MatchPreStartEvent and MatchStartEvent.

There is deliberately no way to cancel a kill, a death, or a player leaving. If you need to stop something during a fight, write a [custom rule](README.md#custom-addons) instead.

Source: https://www.phoenixplugins.com/docs/phoenix-duels/api/events