PlayerJoinAttemptEvent
The PlayerJoinAttemptEvent is triggered before a player is officially added to a game session. This is a critical lifecycle event for developers who want to implement custom entry requirements, spectator handling, party checks, or logging systems.
Technical Overview
Section titled “Technical Overview”- Package:
dev.despical.tntrun.api.event.player - Parent Class:
PlayerEvent - Cancellable: Yes
Methods
Section titled “Methods”Since this event extends PlayerEvent, you have access to getPlayer() and getUser() in addition to the following:
| Method | Return Type | Description |
|---|---|---|
getGame() | Game | Returns the game instance the player is attempting to join. |
isSpectatorJoin() | boolean | Returns whether the player will join as a spectator. |
isCancelled() | boolean | Checks if the join process has been blocked by another listener. |
setCancelled(boolean) | void | Set to true to prevent the player from joining the game. |
Common Use Cases
Section titled “Common Use Cases”- Permission Restrictions: Block players from joining specific arenas if they do not meet custom criteria.
- Party or Queue Systems: Only allow players to join when your external queue permits it.
- Spectator Rules: Treat spectator joins differently from normal active-player joins.
- Join Logging: Track how many players attempt to join specific arenas for analytics.
Example Usage
Section titled “Example Usage”The following example restricts normal player joins unless the player has a specific permission, while still allowing spectator joins.
import dev.despical.tntrun.api.event.player.PlayerJoinAttemptEvent;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;
public class JoinRestrictionListener implements Listener {
@EventHandler public void onJoin(PlayerJoinAttemptEvent event) { if (event.isSpectatorJoin()) { return; }
if (!event.getPlayer().hasPermission("tntrun.vip")) { event.setCancelled(true); event.getPlayer().sendMessage("This TNT Run arena is reserved for VIP members!"); } }}