From 45b0cbc79689d08ac4a0fa9552a0594bf50fabda Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 5 Jul 2019 17:17:48 +0100 Subject: [PATCH] Human: remove getRawUniqueId() premature optimization this is never used in a hot path and presents a potential for inconsistency. --- changelogs/4.0-snapshot.md | 2 ++ src/pocketmine/Server.php | 9 +++++---- src/pocketmine/entity/Human.php | 8 -------- src/pocketmine/player/Player.php | 7 +++---- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/changelogs/4.0-snapshot.md b/changelogs/4.0-snapshot.md index 8dec8eac6..4b1374394 100644 --- a/changelogs/4.0-snapshot.md +++ b/changelogs/4.0-snapshot.md @@ -165,6 +165,8 @@ This version features substantial changes to the network system, improving coher - `Living->hasEffect()` -> `EffectManager->has()` - `Living->hasEffects()` -> `EffectManager->hasEffects()` - `Living->getEffects()` -> `EffectManager->all()` +- The following API methods have been removed: + - `Human->getRawUniqueId()`: use `Human->getUniqueId()->toBinary()` instead - The following classes have been removed: - `Creature` - `Damageable` diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 5e9e96d9d..ee18ea34b 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1781,16 +1781,17 @@ class Server{ foreach($this->playerList as $p){ $p->getNetworkSession()->onPlayerAdded($player); } - $this->playerList[$player->getRawUniqueId()] = $player; + $rawUUID = $player->getUniqueId()->toBinary(); + $this->playerList[$rawUUID] = $player; if($this->sendUsageTicker > 0){ - $this->uniquePlayers[$player->getRawUniqueId()] = $player->getRawUniqueId(); + $this->uniquePlayers[$rawUUID] = $rawUUID; } } public function removeOnlinePlayer(Player $player) : void{ - if(isset($this->playerList[$player->getRawUniqueId()])){ - unset($this->playerList[$player->getRawUniqueId()]); + if(isset($this->playerList[$rawUUID = $player->getUniqueId()->toBinary()])){ + unset($this->playerList[$rawUUID]); foreach($this->playerList as $p){ $p->getNetworkSession()->onPlayerRemoved($player); } diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 6364e72c8..1dd906d99 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -82,7 +82,6 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ /** @var UUID */ protected $uuid; - protected $rawUUID; public $width = 0.6; public $height = 1.8; @@ -137,13 +136,6 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ return $this->uuid; } - /** - * @return string - */ - public function getRawUniqueId() : string{ - return $this->rawUUID; - } - /** * Returns a Skin object containing information about this human's skin. * @return Skin diff --git a/src/pocketmine/player/Player.php b/src/pocketmine/player/Player.php index 570254d16..858a69834 100644 --- a/src/pocketmine/player/Player.php +++ b/src/pocketmine/player/Player.php @@ -282,7 +282,6 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $this->randomClientId = $this->playerInfo->getClientId(); $this->uuid = $this->playerInfo->getUuid(); - $this->rawUUID = $this->uuid->toBinary(); $this->xuid = $this->playerInfo->getXuid(); $this->perm = new PermissibleBase($this); @@ -575,7 +574,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, * @return bool */ public function canSee(Player $player) : bool{ - return !isset($this->hiddenPlayers[$player->getRawUniqueId()]); + return !isset($this->hiddenPlayers[$player->getUniqueId()->toBinary()]); } /** @@ -585,7 +584,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, if($player === $this){ return; } - $this->hiddenPlayers[$player->getRawUniqueId()] = true; + $this->hiddenPlayers[$player->getUniqueId()->toBinary()] = true; $player->despawnFrom($this); } @@ -596,7 +595,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, if($player === $this){ return; } - unset($this->hiddenPlayers[$player->getRawUniqueId()]); + unset($this->hiddenPlayers[$player->getUniqueId()->toBinary()]); if($player->isOnline()){ $player->spawnTo($this); }