From 8274f5b3cc0b2bd76164f661b00dde3b6ff33e3c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 27 Jul 2017 11:25:40 +0100 Subject: [PATCH] More hack-fixes for #1220 Player and network really need to get divorced, and fast. --- src/pocketmine/Player.php | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 09dbad881..d1b204381 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -299,10 +299,17 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** @var int|null */ protected $lineHeight = null; + /** + * @return TranslationContainer|string + */ public function getLeaveMessage(){ - return new TranslationContainer(TextFormat::YELLOW . "%multiplayer.player.left", [ - $this->getDisplayName() - ]); + if($this->joined){ + return new TranslationContainer(TextFormat::YELLOW . "%multiplayer.player.left", [ + $this->getDisplayName() + ]); + } + + return ""; } /** @@ -3444,12 +3451,14 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->usedChunks = []; $this->loadQueue = []; - foreach($this->server->getOnlinePlayers() as $player){ - if(!$player->canSee($this)){ - $player->showPlayer($this); + if($this->loggedIn){ + foreach($this->server->getOnlinePlayers() as $player){ + if(!$player->canSee($this)){ + $player->showPlayer($this); + } } + $this->hiddenPlayers = []; } - $this->hiddenPlayers = []; foreach($this->windowIndex as $window){ $this->removeWindow($window); @@ -3460,8 +3469,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ parent::close(); $this->spawned = false; - $this->interface->close($this, $notify ? $reason : ""); - if($this->loggedIn){ $this->loggedIn = false; $this->server->removeOnlinePlayer($this); @@ -3489,6 +3496,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ }catch(\Throwable $e){ $this->server->getLogger()->logException($e); }finally{ + $this->interface->close($this, $notify ? $reason : ""); $this->server->removePlayer($this); } }