mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Kill off the JSON garbage in commands
kill it with fire!
This commit is contained in:
parent
1a4b653d07
commit
472bf1a1ef
@ -34,8 +34,6 @@ use pocketmine\Server;
|
||||
use pocketmine\utils\TextFormat;
|
||||
|
||||
abstract class Command{
|
||||
/** @var array */
|
||||
private static $defaultDataTemplate = null;
|
||||
|
||||
/** @var string */
|
||||
private $name;
|
||||
@ -48,6 +46,9 @@ abstract class Command{
|
||||
/** @var string */
|
||||
private $label;
|
||||
|
||||
/** @var string[] */
|
||||
private $aliases = [];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
@ -62,6 +63,9 @@ abstract class Command{
|
||||
/** @var string */
|
||||
protected $usageMessage;
|
||||
|
||||
/** @var string|null */
|
||||
private $permission = null;
|
||||
|
||||
/** @var string */
|
||||
private $permissionMessage = null;
|
||||
|
||||
@ -75,7 +79,6 @@ abstract class Command{
|
||||
* @param string[] $aliases
|
||||
*/
|
||||
public function __construct(string $name, string $description = "", string $usageMessage = null, array $aliases = []){
|
||||
$this->commandData = self::generateDefaultData();
|
||||
$this->name = $name;
|
||||
$this->setLabel($name);
|
||||
$this->setDescription($description);
|
||||
@ -83,45 +86,6 @@ abstract class Command{
|
||||
$this->setAliases($aliases);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing command data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDefaultCommandData() : array{
|
||||
return $this->commandData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates modified command data for the specified player
|
||||
* for AvailableCommandsPacket.
|
||||
*
|
||||
* @param Player $player
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function generateCustomCommandData(Player $player) : array{
|
||||
//TODO: fix command permission filtering on join
|
||||
/*if(!$this->testPermissionSilent($player)){
|
||||
return null;
|
||||
}*/
|
||||
$customData = $this->commandData;
|
||||
$customData["aliases"] = $this->getAliases();
|
||||
/*foreach($customData["overloads"] as $overloadName => $overload){
|
||||
if(isset($overload["pocketminePermission"]) and !$player->hasPermission($overload["pocketminePermission"])){
|
||||
unset($customData["overloads"][$overloadName]);
|
||||
}
|
||||
}*/
|
||||
return $customData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOverloads() : array{
|
||||
return $this->commandData["overloads"];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CommandSender $sender
|
||||
* @param string $commandLabel
|
||||
@ -142,7 +106,7 @@ abstract class Command{
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPermission(){
|
||||
return $this->commandData["pocketminePermission"] ?? null;
|
||||
return $this->permission;
|
||||
}
|
||||
|
||||
|
||||
@ -150,11 +114,7 @@ abstract class Command{
|
||||
* @param string|null $permission
|
||||
*/
|
||||
public function setPermission(string $permission = null){
|
||||
if($permission !== null){
|
||||
$this->commandData["pocketminePermission"] = $permission;
|
||||
}else{
|
||||
unset($this->commandData["pocketminePermission"]);
|
||||
}
|
||||
$this->permission = $permission;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -242,7 +202,7 @@ abstract class Command{
|
||||
public function unregister(CommandMap $commandMap) : bool{
|
||||
if($this->allowChangesFrom($commandMap)){
|
||||
$this->commandMap = null;
|
||||
$this->activeAliases = $this->commandData["aliases"];
|
||||
$this->activeAliases = $this->aliases;
|
||||
$this->label = $this->nextLabel;
|
||||
|
||||
return true;
|
||||
@ -285,7 +245,7 @@ abstract class Command{
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription() : string{
|
||||
return $this->commandData["description"];
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -299,9 +259,9 @@ abstract class Command{
|
||||
* @param string[] $aliases
|
||||
*/
|
||||
public function setAliases(array $aliases){
|
||||
$this->commandData["aliases"] = $aliases;
|
||||
$this->aliases = $aliases;
|
||||
if(!$this->isRegistered()){
|
||||
$this->activeAliases = (array) $aliases;
|
||||
$this->activeAliases = $aliases;
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,7 +269,7 @@ abstract class Command{
|
||||
* @param string $description
|
||||
*/
|
||||
public function setDescription(string $description){
|
||||
$this->commandData["description"] = $description;
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -326,16 +286,6 @@ abstract class Command{
|
||||
$this->usageMessage = $usage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
final public static function generateDefaultData() : array{
|
||||
if(self::$defaultDataTemplate === null){
|
||||
self::$defaultDataTemplate = json_decode(file_get_contents(Server::getInstance()->getFilePath() . "src/pocketmine/resources/command_default.json"), true);
|
||||
}
|
||||
return self::$defaultDataTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CommandSender $source
|
||||
* @param TextContainer|string $message
|
||||
|
@ -1,19 +0,0 @@
|
||||
{
|
||||
"aliases": [],
|
||||
"description": "insert_description_here",
|
||||
"overloads": {
|
||||
"default": {
|
||||
"input": {
|
||||
"parameters": [
|
||||
{
|
||||
"name": "args",
|
||||
"type": "rawtext",
|
||||
"optional": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"output": {}
|
||||
}
|
||||
},
|
||||
"permission": "any"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user