PocketMine-MP 5.23.3 git-976fc63567edab7a6fb6aeae739f43cf9fe57de4
Loading...
Searching...
No Matches
PlayerPreLoginEvent.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
25
29use function array_keys;
30use function count;
31
43 public const KICK_FLAG_PLUGIN = 0;
44 public const KICK_FLAG_SERVER_FULL = 1;
45 public const KICK_FLAG_SERVER_WHITELISTED = 2;
46 public const KICK_FLAG_BANNED = 3;
47
48 public const KICK_FLAG_PRIORITY = [
49 self::KICK_FLAG_PLUGIN, //Plugin reason should always take priority over anything else
50 self::KICK_FLAG_SERVER_FULL,
51 self::KICK_FLAG_SERVER_WHITELISTED,
52 self::KICK_FLAG_BANNED
53 ];
54
59 protected array $disconnectReasons = [];
64 protected array $disconnectScreenMessages = [];
65
66 public function __construct(
67 private PlayerInfo $playerInfo,
68 private string $ip,
69 private int $port,
70 protected bool $authRequired
71 ){}
72
78 public function getPlayerInfo() : PlayerInfo{
79 return $this->playerInfo;
80 }
81
82 public function getIp() : string{
83 return $this->ip;
84 }
85
86 public function getPort() : int{
87 return $this->port;
88 }
89
90 public function isAuthRequired() : bool{
91 return $this->authRequired;
92 }
93
94 public function setAuthRequired(bool $v) : void{
95 $this->authRequired = $v;
96 }
97
104 public function getKickFlags() : array{
105 return array_keys($this->disconnectReasons);
106 }
107
111 public function isKickFlagSet(int $flag) : bool{
112 return isset($this->disconnectReasons[$flag]);
113 }
114
122 public function setKickFlag(int $flag, Translatable|string $disconnectReason, Translatable|string|null $disconnectScreenMessage = null) : void{
123 $this->disconnectReasons[$flag] = $disconnectReason;
124 $this->disconnectScreenMessages[$flag] = $disconnectScreenMessage ?? $disconnectReason;
125 }
126
133 public function clearKickFlag(int $flag) : void{
134 unset($this->disconnectReasons[$flag], $this->disconnectScreenMessages[$flag]);
135 }
136
140 public function clearAllKickFlags() : void{
141 $this->disconnectReasons = [];
142 $this->disconnectScreenMessages = [];
143 }
144
148 public function isAllowed() : bool{
149 return count($this->disconnectReasons) === 0;
150 }
151
156 public function getDisconnectReason(int $flag) : Translatable|string|null{
157 return $this->disconnectReasons[$flag] ?? null;
158 }
159
164 public function getDisconnectScreenMessage(int $flag) : Translatable|string|null{
165 return $this->disconnectScreenMessages[$flag] ?? null;
166 }
167
175 public function getFinalDisconnectReason() : Translatable|string{
176 foreach(self::KICK_FLAG_PRIORITY as $p){
177 if(isset($this->disconnectReasons[$p])){
178 return $this->disconnectReasons[$p];
179 }
180 }
181
182 return "";
183 }
184
193 foreach(self::KICK_FLAG_PRIORITY as $p){
194 if(isset($this->disconnectScreenMessages[$p])){
195 return $this->disconnectScreenMessages[$p];
196 }
197 }
198
199 return "";
200 }
201}
setKickFlag(int $flag, Translatable|string $disconnectReason, Translatable|string|null $disconnectScreenMessage=null)