Merge branch 'release/3.5'

This commit is contained in:
Dylan K. Taylor 2018-12-28 19:32:48 +00:00
commit baf278831e

View File

@ -2820,91 +2820,80 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
*/ */
final public function close($message = "", string $reason = "generic reason", bool $notify = true) : void{ final public function close($message = "", string $reason = "generic reason", bool $notify = true) : void{
if($this->isConnected() and !$this->closed){ if($this->isConnected() and !$this->closed){
$ip = $this->networkSession->getIp();
$port = $this->networkSession->getPort();
$this->networkSession->onPlayerDestroyed($reason, $notify);
$this->networkSession = null;
try{ PermissionManager::getInstance()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this);
$ip = $this->networkSession->getIp(); PermissionManager::getInstance()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
$port = $this->networkSession->getPort();
$this->networkSession->onPlayerDestroyed($reason, $notify);
$this->networkSession = null;
PermissionManager::getInstance()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this); $this->stopSleep();
PermissionManager::getInstance()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
$this->stopSleep(); if($this->spawned){
$ev = new PlayerQuitEvent($this, $message, $reason);
$ev->call();
if($ev->getQuitMessage() != ""){
$this->server->broadcastMessage($ev->getQuitMessage());
}
if($this->spawned){ $this->save();
$ev = new PlayerQuitEvent($this, $message, $reason); }
$ev->call();
if($ev->getQuitMessage() != ""){ if($this->isValid()){
$this->server->broadcastMessage($ev->getQuitMessage()); foreach($this->usedChunks as $index => $d){
Level::getXZ($index, $chunkX, $chunkZ);
$this->level->unregisterChunkLoader($this, $chunkX, $chunkZ);
foreach($this->level->getChunkEntities($chunkX, $chunkZ) as $entity){
$entity->despawnFrom($this);
} }
unset($this->usedChunks[$index]);
}
}
$this->usedChunks = [];
$this->loadQueue = [];
try{ if($this->loggedIn){
$this->save(); $this->server->onPlayerLogout($this);
}catch(\Throwable $e){ foreach($this->server->getOnlinePlayers() as $player){
$this->server->getLogger()->critical("Failed to save player data for " . $this->getName()); if(!$player->canSee($this)){
$this->server->getLogger()->logException($e); $player->showPlayer($this);
} }
} }
$this->hiddenPlayers = [];
}
if($this->isValid()){ $this->removeAllWindows(true);
foreach($this->usedChunks as $index => $d){ $this->windows = [];
Level::getXZ($index, $chunkX, $chunkZ); $this->windowIndex = [];
$this->level->unregisterChunkLoader($this, $chunkX, $chunkZ); $this->cursorInventory = null;
foreach($this->level->getChunkEntities($chunkX, $chunkZ) as $entity){ $this->craftingGrid = null;
$entity->despawnFrom($this);
}
unset($this->usedChunks[$index]);
}
}
$this->usedChunks = [];
$this->loadQueue = [];
if($this->loggedIn){ if($this->constructed){
$this->server->onPlayerLogout($this); parent::close();
foreach($this->server->getOnlinePlayers() as $player){ }else{
if(!$player->canSee($this)){ $this->closed = true;
$player->showPlayer($this); }
} $this->spawned = false;
}
$this->hiddenPlayers = [];
}
$this->removeAllWindows(true); if($this->loggedIn){
$this->windows = []; $this->loggedIn = false;
$this->windowIndex = []; $this->server->removeOnlinePlayer($this);
$this->cursorInventory = null; }
$this->craftingGrid = null; $this->server->removePlayer($this);
if($this->constructed){ $this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.player.logOut", [
parent::close(); TextFormat::AQUA . $this->getName() . TextFormat::WHITE,
}else{ $ip,
$this->closed = true; $port,
} $this->getServer()->getLanguage()->translateString($reason)
$this->spawned = false; ]));
if($this->loggedIn){ $this->spawnPosition = null;
$this->loggedIn = false;
$this->server->removeOnlinePlayer($this);
}
$this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.player.logOut", [ if($this->perm !== null){
TextFormat::AQUA . $this->getName() . TextFormat::WHITE, $this->perm->clearPermissions();
$ip, $this->perm = null;
$port,
$this->getServer()->getLanguage()->translateString($reason)
]));
$this->spawnPosition = null;
if($this->perm !== null){
$this->perm->clearPermissions();
$this->perm = null;
}
}catch(\Throwable $e){
$this->server->getLogger()->logException($e);
}finally{
$this->server->removePlayer($this);
} }
} }
} }