Class PlayerJoinGameEvent
- All Implemented Interfaces:
org.bukkit.event.Cancellable
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.bukkit.event.Event
org.bukkit.event.Event.Result -
Constructor Summary
ConstructorsConstructorDescriptionPlayerJoinGameEvent(@NotNull ZentrixGame game, @NotNull org.bukkit.entity.Player player, boolean spectator) Constructs a new PlayerJoinGameEvent. -
Method Summary
Modifier and TypeMethodDescriptionvoidCancels the event with a reason.@Nullable StringGets the reason the join was cancelled, if any.intGets the number of players currently in the game.static @NotNull org.bukkit.event.HandlerListGets the static handler list for this event type.@NotNull org.bukkit.event.HandlerListGets the handler list for this event.@NotNull org.bukkit.entity.PlayerGets the player attempting to join the game.intGets the number of players after this player joins.@NotNull StringGets the player's name.booleanChecks if the player is joining as an active participant.booleanbooleanChecks if the player is joining as a spectator.voidsetCancelled(boolean cancel) voidsetCancelReason(@Nullable String reason) Sets the reason for cancelling the join.booleanChecks if the game will be full after this player joins.Methods inherited from class dev.itsharshxd.zentrix.api.events.ZentrixGameEvent
getArenaName, getGame, getGameId, getGameState, getGameTypeName, getPlayerCountMethods inherited from class org.bukkit.event.Event
callEvent, getEventName, isAsynchronous
-
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 joiningplayer- The player attempting to joinspectator- 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:
trueif 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:
trueif joining as an active player (not spectator)
-
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
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
Cancels the event with a reason.Convenience method that sets both cancelled state and reason.
- Parameters:
reason- The reason for cancelling
-
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:
trueif the game will reach max capacity
-
isCancelled
public boolean isCancelled()- Specified by:
isCancelledin interfaceorg.bukkit.event.Cancellable
-
setCancelled
public void setCancelled(boolean cancel) - Specified by:
setCancelledin interfaceorg.bukkit.event.Cancellable
-
getHandlers
@NotNull public @NotNull org.bukkit.event.HandlerList getHandlers()Gets the handler list for this event.- Overrides:
getHandlersin classZentrixGameEvent- 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
-