Class PlayerJoinGameEvent

java.lang.Object
org.bukkit.event.Event
All Implemented Interfaces:
org.bukkit.event.Cancellable

public class PlayerJoinGameEvent extends ZentrixGameEvent implements org.bukkit.event.Cancellable
Called when a player attempts to join a Zentrix game.

This event is fired before the player is added to the game, allowing addons to prevent the join or perform setup tasks. At this point:

  • The player has requested to join (via command, GUI, etc.)
  • Basic validation has passed (player not already in a game)
  • The game has space for the player

This event is cancellable. Cancelling prevents the player from joining.

Example Usage


 @EventHandler
 public void onPlayerJoinGame(PlayerJoinGameEvent event) {
     Player player = event.getPlayer();
     ZentrixGame game = event.getGame();

     // Check custom permission
     if (!player.hasPermission("myaddon.play")) {
         event.setCancelled(true);
         event.setCancelReason("You don't have permission to play!");
         return;
     }

     // Log the join
     getLogger().info(player.getName() + " is joining game in " + event.getArenaName());

     // Check if joining as spectator
     if (event.isSpectator()) {
         player.sendMessage("You're joining as a spectator!");
     }
 }
 
Since:
1.0.0
See Also:
  • Constructor Details

    • PlayerJoinGameEvent

      public PlayerJoinGameEvent(@NotNull @NotNull ZentrixGame game, @NotNull @NotNull org.bukkit.entity.Player player, boolean spectator)
      Constructs a new PlayerJoinGameEvent.
      Parameters:
      game - The game the player is joining
      player - The player attempting to join
      spectator - Whether the player is joining as a spectator
  • Method Details

    • getPlayer

      @NotNull public @NotNull org.bukkit.entity.Player getPlayer()
      Gets the player attempting to join the game.
      Returns:
      The player (never null)
    • isSpectator

      public boolean isSpectator()
      Checks if the player is joining as a spectator.

      Spectators are players who join to watch an ongoing game rather than participate as active players.

      Returns:
      true if joining as spectator
    • isActivePlayer

      public boolean isActivePlayer()
      Checks if the player is joining as an active participant.

      Active participants are players who will be part of the game and can be eliminated.

      Returns:
      true if joining as an active player (not spectator)
    • getCancelReason

      @Nullable public @Nullable String getCancelReason()
      Gets the reason the join was cancelled, if any.

      This message can be shown to the player to explain why they couldn't join.

      Returns:
      The cancel reason, or null if not cancelled or no reason set
    • setCancelReason

      public void setCancelReason(@Nullable @Nullable String reason)
      Sets the reason for cancelling the join.

      This message will be shown to the player when they are prevented from joining.

      Parameters:
      reason - The reason message (can be null)
    • cancel

      public void cancel(@NotNull @NotNull String reason)
      Cancels the event with a reason.

      Convenience method that sets both cancelled state and reason.

      Parameters:
      reason - The reason for cancelling
    • getPlayerName

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

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

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

      public int getCurrentPlayerCount()
      Gets the number of players currently in the game.

      This is the count before this player joins.

      Returns:
      Current player count
    • getPlayerCountAfterJoin

      public int getPlayerCountAfterJoin()
      Gets the number of players after this player joins.

      Returns the current count + 1 if joining as active player, or the current count if joining as spectator.

      Returns:
      Player count after join
    • willBeFull

      public boolean willBeFull()
      Checks if the game will be full after this player joins.
      Returns:
      true if the game will reach max capacity
    • isCancelled

      public boolean isCancelled()
      Specified by:
      isCancelled in interface org.bukkit.event.Cancellable
    • setCancelled

      public void setCancelled(boolean cancel)
      Specified by:
      setCancelled in interface org.bukkit.event.Cancellable
    • 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