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
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;
 }
Example #2
0
 /**
  * Create a warp or override its position
  *
  * @param string $warp
  * @param Position $pos
  * @param int $yaw
  * @param int $pitch
  * @return bool
  */
 public function setWarp($warp, Position $pos, $yaw = 0, $pitch = 0)
 {
     if (!$this->validateName($warp, false)) {
         return false;
     }
     $this->warps[$warp] = $pos instanceof BaseLocation ? $pos : BaseLocation::fromPosition($warp, $pos instanceof Location ? $pos : Location::fromObject($pos, $pos->getLevel(), $yaw, $pitch));
     return true;
 }