pocketmine\Player::teleport PHP Method

teleport() public method

public teleport ( Vector3 $pos, float $yaw = null, float $pitch = null ) : boolean
$pos pocketmine\math\Vector3
$yaw float
$pitch float
return boolean
    public function teleport(Vector3 $pos, $yaw = null, $pitch = null)
    {
        if (!$this->isOnline()) {
            return false;
        }
        $oldPos = $this->getPosition();
        if (parent::teleport($pos, $yaw, $pitch)) {
            foreach ($this->windowIndex as $window) {
                if ($window === $this->inventory) {
                    continue;
                }
                $this->removeWindow($window);
            }
            $this->teleportPosition = new Vector3($this->x, $this->y, $this->z);
            if (!$this->checkTeleportPosition()) {
                $this->forceMovement = $oldPos;
            } else {
                $this->spawnToAll();
            }
            $this->resetFallDistance();
            $this->nextChunkOrderRun = 0;
            $this->newPosition = null;
            $this->stopSleep();
            return true;
        }
        return false;
    }

Usage Example

Exemplo n.º 1
1
 public function teleport(Player $player)
 {
     if ($this->message !== null) {
         $player->sendMessage($this->message);
     }
     if ($this->position instanceof Position) {
         if ($this->position->isValid()) {
             if ($this->position instanceof WeakPosition) {
                 $this->position->updateProperties();
             }
             //Server::getInstance()->getLogger()->info($this->position->x . " : " . $this->position->y . " : " . $this->position->z);
             $player->teleport($this->position);
         } else {
             $player->sendMessage($this->getApi()->executeTranslationItem("level-not-loaded-warp"));
         }
     } else {
         $plugin = $player->getServer()->getPluginManager()->getPlugin("FastTransfer");
         if ($plugin instanceof PluginBase && $plugin->isEnabled() && $plugin instanceof FastTransfer) {
             $plugin->transferPlayer($player, $this->address, $this->port);
         } else {
             $player->getServer()->getPluginManager()->getPlugin("SimpleWarp")->getLogger()->warning("In order to use warps tp other servers, you must install " . TextFormat::AQUA . "FastTransfer" . TextFormat::RESET . ".");
             $player->sendPopup(TextFormat::RED . "Warp failed!" . TextFormat::RESET);
         }
     }
 }
All Usage Examples Of pocketmine\Player::teleport
Player