mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Merge branch 'master' into api3/network
This commit is contained in:
@ -32,12 +32,12 @@ use pocketmine\Server;
|
||||
use pocketmine\utils\TextFormat;
|
||||
|
||||
abstract class Command{
|
||||
/** @var \stdClass */
|
||||
/** @var array */
|
||||
private static $defaultDataTemplate = null;
|
||||
|
||||
/** @var string */
|
||||
private $name;
|
||||
/** @var \stdClass */
|
||||
/** @var array */
|
||||
protected $commandData = null;
|
||||
|
||||
/** @var string */
|
||||
@ -87,11 +87,11 @@ abstract class Command{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an \stdClass containing command data
|
||||
* Returns an array containing command data
|
||||
*
|
||||
* @return \stdClass
|
||||
* @return array
|
||||
*/
|
||||
public function getDefaultCommandData() : \stdClass{
|
||||
public function getDefaultCommandData() : array{
|
||||
return $this->commandData;
|
||||
}
|
||||
|
||||
@ -101,25 +101,28 @@ abstract class Command{
|
||||
*
|
||||
* @param Player $player
|
||||
*
|
||||
* @return \stdClass|null
|
||||
* @return array
|
||||
*/
|
||||
public function generateCustomCommandData(Player $player){
|
||||
//TODO: fix command permission filtering on join
|
||||
/*if(!$this->testPermissionSilent($player)){
|
||||
return null;
|
||||
}*/
|
||||
$customData = clone $this->commandData;
|
||||
$customData->aliases = $this->getAliases();
|
||||
/*foreach($customData->overloads as &$overload){
|
||||
if(isset($overload->pocketminePermission) and !$player->hasPermission($overload->pocketminePermission)){
|
||||
unset($overload);
|
||||
$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;
|
||||
}
|
||||
|
||||
public function getOverloads(): \stdClass{
|
||||
return $this->commandData->overloads;
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getOverloads(): array{
|
||||
return $this->commandData["overloads"];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,7 +145,7 @@ abstract class Command{
|
||||
* @return string
|
||||
*/
|
||||
public function getPermission(){
|
||||
return $this->commandData->pocketminePermission ?? null;
|
||||
return $this->commandData["pocketminePermission"] ?? null;
|
||||
}
|
||||
|
||||
|
||||
@ -151,9 +154,9 @@ abstract class Command{
|
||||
*/
|
||||
public function setPermission($permission){
|
||||
if($permission !== null){
|
||||
$this->commandData->pocketminePermission = $permission;
|
||||
$this->commandData["pocketminePermission"] = $permission;
|
||||
}else{
|
||||
unset($this->commandData->pocketminePermission);
|
||||
unset($this->commandData["pocketminePermission"]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -239,7 +242,7 @@ abstract class Command{
|
||||
public function unregister(CommandMap $commandMap){
|
||||
if($this->allowChangesFrom($commandMap)){
|
||||
$this->commandMap = null;
|
||||
$this->activeAliases = $this->commandData->aliases;
|
||||
$this->activeAliases = $this->commandData["aliases"];
|
||||
$this->label = $this->nextLabel;
|
||||
|
||||
return true;
|
||||
@ -282,7 +285,7 @@ abstract class Command{
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(){
|
||||
return $this->commandData->description;
|
||||
return $this->commandData["description"];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -296,7 +299,7 @@ abstract class Command{
|
||||
* @param string[] $aliases
|
||||
*/
|
||||
public function setAliases(array $aliases){
|
||||
$this->commandData->aliases = $aliases;
|
||||
$this->commandData["aliases"] = $aliases;
|
||||
if(!$this->isRegistered()){
|
||||
$this->activeAliases = (array) $aliases;
|
||||
}
|
||||
@ -306,7 +309,7 @@ abstract class Command{
|
||||
* @param string $description
|
||||
*/
|
||||
public function setDescription($description){
|
||||
$this->commandData->description = $description;
|
||||
$this->commandData["description"] = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -323,11 +326,14 @@ abstract class Command{
|
||||
$this->usageMessage = $usage;
|
||||
}
|
||||
|
||||
public static final function generateDefaultData() : \stdClass{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static final function generateDefaultData() : array{
|
||||
if(self::$defaultDataTemplate === null){
|
||||
self::$defaultDataTemplate = json_decode(file_get_contents(Server::getInstance()->getFilePath() . "src/pocketmine/resources/command_default.json"));
|
||||
self::$defaultDataTemplate = json_decode(file_get_contents(Server::getInstance()->getFilePath() . "src/pocketmine/resources/command_default.json"), true);
|
||||
}
|
||||
return clone self::$defaultDataTemplate;
|
||||
return self::$defaultDataTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,15 +177,35 @@ class SimpleCommandMap implements CommandMap{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function dispatch(CommandSender $sender, $commandLine){
|
||||
$args = explode(" ", $commandLine);
|
||||
/**
|
||||
* Returns a command to match the specified command line, or null if no matching command was found.
|
||||
* This method is intended to provide capability for handling commands with spaces in their name.
|
||||
* The referenced parameters will be modified accordingly depending on the resulting matched command.
|
||||
*
|
||||
* @param string &$commandName
|
||||
* @param string[] &$args
|
||||
*
|
||||
* @return Command|null
|
||||
*/
|
||||
public function matchCommand(string &$commandName, array &$args){
|
||||
$count = max(count($args), 255);
|
||||
|
||||
if(count($args) === 0){
|
||||
return false;
|
||||
for($i = 0; $i < $count; ++$i){
|
||||
$commandName .= array_shift($args);
|
||||
if(($command = $this->getCommand($commandName)) instanceof Command){
|
||||
return $command;
|
||||
}
|
||||
|
||||
$commandName .= " ";
|
||||
}
|
||||
|
||||
$sentCommandLabel = strtolower(array_shift($args));
|
||||
$target = $this->getCommand($sentCommandLabel);
|
||||
return null;
|
||||
}
|
||||
|
||||
public function dispatch(CommandSender $sender, $commandLine){
|
||||
$args = explode(" ", $commandLine);
|
||||
$sentCommandLabel = "";
|
||||
$target = $this->matchCommand($sentCommandLabel, $args);
|
||||
|
||||
if($target === null){
|
||||
return false;
|
||||
@ -213,11 +233,7 @@ class SimpleCommandMap implements CommandMap{
|
||||
}
|
||||
|
||||
public function getCommand($name){
|
||||
if(isset($this->knownCommands[$name])){
|
||||
return $this->knownCommands[$name];
|
||||
}
|
||||
|
||||
return null;
|
||||
return $this->knownCommands[$name] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -235,7 +251,7 @@ class SimpleCommandMap implements CommandMap{
|
||||
$values = $this->server->getCommandAliases();
|
||||
|
||||
foreach($values as $alias => $commandStrings){
|
||||
if(strpos($alias, ":") !== false or strpos($alias, " ") !== false){
|
||||
if(strpos($alias, ":") !== false){
|
||||
$this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.command.alias.illegal", [$alias]));
|
||||
continue;
|
||||
}
|
||||
@ -243,20 +259,33 @@ class SimpleCommandMap implements CommandMap{
|
||||
$targets = [];
|
||||
|
||||
$bad = "";
|
||||
$recursive = "";
|
||||
foreach($commandStrings as $commandString){
|
||||
$args = explode(" ", $commandString);
|
||||
$command = $this->getCommand($args[0]);
|
||||
$commandName = "";
|
||||
$command = $this->matchCommand($commandName, $args);
|
||||
|
||||
|
||||
if($command === null){
|
||||
if(strlen($bad) > 0){
|
||||
$bad .= ", ";
|
||||
}
|
||||
$bad .= $commandString;
|
||||
}elseif($commandName === $alias){
|
||||
if($recursive !== ""){
|
||||
$recursive .= ", ";
|
||||
}
|
||||
$recursive .= $commandString;
|
||||
}else{
|
||||
$targets[] = $commandString;
|
||||
}
|
||||
}
|
||||
|
||||
if($recursive !== ""){
|
||||
$this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.command.alias.recursive", [$alias, $recursive]));
|
||||
continue;
|
||||
}
|
||||
|
||||
if(strlen($bad) > 0){
|
||||
$this->server->getLogger()->warning($this->server->getLanguage()->translateString("pocketmine.command.alias.notFound", [$alias, $bad]));
|
||||
continue;
|
||||
|
Reference in New Issue
Block a user