pocketmine\level\Location::fromObject PHP Method

fromObject() public static method

public static fromObject ( Vector3 $pos, Level $level = null, float $yaw, float $pitch ) : Location
$pos pocketmine\math\Vector3
$level Level default null
$yaw float default 0.0
$pitch float default 0.0
return Location
    public static function fromObject(Vector3 $pos, Level $level = null, $yaw = 0.0, $pitch = 0.0)
    {
        return new Location($pos->x, $pos->y, $pos->z, $yaw, $pitch, $level === null ? $pos instanceof Position ? $pos->level : null : $level);
    }

Usage Example

Example #1
0
 /**
  * @param CommandSender $sender
  * @param string $alias
  * @param array $args
  * @return bool
  */
 public function execute(CommandSender $sender, $alias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return false;
     }
     if (!isset($args[0]) && !$sender instanceof Player || count($args) > 1) {
         $this->sendUsage($sender, $alias);
         return false;
     }
     $player = $sender;
     if (isset($args[0])) {
         if (!$sender->hasPermission("essentials.spawn.other")) {
             $sender->sendMessage(TextFormat::RED . "[Error] You can't teleport other players to spawn");
             return false;
         } elseif (!($player = $this->getAPI()->getPlayer($args[0]))) {
             $sender->sendMessage(TextFormat::RED . "[Error] Player not found");
             return false;
         }
     }
     $player->teleport(Location::fromObject($this->getAPI()->getServer()->getDefaultLevel()->getSpawnLocation(), $this->getAPI()->getServer()->getDefaultLevel()));
     $player->sendMessage(TextFormat::GREEN . "Teleporting...");
     return true;
 }
All Usage Examples Of pocketmine\level\Location::fromObject