Skip to content

Commit

Permalink
Added command aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
falkirks committed May 5, 2017
1 parent 5fd04a3 commit 2ce10be
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 21 deletions.
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
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 \<name>
**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 \<name> \<data>
**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 `<ID> <PERCENT>`. 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 `<ID>:<METADATA> <PERCENT>`.


### /mine reset \<name>
**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 <name> \[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.
39 changes: 20 additions & 19 deletions src/falkirks/minereset/MineReset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.");
Expand Down Expand Up @@ -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;
}
}
}
8 changes: 7 additions & 1 deletion src/falkirks/minereset/command/MineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}

0 comments on commit 2ce10be

Please sign in to comment.