Fixed possible Player crash on save

This commit is contained in:
Shoghi Cervantes 2014-09-05 10:50:19 +02:00
parent 98e0583f34
commit d3c308c5a8

View File

@ -2222,23 +2222,25 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
parent::saveNBT(); parent::saveNBT();
$this->namedtag["Level"] = $this->getLevel()->getName(); if($this->getLevel() instanceof Level){
if($this->spawnPosition instanceof Position and $this->spawnPosition->getLevel() instanceof Level){ $this->namedtag["Level"] = $this->getLevel()->getName();
$this->namedtag["SpawnLevel"] = $this->spawnPosition->getLevel()->getName(); if($this->spawnPosition instanceof Position and $this->spawnPosition->getLevel() instanceof Level){
$this->namedtag["SpawnX"] = (int) $this->spawnPosition->x; $this->namedtag["SpawnLevel"] = $this->spawnPosition->getLevel()->getName();
$this->namedtag["SpawnY"] = (int) $this->spawnPosition->y; $this->namedtag["SpawnX"] = (int) $this->spawnPosition->x;
$this->namedtag["SpawnZ"] = (int) $this->spawnPosition->z; $this->namedtag["SpawnY"] = (int) $this->spawnPosition->y;
} $this->namedtag["SpawnZ"] = (int) $this->spawnPosition->z;
}
foreach($this->achievements as $achievement => $status){ foreach($this->achievements as $achievement => $status){
$this->namedtag->Achievements[$achievement] = new Byte($achievement, $status === true ? 1 : 0); $this->namedtag->Achievements[$achievement] = new Byte($achievement, $status === true ? 1 : 0);
} }
$this->namedtag["playerGameType"] = $this->gamemode; $this->namedtag["playerGameType"] = $this->gamemode;
$this->namedtag["lastPlayed"] = floor(microtime(true) * 1000); $this->namedtag["lastPlayed"] = floor(microtime(true) * 1000);
if($this->username != "" and $this->isOnline() and $this->namedtag instanceof Compound){ if($this->username != "" and $this->isOnline() and $this->namedtag instanceof Compound){
$this->server->saveOfflinePlayerData($this->username, $this->namedtag); $this->server->saveOfflinePlayerData($this->username, $this->namedtag);
}
} }
} }