Documentation

PlayerPreLoginEvent extends Event
in package
implements Cancellable

Called when a player connects to the server, prior to authentication taking place.

Cancelling this event will cause the player to be disconnected with the kick message set.

This event should be used to decide if the player may continue to login to the server. Do things like checking bans, whitelisting, server-full etc here.

WARNING: Any information about the player CANNOT be trusted at this stage, because they are not authenticated and could be a hacker posing as another player.

Interfaces, Classes, Traits and Enums

Cancellable
This interface is implemented by an Event subclass if and only if it can be cancelled.

Table of Contents

KICK_REASON_BANNED  = 3
KICK_REASON_PLUGIN  = 0
KICK_REASON_PRIORITY  = [ self::KICK_REASON_PLUGIN, //Plugin reason should always take priority over anything else self::KICK_REASON_SERVER_FULL, self::KICK_REASON_SERVER_WHITELISTED, self::KICK_REASON_BANNED, ]
KICK_REASON_SERVER_FULL  = 1
KICK_REASON_SERVER_WHITELISTED  = 2
MAX_EVENT_CALL_DEPTH  = 50
$authRequired  : bool
$eventName  : string|null
$kickReasons  : array<string|int, string>
$eventCallDepth  : int
$ip  : string
$playerInfo  : PlayerInfo
$port  : int
__construct()  : mixed
call()  : void
Calls event handlers registered for this event.
clearAllKickReasons()  : void
Clears all pre-assigned kick reasons, allowing the player to continue logging in.
clearKickReason()  : void
Clears a specific kick flag if it was set. This allows fine-tuned kick reason removal without impacting other reasons (for example, a ban can be bypassed without accidentally allowing a player to join a full server).
getEventName()  : string
getFinalKickMessage()  : string
Returns the final kick message which will be shown on the disconnect screen.
getIp()  : string
getKickMessage()  : string|null
Returns the kick message provided for the given kick flag, or null if not set.
getKickReasons()  : array<string|int, int>
Returns an array of kick reasons currently assigned.
getPlayerInfo()  : PlayerInfo
Returns an object containing self-proclaimed information about the connecting player.
getPort()  : int
isAllowed()  : bool
Returns whether the player is allowed to continue logging in.
isAuthRequired()  : bool
isCancelled()  : bool
Returns whether this instance of the event is currently cancelled.
isKickReasonSet()  : bool
Returns whether the given kick reason is set for this event.
setAuthRequired()  : void
setKickReason()  : void
Sets a reason to disallow the player to continue continue authenticating, with a message.

Constants

KICK_REASON_PRIORITY

public mixed KICK_REASON_PRIORITY = [ self::KICK_REASON_PLUGIN, //Plugin reason should always take priority over anything else self::KICK_REASON_SERVER_FULL, self::KICK_REASON_SERVER_WHITELISTED, self::KICK_REASON_BANNED, ]

MAX_EVENT_CALL_DEPTH

private mixed MAX_EVENT_CALL_DEPTH = 50

Properties

$eventName

protected string|null $eventName = null

$kickReasons

protected array<string|int, string> $kickReasons = []

reason const => associated message

$eventCallDepth

private static int $eventCallDepth = 1

Methods

__construct()

public __construct(PlayerInfo $playerInfo, string $ip, int $port, bool $authRequired) : mixed
Parameters
$playerInfo : PlayerInfo
$ip : string
$port : int
$authRequired : bool
Return values
mixed

call()

Calls event handlers registered for this event.

public call() : void
Tags
throws
RuntimeException

if event call recursion reaches the max depth limit

Return values
void

clearAllKickReasons()

Clears all pre-assigned kick reasons, allowing the player to continue logging in.

public clearAllKickReasons() : void
Return values
void

clearKickReason()

Clears a specific kick flag if it was set. This allows fine-tuned kick reason removal without impacting other reasons (for example, a ban can be bypassed without accidentally allowing a player to join a full server).

public clearKickReason(int $flag) : void
Parameters
$flag : int

Specific flag to clear.

Return values
void

getEventName()

public final getEventName() : string
Return values
string

getFinalKickMessage()

Returns the final kick message which will be shown on the disconnect screen.

public getFinalKickMessage() : string

Note: Only one message (the highest priority one) will be shown. See priority order to decide how to set your messages.

Tags
see
PlayerPreLoginEvent::KICK_REASON_PRIORITY
Return values
string

getKickMessage()

Returns the kick message provided for the given kick flag, or null if not set.

public getKickMessage(int $flag) : string|null
Parameters
$flag : int
Return values
string|null

getKickReasons()

Returns an array of kick reasons currently assigned.

public getKickReasons() : array<string|int, int>
Return values
array<string|int, int>

getPlayerInfo()

Returns an object containing self-proclaimed information about the connecting player.

public getPlayerInfo() : PlayerInfo

WARNING: THE PLAYER IS NOT VERIFIED DURING THIS EVENT. At this point, it's unknown if the player is real or a hacker.

Return values
PlayerInfo

isAllowed()

Returns whether the player is allowed to continue logging in.

public isAllowed() : bool
Return values
bool

isCancelled()

Returns whether this instance of the event is currently cancelled.

public isCancelled() : bool

If it is cancelled, only downstream handlers that declare @handleCancelled will be called with this event.

Return values
bool

isKickReasonSet()

Returns whether the given kick reason is set for this event.

public isKickReasonSet(int $flag) : bool
Parameters
$flag : int
Return values
bool

setAuthRequired()

public setAuthRequired(bool $v) : void
Parameters
$v : bool
Return values
void

setKickReason()

Sets a reason to disallow the player to continue continue authenticating, with a message.

public setKickReason(int $flag, string $message) : void

This can also be used to change kick messages for already-set flags.

Parameters
$flag : int
$message : string
Return values
void

Search results