Class PlayerLeaveGameEvent

java.lang.Object
org.bukkit.event.Event
dev.itsharshxd.zentrix.api.events.ZentrixEvent
dev.itsharshxd.zentrix.api.events.ZentrixGameEvent
dev.itsharshxd.zentrix.api.events.player.PlayerLeaveGameEvent

public class PlayerLeaveGameEvent extends ZentrixGameEvent
Called when a player leaves a Zentrix game.

This event is fired after a player has left the game, either by:

  • Using the leave command
  • Disconnecting from the server
  • Being kicked
  • Being eliminated (death)

This event is NOT cancellable - the player has already left.

Example Usage


 @EventHandler
 public void onPlayerLeaveGame(PlayerLeaveGameEvent event) {
     ZentrixPlayer player = event.getPlayer();
     ZentrixGame game = event.getGame();
     LeaveReason reason = event.getReason();

     switch (reason) {
         case DEATH -> getLogger().info(player.getName() + " was eliminated");
         case QUIT -> getLogger().info(player.getName() + " disconnected");
         case COMMAND -> getLogger().info(player.getName() + " left voluntarily");
         case KICK -> getLogger().info(player.getName() + " was kicked");
     }

     // Check remaining players
     int remaining = event.getRemainingPlayers();
     game.broadcast("&7" + remaining + " players remain!");

     // Check if this triggers a win condition
     if (event.couldTriggerWin()) {
         getLogger().info("This leave may end the game!");
     }
 }
 
Since:
1.0.0
See Also:
  • Constructor Details

    • PlayerLeaveGameEvent

      public PlayerLeaveGameEvent(@NotNull @NotNull ZentrixGame game, @NotNull @NotNull ZentrixPlayer player, @Nullable @Nullable ZentrixTeam team, @NotNull @NotNull PlayerLeaveGameEvent.LeaveReason reason, int remainingPlayers, int remainingTeams, int playerKills, long survivalTime)
      Constructs a new PlayerLeaveGameEvent.
      Parameters:
      game - The game the player is leaving
      player - The player who is leaving
      team - The player's team (may be null if not on a team)
      reason - The reason for leaving
      remainingPlayers - The number of players remaining after this leave
      remainingTeams - The number of teams remaining after this leave
      playerKills - The player's kill count when leaving
      survivalTime - The player's survival time in seconds
  • Method Details

    • getPlayer

      @NotNull public @NotNull ZentrixPlayer getPlayer()
      Gets the player who is leaving the game.
      Returns:
      The player (never null)
    • getPlayerName

      @NotNull public @NotNull String getPlayerName()
      Gets the player's name.

      Convenience method equivalent to getPlayer().getName().

      Returns:
      The player's name (never null)
    • getTeam

      @NotNull public @NotNull Optional<ZentrixTeam> getTeam()
      Gets the player's team at the time of leaving.

      Returns empty if the player was not assigned to a team.

      Returns:
      Optional containing the team, or empty if no team
    • getReason

      @NotNull public @NotNull PlayerLeaveGameEvent.LeaveReason getReason()
      Gets the reason the player left the game.
      Returns:
      The leave reason (never null)
    • wasVoluntary

      public boolean wasVoluntary()
      Checks if the player left voluntarily (by command).
      Returns:
      true if the player used a leave command
    • wasDeath

      public boolean wasDeath()
      Checks if the player left due to death/elimination.
      Returns:
      true if the player was eliminated
    • wasDisconnect

      public boolean wasDisconnect()
      Checks if the player left due to disconnecting.
      Returns:
      true if the player disconnected
    • wasKicked

      public boolean wasKicked()
      Checks if the player was kicked.
      Returns:
      true if the player was kicked
    • getRemainingPlayers

      public int getRemainingPlayers()
      Gets the number of players remaining after this leave.
      Returns:
      Remaining player count
    • getRemainingTeams

      public int getRemainingTeams()
      Gets the number of teams remaining after this leave.
      Returns:
      Remaining team count
    • getPlayerKills

      public int getPlayerKills()
      Gets the player's kill count at the time of leaving.
      Returns:
      The player's kills in this game
    • getSurvivalTime

      public long getSurvivalTime()
      Gets the player's survival time in seconds.

      Measured from game start (PLAYING state) until leaving.

      Returns:
      Survival time in seconds
    • couldTriggerWin

      public boolean couldTriggerWin()
      Checks if this leave could trigger a win condition.

      Returns true if only one team/player remains after this leave.

      Returns:
      true if this leave may end the game
    • hadKills

      public boolean hadKills()
      Checks if the player had any kills before leaving.
      Returns:
      true if the player got at least one kill
    • getHandlers

      @NotNull public @NotNull org.bukkit.event.HandlerList getHandlers()
      Gets the handler list for this event.
      Overrides:
      getHandlers in class ZentrixGameEvent
      Returns:
      The handler list
    • getHandlerList

      @NotNull public static @NotNull org.bukkit.event.HandlerList getHandlerList()
      Gets the static handler list for this event type.
      Returns:
      The handler list