本文整理汇总了PHP中pocketmine\Player::teleport方法的典型用法代码示例。如果您正苦于以下问题:PHP Player::teleport方法的具体用法?PHP Player::teleport怎么用?PHP Player::teleport使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\Player
的用法示例。
在下文中一共展示了Player::teleport方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: TeleportToTeamSpawn
public function TeleportToTeamSpawn(Player $p, $team, $arena)
{
$p->setHealth(20);
$p->setFood(20);
$p->setGamemode(0);
$p->getInventory()->clearAll();
$p->setExpLevel(0);
$config = new Config($this->getDataFolder() . "Arenas/" . $arena . ".yml", Config::YAML);
$welt = $config->getNested("Spawn." . $team . ".Welt");
$x = $config->getNested("Spawn." . $team . ".X");
$y = $config->getNested("Spawn." . $team . ".Y");
$z = $config->getNested("Spawn." . $team . ".Z");
$yaw = $config->getNested("Spawn." . $team . ".Yaw");
$pitch = $config->getNested("Spawn." . $team . ".Pitch");
if ($p->getLevel() != $this->getServer()->getLevelByName($welt)) {
$p->teleport($this->getServer()->getLevelByName($welt)->getSafeSpawn(), 0, 0);
}
$p->teleport(new Vector3($x, $y, $z), $yaw, $pitch);
}
示例2: teleport
public function teleport(Player $player, Position $pos)
{
$player->teleport($pos);
}
示例3: teleport
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);
}
}
}
示例4: work
public function work(Player $interactedPlayer)
{
if (FreedomDive::getInstance()->getWorldManagerByWorldFolderName($this->worldName)->canJoinGame()) {
$interactedPlayer->teleport(Server::getInstance()->getLevelByName($this->worldName)->getSpawnLocation());
FreedomDive::getInstance()->getWorldManagerByWorldFolderName($this->worldName)->onPlayerMoveToWorld($interactedPlayer);
} else {
$interactedPlayer->sendMessage(FreedomDive::getTranslation("CANNOT_JOIN"));
}
}
示例5: onRun
public function onRun(array $args, Faction $faction, Player $player)
{
// TODO find the correct named home
if (isset($args[0])) {
$home = $faction->getHome($args[0]);
if ($home instanceof Position) {
$player->teleport($home);
return "You have been teleported to {$args['0']}.";
}
return "There is no such home named \"{$args['0']}\"!";
}
$home = $faction->getHome();
if ($home instanceof Position) {
$player->teleport($home);
return "You have been teleported to your faction home.";
}
return "Your faction doesn't seem to have a home.";
}
示例6: restorePlayer
public function restorePlayer(Player $player)
{
if (isset($this->players[$player->getName()])) {
$get = $this->players[$player->getName()];
$player->setGamemode($get["gamemode"]);
$player->getInventory()->setContents(unserialize($get["inventory"]));
$player->getInventory()->setArmorContents(unserialize($get["armor"]));
$player->teleport(unserialize($get["spawn"]));
unset($this->players[$player->getName()]);
}
}
示例7: tpNearBy
/**
* Teleport a player near a location
* @param Player $player - player to be teleported
* @param Position $target - location to teleport nearby
* @param int $rand - how far to randomize positions
* @param int|null $dist - if not null it will make sure that new location is upto $dist
* @return bool - true on success, false on failure
*/
public static function tpNearBy(Player $player, Position $target, $rand = 3, $dist = null)
{
$mv = new Vector3($target->getX() + mt_rand(-$rand, $rand), $target->getY(), $target->getZ() + mt_rand(-$rand, $rand));
$pos = $target->getLevel()->getSafeSpawn($mv);
if ($dist !== null) {
$newdist = $pos->distance($target);
if ($newdist > $dist) {
return false;
}
// Will not get close enough!
}
$player->teleport($pos);
return true;
}
示例8: h_onDamage
public function h_onDamage(EntityDamageEvent $event)
{
if ($event->getCause() === EntityDamageEvent::CAUSE_VOID) {
$event->setCancelled();
$this->player->teleport($this->player->getLevel()->getSpawnLocation());
}
if (!$this->isLoggedIn()) {
$event->setCancelled();
$this->disableTpListener = true;
$this->teleport($this->spawningPosition);
$this->disableTpListener = false;
}
/*if($event instanceof EntityDamageByEntityEvent){
$target = $this->getPlayer();
$hitter = $event->getDamager();
if(!($hitter instanceof Player)){
return;
}
if((pow($hitter->x - $target->x, 2) + pow($hitter->z - $target->z, 2)) <= 2.25){
return;
}
$dir = $hitter
// ->add(0, $hitter->getEyeHeight(), 0)
->subtract(
$target
// ->add(0, $target->height / 2, 0)
);
$yaw = rad2deg(atan2($dir->z, $dir->x)) + 90;
// if(($len = $dir->length()) === 0){
// $len = 1;
// }
// $pitch = rad2deg(asin($dir->y / $len));
if((180 - abs(abs($hitter->yaw - $yaw) - 180)) > 90
// or (180 - abs(abs($hitter->pitch - $pitch) - 180)) > 60
){
$event->setCancelled();
$hitter->sendMessage("You can't attack players behind you!");
}
}*/
}
示例9: teleportPlayer
public function teleportPlayer(Player $player, Position $pos)
{
$player->teleport($pos, $player->getYaw(), $player->getPitch());
$player->sendMessage("Teleported!");
}
示例10: jail
private function jail(Player $player)
{
/*--Get player coords and ground coords--*/
$px = round($player->getX());
$py = round($player->getY());
$pz = round($player->getZ());
$gx = round($player->getFloorX());
$gy = round($player->getFloorY());
$gz = round($player->getFloorZ());
$level = $player->getLevel();
/*--Define the position of the 16 blocks around the player--*/
$pos1 = new Vector3($px + 1, $py, $pz);
$pos2 = new Vector3($px + 1, $py, $pz + 1);
$pos3 = new Vector3($px - 1, $py, $pz + 1);
$pos4 = new Vector3($px + 1, $py, $pz - 1);
$pos5 = new Vector3($px, $py, $pz + 1);
$pos6 = new Vector3($px - 1, $py, $pz);
$pos7 = new Vector3($px, $py, $pz - 1);
$pos8 = new Vector3($px - 1, $py + 1, $pz - 1);
$pos9 = new Vector3($px + 1, $py + 1, $pz);
$pos10 = new Vector3($px + 1, $py + 1, $pz + 1);
$pos11 = new Vector3($px - 1, $py + 1, $pz + 1);
$pos12 = new Vector3($px + 1, $py + 1, $pz - 1);
$pos13 = new Vector3($px, $py + 1, $pz + 1);
$pos14 = new Vector3($px - 1, $py + 1, $pz);
$pos15 = new Vector3($px, $py + 1, $pz - 1);
$pos16 = new Vector3($px - 1, $py + 1, $pz - 1);
/*--And place the blocks of bedrock--*/
$this->getServer()->getLevel($level)->setBlock($pos1, Block::get(7, 0));
$this->getServer()->getLevel($level)->setBlock($pos2, Block::get(7, 0));
$this->getServer()->getLevel($level)->setBlock($pos3, Block::get(7, 0));
$this->getServer()->getLevel($level)->setBlock($pos4, Block::get(7, 0));
$this->getServer()->getLevel($level)->setBlock($pos5, Block::get(7, 0));
$this->getServer()->getLevel($level)->setBlock($pos6, Block::get(7, 0));
$this->getServer()->getLevel($level)->setBlock($pos7, Block::get(7, 0));
$this->getServer()->getLevel($level)->setBlock($pos8, Block::get(7, 0));
$this->getServer()->getLevel($level)->setBlock($pos9, Block::get(7, 0));
$this->getServer()->getLevel($level)->setBlock($pos10, Block::get(7, 0));
$this->getServer()->getLevel($level)->setBlock($pos11, Block::get(7, 0));
$this->getServer()->getLevel($level)->setBlock($pos12, Block::get(7, 0));
$this->getServer()->getLevel($level)->setBlock($pos13, Block::get(7, 0));
$this->getServer()->getLevel($level)->setBlock($pos14, Block::get(7, 0));
$this->getServer()->getLevel($level)->setBlock($pos15, Block::get(7, 0));
$this->getServer()->getLevel($level)->setBlock($pos16, Block::get(7, 0));
/*--Place the blocks under and above the player--*/
$this->getServer()->getLevel($level)->setBlock(new Vector3($px, $py + 2, $pz), Block::get(7, 0));
$this->getServer()->getLevel($level)->setBlock(new Vector3($gx, $gy, $gz), Block::get(7, 0));
/*<--Re-Teleport the player to the original position 'cause he can escape before the blocks are placed-->*/
$tppos = new Position($px, $py, $pz, $level);
$player->teleport($tppos);
return true;
}
示例11: teleportToHub_OnJoin
public function teleportToHub_OnJoin(Player $player)
{
$temp = $this->getConfig()->getAll();
if (isset($temp["hub"])) {
if ($player->getLevel()->getName() != $temp["hub"]["world"]) {
if (Server::getInstance()->loadLevel($temp["hub"]["world"]) != false) {
$player->teleport(new Vector3($temp["hub"]["X"], $temp["hub"]["Y"], $temp["hub"]["Z"], $this->getServer()->getLevelByName($temp["hub"]["world"])), $temp["hub"]["Yaw"], $temp["hub"]["Pitch"]);
if ($temp["enable-hub-message"] == true && $temp["show-messages-onjoin"] == true) {
$player->sendMessage($this->translateColors("&", $this->getHubMessage($player)));
}
} else {
$player->sendMessage($this->translateColors("&", $this->getNoWorldMessage()));
}
} else {
$player->teleport(new Vector3($temp["hub"]["X"], $temp["hub"]["Y"], $temp["hub"]["Z"]), $temp["hub"]["Yaw"], $temp["hub"]["Pitch"]);
if ($temp["enable-hub-message"] == true && $temp["show-messages-onjoin"] == true) {
$player->sendMessage($this->translateColors("&", $this->getHubMessage($player)));
}
}
} else {
$player->sendMessage($this->translateColors("&", $this->getNoHubMessage()));
}
}
示例12: ReSpawn
public function ReSpawn(Player $player)
{
$pos = new Position($this->x, $this->y + 3, $this->z, $player->getLevel());
$player->teleport($pos);
}
示例13: handlePlayerEntry
/**
* Handle player entry to CTF game world
*
* @param Player $player
*/
public function handlePlayerEntry(Player $player)
{
// send player to lobby if specify
if ($this->getSetup()->isEnableSpanwToLobby()) {
$lobbyPos = $this->getSetup()->getLobbyPos();
$player->teleport($lobbyPos);
return;
}
// player should be outside of arena
$gameWorld = $this->getSetup()->getCTFWorldName();
if (strtolower($player->level->getName()) == strtolower($gameWorld)) {
// send entry point
$gameWorldPos = $this->getSetup()->getGamePos(CTFSetup::CTF_GAME_ENTRY);
$player->level->getChunk($gameWorldPos->x, $gameWorldPos->z);
$player->level->getBlockLightAt($gameWorldPos->x, $gameWorldPos->y, $gameWorldPos->z);
$player->teleport(new Vector3($gameWorldPos->x, $gameWorldPos->y, $gameWorldPos->z));
//update signs
$this->updateGameSigns($player);
return;
}
//grant player permissions
$this->grantPlayerDefaultPermissions($player);
}
示例14: killHandler
public function killHandler(Player $entity)
{
// $this->getServer()->broadcastMessage("killHandler tries to handle");
// player add deaths
// $nr = $this->games[strtolower($entity->getLevel()->getName())]["players"][$entity->getName()]["deaths"] + 1;
// $this->games[strtolower($entity->getLevel()->getName())]["players"][$entity->getName()]["deaths"] = $nr;
// save to config.. WHY EVEN?! can't i do ranks just only by times played and wins?
$this->getPlayerConfig();
$this->players->getAll()[$entity->getName()]["deaths"]++;
$this->setPlayerConfig();
$entity->sendTip(TextFormat::RED . "You fell into void");
$entity->setGamemode(3);
$entity->teleport($entity->getLevel()->getSpawnLocation());
$this->leaveLobby($entity, $entity->getLevel());
// if killer add kills
/*
* if($killer !== null){
* $players = array();
* foreach(array_keys($this->games[strtolower($killer->getLevel()->getName())]["players"]) as $player){
* array_push($players, $this->getServer()->getPlayer($player));
* }
* $this->getServer()->broadcastMessage(TextFormat::RED . $killer->getDisplayName() . " killed " . $entity->getDisplayName(), $players);
* $this->games[strtolower($killer->getLevel()->getName())]["players"][$killer->getName()]["kills"]++;
* // add arrow
* $killer->getInventory()->addItem(Item::fromString("Arrow"));
* // save to config.. WHY EVEN?! can't i do ranks just only by times played and wins?
* $this->getPlayerConfig();
* $this->players->getAll()[$killer->getName()]["kills"]++;
* $this->setPlayerConfig();
* $killer->sendTip(TextFormat::GOLD . "Kills: " . TextFormat::GREEN . $this->games[strtolower($killer->getLevel()->getName())]["players"][$killer->getName()]["kills"] . TextFormat::LIGHT_PURPLE . " | " . TextFormat::GOLD . "Deaths: " . TextFormat::RED . $this->games[strtolower($killer->getLevel()->getName())]["players"][$killer->getName()]["deaths"]);
*/
if (isset($this->games[strtolower($entity->getLevel()->getName())])) {
if (count(array_keys($this->games[strtolower($entity->getLevel()->getName())]["players"])) <= 1) {
$this->stopGame($entity->getLevel(), $this->getServer()->getPlayer(array_keys($this->games[strtolower($entity->getLevel()->getName())]["players"])[0]));
return;
}
// }
// else{
$this->getServer()->broadcastTip(TextFormat::RED . $entity->getName() . " fell into void\n" . TextFormat::GREEN . count(array_keys($this->games[strtolower($entity->getLevel()->getName())]["players"])) . " players remaining");
}
// }
// end if died too often
/*
* if($nr >= $this->getConfig()->getNested("lobby-defaults.maxdeaths")){
* $entity->setGamemode(3);
* $entity->sendMessage(TextFormat::RED . "You died too many times.");
* // leave or better let the player spectate? if spectate then the player has to do /spleef leave.. but the game will run until the player will do this
* }
* else{
* $this->respawnPlayer($entity, strtolower($entity->getLevel()->getName()));
* }
*/
$this->leaveLobby($entity, $entity->getLevel());
}
示例15: onRun
public function onRun($t)
{
$this->player->teleport($this->pos);
}