PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
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
56 protected array $disconnectReasons = [];
58 protected array $disconnectScreenMessages = [];
59
60 public function __construct(
61 private PlayerInfo $playerInfo,
62 private string $ip,
63 private int $port,
64 protected bool $authRequired
65 ){}
66
72 public function getPlayerInfo() : PlayerInfo{
73 return $this->playerInfo;
74 }
75
76 public function getIp() : string{
77 return $this->ip;
78 }
79
80 public function getPort() : int{
81 return $this->port;
82 }
83
84 public function isAuthRequired() : bool{
85 return $this->authRequired;
86 }
87
88 public function setAuthRequired(bool $v) : void{
89 $this->authRequired = $v;
90 }
91
97 public function getKickFlags() : array{
98 return array_keys($this->disconnectReasons);
99 }
100
104 public function isKickFlagSet(int $flag) : bool{
105 return isset($this->disconnectReasons[$flag]);
106 }
107
115 public function setKickFlag(int $flag, Translatable|string $disconnectReason, Translatable|string|null $disconnectScreenMessage = null) : void{
116 $this->disconnectReasons[$flag] = $disconnectReason;
117 $this->disconnectScreenMessages[$flag] = $disconnectScreenMessage ?? $disconnectReason;
118 }
119
126 public function clearKickFlag(int $flag) : void{
127 unset($this->disconnectReasons[$flag], $this->disconnectScreenMessages[$flag]);
128 }
129
133 public function clearAllKickFlags() : void{
134 $this->disconnectReasons = [];
135 $this->disconnectScreenMessages = [];
136 }
137
141 public function isAllowed() : bool{
142 return count($this->disconnectReasons) === 0;
143 }
144
149 public function getDisconnectReason(int $flag) : Translatable|string|null{
150 return $this->disconnectReasons[$flag] ?? null;
151 }
152
157 public function getDisconnectScreenMessage(int $flag) : Translatable|string|null{
158 return $this->disconnectScreenMessages[$flag] ?? null;
159 }
160
168 public function getFinalDisconnectReason() : Translatable|string{
169 foreach(self::KICK_FLAG_PRIORITY as $p){
170 if(isset($this->disconnectReasons[$p])){
171 return $this->disconnectReasons[$p];
172 }
173 }
174
175 return "";
176 }
177
186 foreach(self::KICK_FLAG_PRIORITY as $p){
187 if(isset($this->disconnectScreenMessages[$p])){
188 return $this->disconnectScreenMessages[$p];
189 }
190 }
191
192 return "";
193 }
194}
setKickFlag(int $flag, Translatable|string $disconnectReason, Translatable|string|null $disconnectScreenMessage=null)