Example #1
0
 public function __construct(Position $center, $size, $what = null)
 {
     $this->level = $center->getLevel();
     $this->source = $center;
     $this->size = max($size, 0);
     $this->what = $what;
 }
Example #2
0
 /**
  * Returns a Position pointing to the spawn
  *
  * @return Position
  */
 public function getSpawnLocation()
 {
     return Position::fromObject($this->provider->getSpawn(), $this);
 }
Example #3
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));
         $this->namedtag["Hunger"] = new Short("Hunger", $this->getFood());
         $this->namedtag["Health"] = new Short("Health", $this->getHealth());
         $this->namedtag["MaxHealth"] = new Short("MaxHealth", $this->getMaxHealth());
         $this->namedtag["ExpCurrent"] = new Long("ExpCurrent", $this->getCurrentExperience());
         $this->namedtag["ExpLevel"] = new Long("ExpLevel", $this->getExperienceLevel());
         if ($this->username != "" and $this->namedtag instanceof Compound) {
             $this->server->saveOfflinePlayerData($this->username, $this->namedtag, $async);
         }
     }
 }
Example #4
0
 /**
  * Returns the Block on the side $side, works like Vector3::side()
  *
  * @param int $side
  * @param int $step
  *
  * @return Block
  */
 public function getSide($side, $step = 1)
 {
     if ($this->isValid()) {
         return $this->getLevel()->getBlock(Vector3::getSide($side, $step));
     }
     return Block::get(Item::AIR, 0, Position::fromObject(Vector3::getSide($side, $step)));
 }
Example #5
0
 /**
  * Returns a side Vector
  *
  * @param int $side
  * @param int $step
  *
  * @return Position
  *
  * @throws LevelException
  */
 public function getSide($side, $step = 1)
 {
     if (!$this->isValid()) {
         throw new LevelException("Undefined Level reference");
     }
     return Position::fromObject(parent::getSide($side, $step), $this->level);
 }
Example #6
0
 /**
  * @param Vector3|Position|Location $pos
  * @param float                     $yaw
  * @param float                     $pitch
  *
  * @return bool
  */
 public function teleport(Vector3 $pos, $yaw = null, $pitch = null)
 {
     if ($pos instanceof Location) {
         $yaw = $yaw === null ? $pos->yaw : $yaw;
         $pitch = $pitch === null ? $pos->pitch : $pitch;
     }
     $from = Position::fromObject($this, $this->level);
     $to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->level);
     $this->server->getPluginManager()->callEvent($ev = new EntityTeleportEvent($this, $from, $to));
     if ($ev->isCancelled()) {
         return false;
     }
     $this->ySize = 0;
     $pos = $ev->getTo();
     $this->setMotion($this->temporalVector->setComponents(0, 0, 0));
     if ($this->setPositionAndRotation($pos, $yaw === null ? $this->yaw : $yaw, $pitch === null ? $this->pitch : $pitch) !== false) {
         $this->resetFallDistance();
         $this->onGround = true;
         $this->lastX = $this->x;
         $this->lastY = $this->y;
         $this->lastZ = $this->z;
         $this->lastYaw = $this->yaw;
         $this->lastPitch = $this->pitch;
         $this->updateMovement();
         return true;
     }
     return false;
 }
Example #7
0
 public function __construct(Inventory $inventory, Position $pos)
 {
     $this->inventory = $inventory;
     parent::__construct($pos->x, $pos->y, $pos->z, $pos->level);
 }