diff --git a/README.md b/README.md index 8a79130..38e1ca2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,48 @@ MineReset ========= -MineReset is a powerful mine management tool for PocketMine-MP. It allows for the creation of ratio based, resettable mines. \ No newline at end of file +MineReset is a fancy tool which allows you to create resettable mines the right way. It has been entirely rewritten in version 3.0. + + +## Commands + +### /mine create \ +**minereset.command.create** + +This command must be run in game. It will start the creation wizard to create a mine with the specified name. This will require you to tap two points to be the corner blocks of the mine. Upon tapping the second block, the mine will be created and saved. + + +### /mine set \ \ +**minereset.command.set** + +In order for MineReset to reset a mine, it needs to know what blocks to put in it and what how often each block should occur. You must specify this in the form ` `. So if I wanted mine A to have 50% stone and 50% air, I would run `/mine set A 1 50 0 50`. MineReset can handle metadata for blocks in the form `: `. + + +### /mine reset \ +**minereset.command.reset** + +This command wil trigger a manual reset if there is not already one ongoing. Mines are reset in the following way +1. Chunks in the mine are collected and turned into raw data. +2. These chunks are loaded and modfied in a seperate task (PocketMine can keep running at the same time). +3. The chunks are transferred back to PocketMine and set in bulk. + +This means that any changes you make to the chunks while the mine is resetting will have no effect and MineReset will attempt to block you. + +### /mine reset-all +**minereset.command.resetall** + +This command will dispatch a reset for each mine. + +### /mine destroy \[code] +**minereset.command.destroy** + +This command will irreversible delete a mine. When running this command you will be asked to confirm your action by re-running the command with a confirmation code. If you would like to avoid confirming, you should edit the `mines.yml` file directly. + +### /mine list +**minereset.command.list** + +This command will list out all existing mines. + +### /mine about +**minereset.command.about** + +This command will display a little info blurb downloaded from the web. diff --git a/src/falkirks/minereset/MineReset.php b/src/falkirks/minereset/MineReset.php index 7348543..1c1a26b 100644 --- a/src/falkirks/minereset/MineReset.php +++ b/src/falkirks/minereset/MineReset.php @@ -37,7 +37,7 @@ class MineReset extends PluginBase{ /** @var MineCommand */ private $mainCommand; /** @var bool */ - private static $supportsChunkSetting; + private static $supportsChunkSetting = null; /** @var CreationListener */ private $creationListener; @@ -60,14 +60,13 @@ public function onEnable(){ $this->mainCommand = new MineCommand($this); $this->getServer()->getCommandMap()->register("minereset", $this->mainCommand); - $this->mainCommand->registerSubCommand("about", new AboutCommand($this)); - $this->mainCommand->registerSubCommand("list", new ListCommand($this)); - $this->mainCommand->registerSubCommand("create", new CreateCommand($this)); - $this->mainCommand->registerSubCommand("set", new SetCommand($this)); - $this->mainCommand->registerSubCommand("destroy", new DestroyCommand($this)); - $this->mainCommand->registerSubCommand("create", new CreateCommand($this)); - $this->mainCommand->registerSubCommand("reset", new ResetCommand($this)); - $this->mainCommand->registerSubCommand("reset-all", new ResetAllCommand($this)); + $this->mainCommand->registerSubCommand("about", new AboutCommand($this), ['a']); + $this->mainCommand->registerSubCommand("list", new ListCommand($this), ['l']); + $this->mainCommand->registerSubCommand("create", new CreateCommand($this), ['c']); + $this->mainCommand->registerSubCommand("set", new SetCommand($this), ['s']); + $this->mainCommand->registerSubCommand("destroy", new DestroyCommand($this), ['d']); + $this->mainCommand->registerSubCommand("reset", new ResetCommand($this), ['r']); + $this->mainCommand->registerSubCommand("reset-all", new ResetAllCommand($this), ['ra']); if(!self::supportsChunkSetting()){ $this->getLogger()->warning("Your server does not support setting chunks without unloading them. This will cause tiles and entities to be lost when resetting mines. Upgrade to a newer pmmp to resolve this."); @@ -120,15 +119,17 @@ public static function supportsChunkSetting(): bool { } private static function detectChunkSetting(){ - $class = new \ReflectionClass(Level::class); - $func = $class->getMethod("setChunk"); - $filename = $func->getFileName(); - $start_line = $func->getStartLine() - 1; - $end_line = $func->getEndLine(); - $length = $end_line - $start_line; - - $source = file($filename); - $body = implode("", array_slice($source, $start_line, $length)); - self::$supportsChunkSetting = strpos($body, 'removeEntity') !== false; + if(self::$supportsChunkSetting === null) { + $class = new \ReflectionClass(Level::class); + $func = $class->getMethod("setChunk"); + $filename = $func->getFileName(); + $start_line = $func->getStartLine() - 1; + $end_line = $func->getEndLine(); + $length = $end_line - $start_line; + + $source = file($filename); + $body = implode("", array_slice($source, $start_line, $length)); + self::$supportsChunkSetting = strpos($body, 'removeEntity') !== false; + } } } \ No newline at end of file diff --git a/src/falkirks/minereset/command/MineCommand.php b/src/falkirks/minereset/command/MineCommand.php index 56068f0..fb69dc3 100644 --- a/src/falkirks/minereset/command/MineCommand.php +++ b/src/falkirks/minereset/command/MineCommand.php @@ -43,7 +43,13 @@ public function getPlugin(): Plugin{ return $this->api; } - public function registerSubCommand(string $name, SubCommand $command){ + public function registerSubCommand(string $name, SubCommand $command, $aliases = []){ $this->subCommands[$name] = $command; + + foreach ($aliases as $alias){ + if(!isset($this->subCommands[$alias])){ + $this->registerSubCommand($alias, $command); + } + } } } \ No newline at end of file