mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-09 11:31:49 +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;
|
use pocketmine\utils\TextFormat;
|
||||||
|
|
||||||
abstract class Command{
|
abstract class Command{
|
||||||
/** @var array */
|
|
||||||
private static $defaultDataTemplate = null;
|
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $name;
|
private $name;
|
||||||
@ -48,6 +46,9 @@ abstract class Command{
|
|||||||
/** @var string */
|
/** @var string */
|
||||||
private $label;
|
private $label;
|
||||||
|
|
||||||
|
/** @var string[] */
|
||||||
|
private $aliases = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
@ -62,6 +63,9 @@ abstract class Command{
|
|||||||
/** @var string */
|
/** @var string */
|
||||||
protected $usageMessage;
|
protected $usageMessage;
|
||||||
|
|
||||||
|
/** @var string|null */
|
||||||
|
private $permission = null;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $permissionMessage = null;
|
private $permissionMessage = null;
|
||||||
|
|
||||||
@ -75,7 +79,6 @@ abstract class Command{
|
|||||||
* @param string[] $aliases
|
* @param string[] $aliases
|
||||||
*/
|
*/
|
||||||
public function __construct(string $name, string $description = "", string $usageMessage = null, array $aliases = []){
|
public function __construct(string $name, string $description = "", string $usageMessage = null, array $aliases = []){
|
||||||
$this->commandData = self::generateDefaultData();
|
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->setLabel($name);
|
$this->setLabel($name);
|
||||||
$this->setDescription($description);
|
$this->setDescription($description);
|
||||||
@ -83,45 +86,6 @@ abstract class Command{
|
|||||||
$this->setAliases($aliases);
|
$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 CommandSender $sender
|
||||||
* @param string $commandLabel
|
* @param string $commandLabel
|
||||||
@ -142,7 +106,7 @@ abstract class Command{
|
|||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getPermission(){
|
public function getPermission(){
|
||||||
return $this->commandData["pocketminePermission"] ?? null;
|
return $this->permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -150,11 +114,7 @@ abstract class Command{
|
|||||||
* @param string|null $permission
|
* @param string|null $permission
|
||||||
*/
|
*/
|
||||||
public function setPermission(string $permission = null){
|
public function setPermission(string $permission = null){
|
||||||
if($permission !== null){
|
$this->permission = $permission;
|
||||||
$this->commandData["pocketminePermission"] = $permission;
|
|
||||||
}else{
|
|
||||||
unset($this->commandData["pocketminePermission"]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -242,7 +202,7 @@ abstract class Command{
|
|||||||
public function unregister(CommandMap $commandMap) : bool{
|
public function unregister(CommandMap $commandMap) : bool{
|
||||||
if($this->allowChangesFrom($commandMap)){
|
if($this->allowChangesFrom($commandMap)){
|
||||||
$this->commandMap = null;
|
$this->commandMap = null;
|
||||||
$this->activeAliases = $this->commandData["aliases"];
|
$this->activeAliases = $this->aliases;
|
||||||
$this->label = $this->nextLabel;
|
$this->label = $this->nextLabel;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -285,7 +245,7 @@ abstract class Command{
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getDescription() : string{
|
public function getDescription() : string{
|
||||||
return $this->commandData["description"];
|
return $this->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -299,9 +259,9 @@ abstract class Command{
|
|||||||
* @param string[] $aliases
|
* @param string[] $aliases
|
||||||
*/
|
*/
|
||||||
public function setAliases(array $aliases){
|
public function setAliases(array $aliases){
|
||||||
$this->commandData["aliases"] = $aliases;
|
$this->aliases = $aliases;
|
||||||
if(!$this->isRegistered()){
|
if(!$this->isRegistered()){
|
||||||
$this->activeAliases = (array) $aliases;
|
$this->activeAliases = $aliases;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,7 +269,7 @@ abstract class Command{
|
|||||||
* @param string $description
|
* @param string $description
|
||||||
*/
|
*/
|
||||||
public function setDescription(string $description){
|
public function setDescription(string $description){
|
||||||
$this->commandData["description"] = $description;
|
$this->description = $description;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -326,16 +286,6 @@ abstract class Command{
|
|||||||
$this->usageMessage = $usage;
|
$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 CommandSender $source
|
||||||
* @param TextContainer|string $message
|
* @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