public function save($async = false)
{
if ($this->closed) {
throw new \InvalidStateException("Tried to save closed player");
}
parent::saveNBT();
if ($this->level instanceof Level) {
$this->namedtag->Level = new StringTag("Level", $this->level->getName());
if ($this->spawnPosition instanceof Position and $this->spawnPosition->getLevel() instanceof Level and $this->spawnPosition->getLevel()->getProvider() !== NULL) {
$this->namedtag["SpawnLevel"] = $this->spawnPosition->getLevel()->getName();
$this->namedtag["SpawnX"] = (int) $this->spawnPosition->x;
$this->namedtag["SpawnY"] = (int) $this->spawnPosition->y;
$this->namedtag["SpawnZ"] = (int) $this->spawnPosition->z;
}
foreach ($this->achievements as $achievement => $status) {
$this->namedtag->Achievements[$achievement] = new ByteTag($achievement, $status === true ? 1 : 0);
}
$this->namedtag["playerGameType"] = $this->gamemode;
$this->namedtag["lastPlayed"] = new LongTag("lastPlayed", floor(microtime(true) * 1000));
$this->namedtag["Hunger"] = new ShortTag("Hunger", $this->food);
$this->namedtag["Health"] = new ShortTag("Health", $this->getHealth());
$this->namedtag["MaxHealth"] = new ShortTag("MaxHealth", $this->getMaxHealth());
$this->namedtag["Experience"] = new LongTag("Experience", $this->exp);
$this->namedtag["ExpLevel"] = new LongTag("ExpLevel", $this->expLevel);
if ($this->username != "" and $this->namedtag instanceof CompoundTag) {
$this->server->saveOfflinePlayerData($this->username, $this->namedtag, $async);
}
}
}