本文整理汇总了PHP中pocketmine\Player::getPosition方法的典型用法代码示例。如果您正苦于以下问题:PHP Player::getPosition方法的具体用法?PHP Player::getPosition怎么用?PHP Player::getPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\Player
的用法示例。
在下文中一共展示了Player::getPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(SimpleWarp $plugin, Warp $warp, Player $player)
{
parent::__construct($plugin);
$this->warp = $warp;
$this->player = $player;
$this->position = $player->getPosition();
}
示例2: onRun
public function onRun(array $args, Player $player)
{
$global = false;
$anchor = $player->getPosition();
$name = isset($args[0]) ? array_shift($args) : "default";
while (isset($args[0])) {
$arg = array_shift($args);
switch ($arg) {
case "g":
$global = $this->getMain()->getClipboardProvider();
break;
case "a":
case "anchor":
$anchor = $this->getMain()->getAnchor($player);
break;
}
}
if ($global instanceof ClipboardProvider) {
$clip = $global[$name];
} else {
$clip = $this->getMain()->getClip($player, $name);
}
if (!$clip instanceof Clip) {
if ($global instanceof ClipboardProvider) {
return "There isn't a global clip called {$name}!";
} else {
return "You don't have a clip called {$name}!";
}
}
$clip->paste($anchor);
return count($clip->getBlocks()) . " block(s) have been pasted.";
}
示例3: onActivate
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
{
if ($player === null or $player->isSurvival() !== true) {
return false;
}
if ($target->getId() === Block::STILL_WATER or $target->getId() === Block::WATER) {
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerGlassBottleEvent($player, $target, $this));
if ($ev->isCancelled()) {
return false;
} else {
if ($this->count <= 1) {
$player->getInventory()->setItemInHand(Item::get(Item::POTION, 0, 1));
return true;
} else {
$this->count--;
$player->getInventory()->setItemInHand($this);
}
if ($player->getInventory()->canAddItem(Item::get(Item::POTION, 0, 1)) === true) {
$player->getInventory()->AddItem(Item::get(Item::POTION, 0, 1));
} else {
$motion = $player->getDirectionVector()->multiply(0.4);
$position = clone $player->getPosition();
$player->getLevel()->dropItem($position->add(0, 0.5, 0), Item::get(Item::POTION, 0, 1), $motion, 40);
}
return true;
}
}
return false;
}
示例4: onRun
public function onRun(array $args, Player $player)
{
$mode = 0;
$target = $player->getPosition();
while (isset($args[0])) {
$arg = array_shift($args);
switch ($arg) {
case "c":
case "crosshair":
$target = WorldEditArt::getCrosshairTarget($player);
if (!$target instanceof Block) {
return "The block is too far/in the void/sky!";
}
break;
case "v":
case "view":
$mode = 1;
break;
}
}
switch ($mode) {
case 0:
$this->getMain()->setAnchor($player, $target);
return "Your anchor has been set to " . WorldEditArt::posToStr($target) . ".";
case 1:
$anchor = $this->getMain()->getAnchor($player);
if (!$anchor instanceof Position) {
return "You don't have an anchor selected!";
}
return "Your anchor is at " . WorldEditArt::posToStr($anchor) . ".";
default:
return null;
}
}
示例5: onShootRun
public function onShootRun(array $args, Player $player)
{
if (!isset($args[0]) or !is_numeric($args[0])) {
return self::WRONG_USE;
}
$length = floatval(array_shift($args));
$p1 = $player->getPosition()->floor();
$p2 = $player->add($player->getDirectionVector()->multiply($length))->floor();
if ($p1->y < 0 or $p1->y > (defined($path = "pemapmodder\\worldeditart\\MAX_WORLD_HEIGHT") ? constant($path) : 127)) {
return "You must be inside the building height!";
} elseif ($p2->y < 0 or $p2->y > (defined($path = "pemapmodder\\worldeditart\\MAX_WORLD_HEIGHT") ? constant($path) : 127)) {
return "The selected area exceeded the world height limit!";
}
$player->getLevel()->loadChunk($p2->x >> 4, $p2->z >> 4);
while (isset($args[0])) {
$arg = array_shift($args);
switch ($arg) {
case "a":
case "adverse":
$cache = [$p1, $p2];
$p1 = $cache[1];
$p2 = $cache[0];
break;
}
}
$level = $player->getLevel();
$this->getMain()->setSelection($player, $sel = new CuboidSpace($p1 = Position::fromObject($p1, $level), $p2 = Position::fromObject($p2, $level)));
return "Cuboid selection set: {$sel} (" . count($sel->getPosList()) . " blocks)";
}
示例6: storePlayer
public function storePlayer(Player $player)
{
if (!isset($this->players[$player->getName()])) {
$this->players[$player->getName()] = ["inventory" => serialize($player->getInventory()->getContents()), "armor" => serialize($player->getInventory()->getArmorContents()), "spawn" => serialize($player->getPosition()), "gamemode" => $player->getGamemode()];
$player->setGamemode(0);
$player->getInventory()->clearAll();
}
}
示例7: onRun
public function onRun(array $args, Space $space, Player $player)
{
$anchor = $player->getPosition();
if (isset($args[0]) and ($args[0] === "-a" or $args[0] === "-anchor")) {
$anchor = $this->getMain()->getAnchor($player);
}
if (!isset($args[0])) {
array_unshift($args, "default");
}
$clip = new Clip($space, $anchor, array_shift($args));
if (isset($args[0]) and ($args[0] === "g" or $args[0] === "global")) {
$clipboard = $this->getMain()->getClipboardProvider();
$clipboard[$clip->getName()] = $clip;
} else {
$this->getMain()->setClip($player, $clip, $clip->getName());
}
return "Clip " . $clip->getName() . " copied.";
}
示例8: addPlayerFireworks
public static function addPlayerFireworks(Player $player, Position $pos1, $count = 5)
{
$pos = new Position($player->getPosition()->x, $player->getPosition()->y + 3, $player->getPosition()->z, $player->getLevel());
$pos2 = new Position($player->getPosition()->x, $player->getPosition()->y + 1, $player->getPosition()->z, $player->getLevel());
$exp = new Explosion($pos, 1);
$exp->explodeB();
MagicUtil::addParticles($player->getLevel(), "explode", $pos2);
for ($i = 0; $i < 5; $i++) {
$pos = new Position($pos1->x + rand(-2, 3), $pos1->y + rand(0, 5), $pos1->z + rand(-2, 3), $player->getLevel());
$player->getLevel()->addParticle(new DustParticle($pos, rand(1, 255), rand(1, 255), rand(1, 255)));
$player->getLevel()->addParticle(new DustParticle($pos, rand(1, 255), rand(1, 255), rand(1, 255)));
$player->getLevel()->addParticle(new DustParticle($pos, rand(1, 255), rand(1, 255), rand(1, 255)));
$player->getLevel()->addParticle(new DustParticle($pos, rand(1, 255), rand(1, 255), rand(1, 255)));
$player->getLevel()->addParticle(new DustParticle($pos, rand(1, 255), rand(1, 255), rand(1, 255)));
}
MagicUtil::addParticles($player->getLevel(), "driplava", $pos1);
}
示例9: onRun
public function onRun(array $args, Player $player)
{
if (!isset($args[0])) {
return false;
}
$radius = floatval(array_shift($args));
$anchor = $player->getPosition();
while (isset($args[0])) {
$arg = array_shift($args);
switch ($arg) {
case "a":
case "anchor":
$anchor = $this->getMain()->getAnchor($player);
if (!$anchor instanceof Position) {
return self::NO_ANCHOR;
}
break;
}
}
$sel = new SphereSpace($anchor, $radius);
$this->getMain()->setSelection($player, $sel);
return "You have selected {$sel}.";
}
示例10: teleportToMap
public static final function teleportToMap($levelname, Player $player)
{
if (!$player->getServer()->isLevelLoaded($levelname)) {
$ret = $player->getServer()->loadLevel($levelname);
if (!$ret) {
$player->sendMessage("[HG]Error, unable load World: " . $levelname);
return;
}
}
if (!$player->getServer()->isLevelGenerated($levelname)) {
$player->sendMessage("[HG] world generation is not ready! try later.");
return;
}
$level = $player->getServer()->getLevelByName($levelname);
if (is_null($level)) {
$player->sendMessage("[HG] Error, unable access world: " . $levelname);
return;
}
$player->getLevel()->updateAllLight($player->getPosition());
$player->getLevel()->updateAround($player->getPosition());
$player->teleport($level->getSafeSpawn());
}
示例11: handleTapOnArenaSigns
/**
*
* Handle Tap On Arena Signs
*
* @param Player $player
* @param unknown $b
* @return boolean
*/
public function handleTapOnArenaSigns(Player $player, $b)
{
foreach ($this->arenas as &$arena) {
if ($arena instanceof MapArenaModel) {
// tap on vote sign
if (!empty($arena->signVote)) {
$blockPosKey = round($b->x) . "." . round($b->y) . "." . round($b->z);
$casePosKey = round($arena->signVote->x) . "." . round($arena->signVote->y) . "." . round($arena->signVote->z);
if ($blockPosKey === $casePosKey && $blockPosKey != "0.0.0") {
if (!$arena->published) {
$player->sendMessage("[HG] This map is not available yet! please try another one.");
break;
}
$players[] = $player;
$player->getLevel()->addSound(new ClickSound($player->getPosition()), $players);
MagicUtil::addParticles($player->getLevel(), "reddust", $arena->signVote, 20);
if ($arena->vote === 0 && isset($arena->votedPlayers[$player->getName()])) {
unset($arena->votedPlayers[$player->getName()]);
}
if (!isset($arena->votedPlayers[$player->getName()])) {
$arena->vote++;
$arena->votedPlayers[$player->getName()] = $player;
} else {
$player->sendMessage(TextFormat::YELLOW . "[HG] Already voted! [" . $arena->displayName . "]");
}
$player->sendMessage(TextFormat::GRAY . "[HG] " . $arena->displayName . " map votes [" . TextFormat::YELLOW . $arena->vote . TextFormat::GRAY . "]");
break;
}
}
if (!empty($arena->signExit) && !empty($arena->arenaExitPos)) {
$blockPosKey = round($b->x) . "." . round($b->y) . "." . round($b->z);
$casePosKey = round($arena->signExit->x) . "." . round($arena->signExit->y) . "." . round($arena->signExit->z);
if ($blockPosKey === $casePosKey && $blockPosKey != "0.0.0") {
$players[] = $player;
$player->level->addSound(new ClickSound($player->getPosition()), $players);
MagicUtil::addParticles($player->getLevel(), "portal", $player->getPosition(), 100);
unset($arena->joinedPlayers[$player->getName()]);
unset($arena->livePlayers[$player->getName()]);
$player->teleport($arena->arenaExitPos);
break;
}
}
if (!empty($arena->signJoin) && !empty($arena->arenaEnterPos)) {
$blockPosKey = round($b->x) . "." . round($b->y) . "." . round($b->z);
$casePosKey = round($arena->signJoin->x) . "." . round($arena->signJoin->y) . "." . round($arena->signJoin->z);
if ($blockPosKey === $casePosKey && $blockPosKey != "0.0.0") {
$players[] = $player;
$player->level->addSound(new ClickSound($player->getPosition()), $players);
MagicUtil::addParticles($player->getLevel(), "portal", $player->getPosition(), 100);
MapPortal::teleportToMap($arena->levelName, $player);
$player->teleport($arena->arenaEnterPos);
break;
}
}
}
}
}
示例12: addItem
public function addItem(Item $item, Player $player, Item $result)
{
if ($item->getCount() <= 1) {
$player->getInventory()->setItemInHand($result);
} else {
$item->setCount($item->getCount() - 1);
if ($player->getInventory()->canAddItem($result) === true) {
$player->getInventory()->addItem($result);
} else {
$motion = $player->getDirectionVector()->multiply(0.4);
$position = clone $player->getPosition();
$player->getLevel()->dropItem($position->add(0, 0.5, 0), $result, $motion, 40);
}
}
}
示例13: fire
private function fire(Player $c, $fuse, $speed)
{
$pos = $c->getPosition();
$pos->y += $c->getEyeHeight();
$dir = $c->getDirectionVector();
$dir->x = $dir->x * $speed;
$dir->y = $dir->y * $speed;
$dir->z = $dir->z * $speed;
$this->scorchit($pos, $dir, $fuse);
}
示例14: onRun
public function onRun(array $args, Player $player)
{
$flag = 0;
// 0 for me, 1 for anchor, 2 for crosshair
if (isset($args[0])) {
$arg = array_shift($args);
switch ($arg) {
case "a":
case "anchor":
$flag = 1;
break;
case "c":
case "crosshair":
$flag = 2;
break;
}
}
$selected = $player->getPosition();
if ($flag === 1) {
$selected = $this->getMain()->getAnchor($player);
if (!$selected instanceof Position) {
return self::NO_ANCHOR;
}
}
if ($flag === 2) {
$selected = WorldEditArt::getCrosshairTarget($player);
if (!$selected instanceof Position) {
return "The block is too far/in the void/in the sky.";
}
}
if ($selected->y < 0 or $selected->y > (defined($path = "pemapmodder\\worldeditart\\MAX_WORLD_HEIGHT") ? constant($path) : 127)) {
return "The selected point is too high/too low.";
}
$selected->getLevel()->loadChunk($selected->x >> 4, $selected->z >> 4);
$selected = Position::fromObject($selected->floor(), $selected->getLevel());
$space = $this->getMain()->getSelection($player);
if ($space instanceof CuboidSpace and $space->getLevel() === $selected->getLevel()) {
if ($this->is2) {
$space->set1($selected);
} else {
$space->set0($selected);
}
goto end;
}
$temp = $this->getMain()->getTempPos($player);
if (is_array($temp) and $temp["#"] !== $this->is2) {
/** @var Position $pos */
$pos = $temp["position"];
if ($pos->getLevel() === $selected->getLevel()) {
if ($this->is2) {
$this->getMain()->setSelection($player, new CuboidSpace($pos, $selected));
} else {
$this->getMain()->setSelection($player, new CuboidSpace($selected, $pos));
}
goto end;
}
}
$this->getMain()->unsetSelection($player);
$this->getMain()->setTempPos($player, $selected, $this->is2);
end:
$space = $this->getMain()->getSelection($player);
if ($space instanceof Space) {
$cnt = count($space);
}
return ($this->is2 ? "Second" : "First") . " position set to " . "({$selected->x}, {$selected->y}, {$selected->z})." . (isset($cnt) ? "\n (Cuboid selected with {$cnt} blocks)" : "");
}
示例15: portalEnter
/**
*
* @param GameLevelModel $lv
* @param Player $player
* @return boolean
*/
public function portalEnter(HungerGamesPlugIn $plugin, GameLevelModel $lv, Player $player)
{
if ($player->getLevel()->getName() != $lv->levelName) {
return true;
}
if ($lv->insideLevelEntracePortal($player->getPosition())) {
if (!isset($this->joinedPlayers[$player->getName()])) {
if ($plugin->storyenforceaccess && $lv->type != 1) {
$w = $plugin->storyManager->hasPlayerWonLevel($player->getName(), $lv->type - 1);
if (!$w) {
$player->sendMessage(TextFormat::RED . "[HG Story Mode Enabled]");
$player->sendMessage(TextFormat::YELLOW . "Required " . TextFormat::GOLD . "WIN " . TextFormat::YELLOW . "previous level before play this level!");
$player->getLevel()->addSound(new LaunchSound($player->getPosition()), array($player));
if ($player->isOp()) {
$player->sendMessage(TextFormat::AQUA . "[Admin BY-PASS Story Mode Checking]");
} else {
$player->teleport($lv->enterpos);
return;
}
}
}
$this->joinedPlayers[$player->getName()] = $player;
$message = TextFormat::GRAY . "[HG] [" . TextFormat::AQUA . $player->getName() . TextFormat::GRAY . "] joined " . $lv->displayName . " [" . TextFormat::GREEN . count($lv->joinedPlayers) . TextFormat::GRAY . " |" . TextFormat::WHITE . "minimal " . TextFormat::YELLOW . $lv->minPlayers . TextFormat::GRAY . "]";
$player->getServer()->broadcastMessage($message, $this->joinedPlayers);
$lv->level->addSound(new DoorSound($player->getPosition()), $lv->joinedPlayers);
$effect = MagicUtil::addEffect($player, Effect::STRENGTH);
if ($effect != null) {
$this->playersWithEffects[$player->getName()] = $effect;
}
if (!$player->isOp()) {
if (!$player->isSurvival()) {
$player->setGamemode(Player::SURVIVAL);
}
}
$player->sendMessage(TextFormat::YELLOW . "[HG] Please wait here");
$player->sendMessage(TextFormat::GRAY . "[HG] The game auto start with minimal players");
}
} else {
if (isset($this->joinedPlayers[$player->getName()])) {
$message = TextFormat::GRAY . "[ " . $player->getName() . " ] left " . $lv->displayName;
$player->getServer()->broadcastMessage($message, $this->joinedPlayers);
$lv->level->addSound(new DoorSound($player), $lv->joinedPlayers);
unset($this->joinedPlayers[$player->getName()]);
if (count($this->joinedPlayers) < $lv->minPlayers) {
$lv->joinDownCounter = $lv->joinDownCounterReset;
}
foreach ($plugin->arenaManager->arenas as &$arena) {
if ($arena instanceof MapArenaModel) {
if (isset($arena->votedPlayers[$player->getName()])) {
unset($arena->votedPlayers[$player->getName()]);
if ($arena->vote >= 1) {
$arena->vote--;
}
break;
}
}
}
if (isset($this->playersWithEffects[$player->getName()])) {
$effect = $this->playersWithEffects[$player->getName()];
if ($effect != null) {
$player->removeEffect($effect->getId());
unset($this->playersWithEffects[$player->getName()]);
}
}
}
}
}