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; } }
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)" : ""); }