Skip to content

PlayerLeaveGameEvent

The PlayerLeaveGameEvent is an informational event called exactly one step before a player is removed from an active game session. Since the event is triggered before the actual leave logic, the player’s game state, scores, and round data are still fully intact when this event is called.


  • Package: io.greenmc.santasays.api.event.player
  • Parent Class: PlayerEvent
  • Cancellable: No

This event inherits getPlayer() and getUser() from PlayerEvent.

MethodReturn TypeDescription
getGame()GameReturns the game instance the player is leaving.
getReason()LeaveReasonReturns the specific cause of the departure.

The LeaveReason enum provides context on why the player is exiting the game:

ReasonDescription
LEAVE_COMMANDThe player manually typed a command to leave.
LEAVE_ITEMThe player interacted with a specific “Leave” item in their inventory.
DISCONNECTThe player left the server entirely.

When this event is called:

  • The player is still registered in the game.
  • No inventory restoration or visibility cleanup has been performed yet.
  • You can still access the player’s final scores or round progress for logging or rewards.

This example shows how to log players who leave during an active game for administrative tracking.

import io.greenmc.santasays.api.event.player.PlayerLeaveGameEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class LeaveLogger implements Listener {
@EventHandler
public void onLeave(PlayerLeaveGameEvent event) {
String name = event.getPlayer().getName();
String reason = event.getReason().name();
System.out.println("Player " + name + " is leaving the game. Reason: " + reason);
// Example: Reward players if they didn't leave via disconnect
if (event.getReason() != PlayerLeaveGameEvent.LeaveReason.DISCONNECT) {
// custom logic here
}
}
}