Use typed properties in Server

This commit is contained in:
Dylan K. Taylor 2021-08-12 23:52:39 +01:00
parent e907c70160
commit 0e0bbdfb70
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -164,134 +164,93 @@ class Server{
public const BROADCAST_CHANNEL_ADMINISTRATIVE = "pocketmine.broadcast.admin"; public const BROADCAST_CHANNEL_ADMINISTRATIVE = "pocketmine.broadcast.admin";
public const BROADCAST_CHANNEL_USERS = "pocketmine.broadcast.user"; public const BROADCAST_CHANNEL_USERS = "pocketmine.broadcast.user";
/** @var Server|null */ private static ?Server $instance = null;
private static $instance = null;
/** @var SleeperHandler */ private SleeperHandler $tickSleeper;
private $tickSleeper;
/** @var BanList */ private BanList $banByName;
private $banByName;
/** @var BanList */ private BanList $banByIP;
private $banByIP;
/** @var Config */ private Config $operators;
private $operators;
/** @var Config */ private Config $whitelist;
private $whitelist;
/** @var bool */ private bool $isRunning = true;
private $isRunning = true;
/** @var bool */ private bool $hasStopped = false;
private $hasStopped = false;
/** @var PluginManager */ private PluginManager $pluginManager;
private $pluginManager;
/** @var float */ private float $profilingTickRate = 20;
private $profilingTickRate = 20;
/** @var AutoUpdater */ private AutoUpdater $updater;
private $updater;
/** @var AsyncPool */ private AsyncPool $asyncPool;
private $asyncPool;
/** /** Counts the ticks since the server start */
* Counts the ticks since the server start private int $tickCounter = 0;
* private float $nextTick = 0;
* @var int
*/
private $tickCounter = 0;
/** @var float */
private $nextTick = 0;
/** @var float[] */ /** @var float[] */
private $tickAverage = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]; private array $tickAverage = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20];
/** @var float[] */ /** @var float[] */
private $useAverage = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; private array $useAverage = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
/** @var float */ private float $currentTPS = 20;
private $currentTPS = 20; private float $currentUse = 0;
/** @var float */ private float $startTime;
private $currentUse = 0;
/** @var float */
private $startTime;
/** @var bool */ private bool $doTitleTick = true;
private $doTitleTick = true;
/** @var int */ private int $sendUsageTicker = 0;
private $sendUsageTicker = 0;
/** @var \AttachableThreadedLogger */ private \AttachableThreadedLogger $logger;
private $logger;
/** @var MemoryManager */ private MemoryManager $memoryManager;
private $memoryManager;
/** @var ConsoleReaderThread */ private ConsoleReaderThread $console;
private $console;
/** @var SimpleCommandMap */ private SimpleCommandMap $commandMap;
private $commandMap;
/** @var CraftingManager */ private CraftingManager $craftingManager;
private $craftingManager;
/** @var ResourcePackManager */ private ResourcePackManager $resourceManager;
private $resourceManager;
/** @var WorldManager */ private WorldManager $worldManager;
private $worldManager;
/** @var int */ private int $maxPlayers;
private $maxPlayers;
/** @var bool */ private bool $onlineMode = true;
private $onlineMode = true;
/** @var Network */ private Network $network;
private $network; private bool $networkCompressionAsync = true;
/** @var bool */
private $networkCompressionAsync = true;
/** @var Language */ private Language $language;
private $language; private bool $forceLanguage = false;
/** @var bool */
private $forceLanguage = false;
/** @var UuidInterface */ private UuidInterface $serverID;
private $serverID;
/** @var \DynamicClassLoader */ private \DynamicClassLoader $autoloader;
private $autoloader; private string $dataPath;
/** @var string */ private string $pluginPath;
private $dataPath;
/** @var string */
private $pluginPath;
/** /**
* @var string[] * @var string[]
* @phpstan-var array<string, string> * @phpstan-var array<string, string>
*/ */
private $uniquePlayers = []; private array $uniquePlayers = [];
/** @var QueryInfo */ private QueryInfo $queryInfo;
private $queryInfo;
/** @var ServerConfigGroup */ private ServerConfigGroup $configGroup;
private $configGroup;
/** @var Player[] */ /** @var Player[] */
private $playerList = []; private array $playerList = [];
/** /**
* @var CommandSender[][] * @var CommandSender[][]
* @phpstan-var array<string, array<int, CommandSender>> * @phpstan-var array<string, array<int, CommandSender>>
*/ */
private $broadcastSubscribers = []; private array $broadcastSubscribers = [];
public function getName() : string{ public function getName() : string{
return VersionInfo::NAME; return VersionInfo::NAME;
@ -1396,16 +1355,16 @@ class Server{
$this->shutdown(); $this->shutdown();
if($this->pluginManager instanceof PluginManager){ if(isset($this->pluginManager)){
$this->getLogger()->debug("Disabling all plugins"); $this->getLogger()->debug("Disabling all plugins");
$this->pluginManager->disablePlugins(); $this->pluginManager->disablePlugins();
} }
if($this->network instanceof Network){ if(isset($this->network)){
$this->network->getSessionManager()->close($this->configGroup->getPropertyString("settings.shutdown-message", "Server closed")); $this->network->getSessionManager()->close($this->configGroup->getPropertyString("settings.shutdown-message", "Server closed"));
} }
if($this->worldManager instanceof WorldManager){ if(isset($this->worldManager)){
$this->getLogger()->debug("Unloading all worlds"); $this->getLogger()->debug("Unloading all worlds");
foreach($this->worldManager->getWorlds() as $world){ foreach($this->worldManager->getWorlds() as $world){
$this->worldManager->unloadWorld($world, true); $this->worldManager->unloadWorld($world, true);
@ -1415,23 +1374,23 @@ class Server{
$this->getLogger()->debug("Removing event handlers"); $this->getLogger()->debug("Removing event handlers");
HandlerListManager::global()->unregisterAll(); HandlerListManager::global()->unregisterAll();
if($this->asyncPool instanceof AsyncPool){ if(isset($this->asyncPool)){
$this->getLogger()->debug("Shutting down async task worker pool"); $this->getLogger()->debug("Shutting down async task worker pool");
$this->asyncPool->shutdown(); $this->asyncPool->shutdown();
} }
if($this->configGroup !== null){ if(isset($this->configGroup)){
$this->getLogger()->debug("Saving properties"); $this->getLogger()->debug("Saving properties");
$this->configGroup->save(); $this->configGroup->save();
} }
if($this->console instanceof ConsoleReaderThread){ if(isset($this->console)){
$this->getLogger()->debug("Closing console"); $this->getLogger()->debug("Closing console");
$this->console->shutdown(); $this->console->shutdown();
$this->console->notify(); $this->console->notify();
} }
if($this->network instanceof Network){ if(isset($this->network)){
$this->getLogger()->debug("Stopping network interfaces"); $this->getLogger()->debug("Stopping network interfaces");
foreach($this->network->getInterfaces() as $interface){ foreach($this->network->getInterfaces() as $interface){
$this->getLogger()->debug("Stopping network interface " . get_class($interface)); $this->getLogger()->debug("Stopping network interface " . get_class($interface));