Initial working slash commands on 0.16. TODO: new API

This commit is contained in:
Dylan K. Taylor
2016-10-06 11:21:48 +01:00
parent b198f287db
commit 018897062c
3 changed files with 93 additions and 2 deletions

View File

@ -27,6 +27,7 @@ namespace pocketmine\command;
use pocketmine\event\TextContainer;
use pocketmine\event\TimingsHandler;
use pocketmine\event\TranslationContainer;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\utils\TextFormat;
@ -85,6 +86,25 @@ abstract class Command{
$this->timings = new TimingsHandler("** Command: " . $name);
}
public function generateJsonData(Player $player) : array{
/*if(!$this->testPermissionSilent($player)){
return [];
}*/
$data = [
"versions" => [
[
"description" => $this->getDescription(),
"overloads" => $this->getOverloadData(),
"permission" => "any", //TODO: implement vanilla op API
]
]
];
if(count($aliases = $this->getAliases()) > 0){
$data["versions"][0]["aliases"] = $aliases;
}
return $data;
}
/**
* @param CommandSender $sender
* @param string $commandLabel
@ -101,6 +121,34 @@ abstract class Command{
return $this->name;
}
/**
* Returns an array of overload data for generating JSON data for AvailableCommandsPacket
* To show custom usages and command parameters, you MUST override this method and define
* your own parameters and overloads. Omitting this method will cause the generic default
* [args: string] message to be shown.
*
* @return array
*/
public function getOverloadData() : array{
$data = [
"default" => [
"input" => [
"parameters" => [
0 => [ //Default rawtext parameter for old plugins
"name" => "args",
"type" => "rawtext",
"optional" => true
]
]
],
"output" => [
"format_strings" => []
]
]
];
return $data;
}
/**
* @return string
*/