Player: make use of typed properties

readability significantly benefits from use of typed properties here.
This commit is contained in:
Dylan K. Taylor
2021-08-03 15:02:32 +01:00
parent 8221475ce2
commit dcd203370b

View File

@ -157,113 +157,77 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
return $lname !== "rcon" and $lname !== "console" and $len >= 1 and $len <= 16 and preg_match("/[^A-Za-z0-9_ ]/", $name) === 0; return $lname !== "rcon" and $lname !== "console" and $len >= 1 and $len <= 16 and preg_match("/[^A-Za-z0-9_ ]/", $name) === 0;
} }
/** @var NetworkSession|null */ protected ?NetworkSession $networkSession;
protected $networkSession;
/** @var bool */ public bool $spawned = false;
public $spawned = false;
/** @var string */ protected string $username;
protected $username; protected string $displayName;
/** @var string */ protected string $xuid = "";
protected $displayName; protected bool $authenticated;
/** @var string */ protected PlayerInfo $playerInfo;
protected $xuid = "";
/** @var bool */
protected $authenticated;
/** @var PlayerInfo */
protected $playerInfo;
/** @var Inventory|null */ protected ?Inventory $currentWindow = null;
protected $currentWindow = null;
/** @var Inventory[] */ /** @var Inventory[] */
protected $permanentWindows = []; protected array $permanentWindows = [];
/** @var PlayerCursorInventory */ protected PlayerCursorInventory $cursorInventory;
protected $cursorInventory; protected CraftingGrid $craftingGrid;
/** @var CraftingGrid */
protected $craftingGrid;
/** @var int */ protected int $messageCounter = 2;
protected $messageCounter = 2;
/** @var int */ protected int $firstPlayed;
protected $firstPlayed; protected int $lastPlayed;
/** @var int */ protected GameMode $gamemode;
protected $lastPlayed;
/** @var GameMode */
protected $gamemode;
/** /**
* @var UsedChunkStatus[] chunkHash => status * @var UsedChunkStatus[] chunkHash => status
* @phpstan-var array<int, UsedChunkStatus> * @phpstan-var array<int, UsedChunkStatus>
*/ */
protected $usedChunks = []; protected array $usedChunks = [];
/** @var bool[] chunkHash => dummy */ /** @var bool[] chunkHash => dummy */
protected $loadQueue = []; protected array $loadQueue = [];
/** @var int */ protected int $nextChunkOrderRun = 5;
protected $nextChunkOrderRun = 5;
/** @var int */ protected int $viewDistance = -1;
protected $viewDistance = -1; protected int $spawnThreshold;
/** @var int */ protected int $spawnChunkLoadCount = 0;
protected $spawnThreshold; protected int $chunksPerTick;
/** @var int */ protected ChunkSelector $chunkSelector;
protected $spawnChunkLoadCount = 0; protected PlayerChunkLoader $chunkLoader;
/** @var int */
protected $chunksPerTick;
/** @var ChunkSelector */
protected $chunkSelector;
/** @var PlayerChunkLoader */
protected $chunkLoader;
/** @var bool[] map: raw UUID (string) => bool */ /** @var bool[] map: raw UUID (string) => bool */
protected $hiddenPlayers = []; protected array $hiddenPlayers = [];
/** @var float */ protected float $moveRateLimit = 10 * self::MOVES_PER_TICK;
protected $moveRateLimit = 10 * self::MOVES_PER_TICK; protected ?float $lastMovementProcess = null;
/** @var float|null */
protected $lastMovementProcess = null;
/** @var int */ protected int $inAirTicks = 0;
protected $inAirTicks = 0; protected float $stepHeight = 0.6;
/** @var float */
protected $stepHeight = 0.6;
/** @var Vector3|null */ protected ?Vector3 $sleeping = null;
protected $sleeping = null; private ?Position $spawnPosition = null;
/** @var Position|null */
private $spawnPosition = null;
private bool $respawnLocked = false; private bool $respawnLocked = false;
//TODO: Abilities //TODO: Abilities
/** @var bool */ protected bool $autoJump = true;
protected $autoJump = true; protected bool $allowFlight = false;
/** @var bool */ protected bool $flying = false;
protected $allowFlight = false;
/** @var bool */
protected $flying = false;
/** @var int|null */ protected ?int $lineHeight = null;
protected $lineHeight = null; protected string $locale = "en_US";
/** @var string */
protected $locale = "en_US";
/** @var int */ protected int $startAction = -1;
protected $startAction = -1;
/** @var int[] ID => ticks map */ /** @var int[] ID => ticks map */
protected $usedItemsCooldown = []; protected array $usedItemsCooldown = [];
/** @var int */ protected int $formIdCounter = 0;
protected $formIdCounter = 0;
/** @var Form[] */ /** @var Form[] */
protected $forms = []; protected array $forms = [];
/** @var \Logger */ protected \Logger $logger;
protected $logger;
/** @var SurvivalBlockBreakHandler|null */ protected ?SurvivalBlockBreakHandler $blockBreakHandler = null;
protected $blockBreakHandler = null;
public function __construct(Server $server, NetworkSession $session, PlayerInfo $playerInfo, bool $authenticated, Location $spawnLocation, ?CompoundTag $namedtag){ public function __construct(Server $server, NetworkSession $session, PlayerInfo $playerInfo, bool $authenticated, Location $spawnLocation, ?CompoundTag $namedtag){
$username = TextFormat::clean($playerInfo->getUsername()); $username = TextFormat::clean($playerInfo->getUsername());
@ -2019,8 +1983,8 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
protected function destroyCycles() : void{ protected function destroyCycles() : void{
$this->networkSession = null; $this->networkSession = null;
$this->cursorInventory = null; unset($this->cursorInventory);
$this->craftingGrid = null; unset($this->craftingGrid);
$this->spawnPosition = null; $this->spawnPosition = null;
$this->blockBreakHandler = null; $this->blockBreakHandler = null;
parent::destroyCycles(); parent::destroyCycles();