Skip to content

PlayerLeaveGameEvent

The PlayerLeaveGameEvent is an informational event called immediately before a player is removed from an active game session. Since the event is triggered before the actual leave cleanup, the player’s game state, scores, and arena data are still available when this event is called.


  • Package: dev.despical.tntrun.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 the configured leave item.
KICKAn administrator kicked the player from the arena.
DISCONNECTThe player left the server entirely.

When this event is called:

  • The player is still registered in the game.
  • Inventory restoration and visibility cleanup have not been performed yet.
  • You can still access the player’s final in-game state for logging or integrations.

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

import dev.despical.tntrun.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 TNT Run. Reason: " + reason);
if (event.getReason() == PlayerLeaveGameEvent.LeaveReason.DISCONNECT) {
// Custom disconnect handling
}
}
}