public function makeThreadUnsafe(WorldEditArt $main) { $this->main = $main; if ($this->listener !== null) { $this->listener = $main->getObjectPool()->get($this->listener); } }
public function execute(CommandSender $sender, $alias, array $args) { if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game or through a CCS (run \"ccs\" for help)."); return true; } $session = $this->main->getSessionCollection()->getSession($sender); if ($session === null or !$session->isValid()) { $sender->sendMessage("Your account is still being loaded. Please wait..."); return true; } if ($alias[0] !== "/") { return false; // how come this could even happen! } if ($alias === "/") { $this->displayHelp($sender); return true; } else { $cmdName = substr($alias, 1); var_dump($cmdName); $cmd = $this->findCommand($cmdName); if ($cmd === null) { return false; } $ret = $cmd->run($session, $args); if (is_string($ret)) { $session->sendMessage($ret); } elseif (is_int($ret)) { // TODO } return true; } }
/** * Returns the * * @param Player|string $player the partial name (same rules as {@link \pocketmine\Server#getPlayer}) of the * player, or the {@link Player} object representing the player. * * @return WorldEditSession|null An instance of {@link WorldEditSession} if found, <code>null</code> otherwise. */ public function getSession($player) { if (is_string($player)) { $player = $this->main->getServer()->getPlayer($player); } if (!$player instanceof Player) { return null; } return isset($this->sessions[$player->getId()]) ? $this->sessions[$player->getId()] : null; }
/** * @param string $key * @param string $lang * * @return Phrase|null */ public function get($key, $lang) { if (isset($this->langs[$key])) { if (isset($this->langs[$key][$lang])) { return $this->langs[$key][$lang]; } if (isset($this->langs[$key]["en"])) { return $this->langs[$key]["en"]; } } $this->main->getLogger()->warning("Returning null for unknown translation string ID '{$key}'"); return null; }
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 execute(CommandSender $issuer, $lbl, array $args) { if (count($args) === 0) { $args = ["help"]; } if (is_string($lbl) and substr($lbl, 0, 1) === "/" and strlen($lbl) > 1) { $cmd = substr($lbl, 1); } else { $cmd = array_shift($args); } if (isset($this->subcmds[$cmd = strtolower(trim($cmd))]) and $this->subcmds[$cmd]->valid() and $cmd !== "help") { if ($this->subcmds[$cmd]->get()->hasPermission($issuer)) { if (!IS_DEBUGGING) { try { $this->subcmds[$cmd]->get()->run($this, $args, $issuer); } catch (\Exception $exception) { $issuer->sendMessage("Uh-oh. Something went wrong! An exception has been caught during executing your command."); $issuer->sendMessage("Error caught: " . ($class = array_slice(explode("\\", get_class($exception)), -1)[0])); $issuer->sendMessage("Error message: " . $exception->getMessage()); $issuer->sendMessage("The error has been reported to console."); $this->main->getLogger()->notice("An exception has been caught. Exception name: '{$class}'. Exception message: " . $exception->getMessage()); } } else { $this->subcmds[$cmd]->get()->run($this, $args, $issuer); // let the error fly } } else { $issuer->sendMessage("You either have to select an anchor / make a selection first, don't have permission to do this, or you have to run this command in-game/on-console."); } } else { $help = $this->getFullHelp($issuer); $page = 1; $max = (int) ceil(count($help) / 5); if (isset($args[0])) { $page = max(1, (int) $args[0]); $page = min($max, $page); } $output = "Commands available for you currently: (page {$page} of {$max})\n"; for ($i = ($page - 1) * 5; $i < $page * 5 and isset($help[$i]); $i++) { $output .= $help[$i] . "\n"; } $issuer->sendMessage($output); } return true; }
/** * @param UserConfiguration $config * @param Space[] $selections * @param Bookmark[] $bookmarks * @param int $callbackId */ protected function onLoadedSession(UserConfiguration $config, $selections, $bookmarks, $callbackId) { $session = $this->main->getObjectPool()->get($callbackId); if ($session instanceof WorldEditSession and !$session->isClosed()) { $session->init($config); $session->setSelections($selections); $session->setBookmarks($bookmarks); } }
public function onRun(array $args, Player $player) { if (!isset($args[0])) { return self::WRONG_USE; } $center = $player->floor(); $level = $player->getLevel(); $radius = floatval(array_shift($args)); $height = (int) array_shift($args); $axis = WorldEditArt::directionNumber2Array($player->getDirection()); while (count($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; } $center = $anchor->floor(); break; case "d": $d = array_shift($args); switch (strtolower($d)) { case "m": case "me": break; case "u": case "up": $axis = [CylinderSpace::Y, CylinderSpace::PLUS]; break; case "d": case "down": $axis = [CylinderSpace::Y, CylinderSpace::MINUS]; break; case "l": case "left": $axis = WorldEditArt::directionNumber2Array(WorldEditArt::rotateDirectionNumberClockwise($player->getDirection(), 3)); break; case "r": case "right": $axis = WorldEditArt::directionNumber2Array(WorldEditArt::rotateDirectionNumberClockwise($player->getDirection(), 1)); break; case "b": case "back": $axis = WorldEditArt::directionNumber2Array(WorldEditArt::rotateDirectionNumberClockwise($player->getDirection(), 2)); break; } break; } } $center = Position::fromObject($center, $level); $space = new CylinderSpace($axis[0], $radius, $center, $height * $axis[1]); $this->getMain()->setSelection($player, $space); return "Your selection is now {$space}."; }
/** * @param object $object * * @return int */ public function store($object) { $this->objects[$id = $this->nextId()] = $object; if (count($this->objects) >= $this->main->getConfig()->getNested("advanced.objectPool.warningSize")) { $this->main->getLogger()->warning("OrderedObjectPool size reached " . count($this->objects) . "! Object summary:"); $summary = []; foreach ($this->objects as $obj) { $class = get_class($obj); if (isset($summary[$class])) { $summary[$class]++; } else { $summary[$class] = 1; } } foreach ($summary as $class => $cnt) { $this->main->getLogger()->warning($class . ": {$cnt} entries"); } $this->main->getLogger()->warning("The above is most likely caused by a mistake in code that results in a memory leak. Please report the above to the issue tracker on GitHub at " . TextFormat::LIGHT_PURPLE . "http://lgpe.co/weai/"); } return $id; }
public function __toString() { return "a sphere centered at " . WorldEditArt::posToStr($this->centre) . " of radius {$this->radius}"; }
public function __toString() { return "a cuboid from " . WorldEditArt::v3ToStr($this->raw0) . " to " . WorldEditArt::posToStr($this->raw1); }
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)" : ""); }
public function __toString() { return "a cylinder of axis " . self::axisToStr($this->axis) . " based at " . WorldEditArt::posToStr($this->base) . " with {$this->height} blocks long, with a total of " . count($this->getPosList()) . " blocks."; }
public function update() { $this->main->getPlayerDataProvider()[$this->name] = $this; }