mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 16:24:05 +00:00
Drop support for commands with spaces in the names
the use case for this is basically zero, since the community prefers implementing their own subcommand systems instead (which are much more flexible). In addition, allowing spaces in command names makes it extra complicated to display helpful information to the user, such as the command that was actually accepted by the command map (which would be useful for identifying accidental invisible characters / control characters when sending commands).
This commit is contained in:
parent
e140614a63
commit
7919a1a1c5
@ -200,29 +200,6 @@ class SimpleCommandMap implements CommandMap{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 reference parameter
|
||||
* @param string[] $args reference parameter
|
||||
*/
|
||||
public function matchCommand(string &$commandName, array &$args) : ?Command{
|
||||
$count = min(count($args), 255);
|
||||
|
||||
for($i = 0; $i < $count; ++$i){
|
||||
$commandName .= array_shift($args);
|
||||
if(($command = $this->getCommand($commandName)) instanceof Command){
|
||||
return $command;
|
||||
}
|
||||
|
||||
$commandName .= " ";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function dispatch(CommandSender $sender, string $commandLine) : bool{
|
||||
$args = [];
|
||||
preg_match_all('/"((?:\\\\.|[^\\\\"])*)"|(\S+)/u', $commandLine, $matches);
|
||||
@ -234,9 +211,11 @@ class SimpleCommandMap implements CommandMap{
|
||||
}
|
||||
}
|
||||
}
|
||||
$sentCommandLabel = "";
|
||||
$target = $this->matchCommand($sentCommandLabel, $args);
|
||||
|
||||
$sentCommandLabel = array_shift($args);
|
||||
if($sentCommandLabel === null){
|
||||
return false;
|
||||
}
|
||||
$target = $this->getCommand($sentCommandLabel);
|
||||
if($target === null){
|
||||
return false;
|
||||
}
|
||||
@ -288,8 +267,8 @@ class SimpleCommandMap implements CommandMap{
|
||||
|
||||
foreach($commandStrings as $commandString){
|
||||
$args = explode(" ", $commandString);
|
||||
$commandName = "";
|
||||
$command = $this->matchCommand($commandName, $args);
|
||||
$commandName = array_shift($args);
|
||||
$command = $this->getCommand($commandName);
|
||||
|
||||
if($command === null){
|
||||
$bad[] = $commandString;
|
||||
|
Loading…
x
Reference in New Issue
Block a user