Esempio n. 1
0
 /**
  * Returns a side Vector
  *
  * @param int $side
  * @param int $step
  *
  * @return WeakPosition
  *
  * @throws LevelException
  */
 public function getSide($side, $step = 1)
 {
     assert($this->isValid());
     return WeakPosition::fromObject(parent::getSide($side, $step), $this->level);
 }
Esempio n. 2
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 StringTag("Level", $this->level->getName());
         if ($this->hasValidSpawnPosition()) {
             $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));
         if ($this->username != "" and $this->namedtag instanceof CompoundTag) {
             $this->server->saveOfflinePlayerData($this->username, $this->namedtag, $async);
         }
     }
 }