public function onRun(array $args, Space $space, Player $player) { if (!isset($args[0])) { return self::WRONG_USE; } $name = array_shift($args); $block = BlockList::getBlockFronString($name); if ($block === null) { return self::NO_BLOCK; } $duration = 300; while (isset($args[0])) { $arg = array_shift($args); if (is_numeric($arg)) { $duration = intval($arg) * 20; } else { $replaces = BlockList::getBlockArrayFromString($arg); } } if (isset($replaces)) { $space->replaceBlocks($replaces, $block, true, $player); } else { $space->setBlocks($block, $player); } $this->getMain()->getServer()->getScheduler()->scheduleDelayedTask(new UndoTestTask($this->getMain(), $space), $duration); return "Previewing the selection for " . $duration / 20 . " seconds."; }
public function onRun(array $args, Space $space) { if (!isset($args[0])) { return self::WRONG_USE; } $name = array_shift($args); $perc = strpos($name, "%") !== false; if (($pos = strpos($name, ",")) !== false) { if (strpos(substr($name, $pos), ",") === false) { if (!$this->twoNo and !$perc) { return "Setting two block types without percentage is disabled on this server."; } if (!$this->twoYes and $perc) { return "Setting two block types with percentage is disabled on this server."; } if (!$this->mulNo and !$perc) { return "Setting multiple block types without percentage is disabled on this server."; } if (!$this->mulYes and $perc) { return "Setting multiple block types with percentage is disabled on this server."; } } try { $list = new BlockList($name); } catch (BlockPatternParseException $e) { return "The following pattern error occurred: " . $e->getMessage(); } } else { $block = BlockList::getBlockFronString($name); if ($block === null) { return self::NO_BLOCK; } $list = new SingleList($block); } $hollow = false; $update = false; while (isset($args[0])) { $arg = array_shift($args); switch ($arg) { case "h": case "hollow": $hollow = true; case "nu": case "no-update": $update = true; break; } } if ($hollow) { $cnt = $space->randomHollow($list, $update); } else { $cnt = $space->randomPlaces($list, $update); } return "{$cnt} block(s) have been changed."; }
public function onRun(array $args, Space $space) { if (!isset($args[1])) { return self::WRONG_USE; } $from = BlockList::getBlockArrayFromString(array_shift($args)); $targets = array_shift($args); $perc = strpos($targets, "%") !== false; $pos = strpos($targets, ","); if ($pos === false) { if (strpos(substr($targets, $pos), ",") === false) { if (!$this->twoNo and !$perc) { return "Replacing blocks into two block types without percentage is disabled on this server."; } if (!$this->twoYes and $perc) { return "Replacing blocks into two block types with percentage is disabled on this server."; } } else { if (!$this->mulNo and !$perc) { return "Replacing blocks into multiple block types without percentage is disabled on this server."; } if (!$this->mulYes and $perc) { return "Replacing blocks into multiple block types with percentage is disabled on this server."; } } $to = new BlockList($targets); } else { $to = new SingleList(BlockList::getBlockFronString($targets)); } $hollow = false; $update = true; while (isset($args[0])) { switch ($arg = strtolower(array_shift($args))) { case "h": case "hollow": $hollow = true; break; case "nu": case "no-update": $update = false; break; } } if ($hollow) { $cnt = $space->randomHollowReplace($from, $to, $update); } else { $cnt = $space->randomReplaces($from, $to, $update); } return "{$cnt} block(s) have been changed."; }
public function randomHollowReplace($froms, BlockList $list, $update = true) { $cnt = 0; foreach ($this->getMarginBlockList() as $b) { $equal = false; foreach ($froms as $from) { if (self::equals($from, $b)) { $equal = true; break; } } if ($equal) { $this->getLevel()->setBlock($b, $list->getRandom(), false, $update); $cnt++; } } return $cnt; }