Skip to content

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.


  • Package: dev.despical.tntrun.api.event.player
  • Parent Class: PlayerEvent
  • Cancellable: Yes

Since this event extends PlayerEvent, you have access to getPlayer() and getUser() in addition to the following:

MethodReturn TypeDescription
getGame()GameReturns the game instance the player is attempting to join.
isSpectatorJoin()booleanReturns whether the player will join as a spectator.
isCancelled()booleanChecks if the join process has been blocked by another listener.
setCancelled(boolean)voidSet to true to prevent the player from joining the game.

  • 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.

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!");
}
}
}