saveNBT() public method

public saveNBT ( )
Example #1
0
 /**
  * Handles player data saving
  */
 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 String("Level", $this->level->getName());
         if ($this->spawnPosition instanceof Position and $this->spawnPosition->getLevel() instanceof Level) {
             $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 Byte($achievement, $status === true ? 1 : 0);
         }
         $this->namedtag["playerGameType"] = $this->gamemode;
         $this->namedtag["lastPlayed"] = new Long("lastPlayed", floor(microtime(true) * 1000));
         if ($this->username != "" and $this->namedtag instanceof Compound) {
             $this->server->saveOfflinePlayerData($this->username, $this->namedtag, $async);
         }
     }
 }