Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace pocketmine\command;

use pocketmine\command\utils\CommandException;
use pocketmine\command\utils\CommandStringHelper;
use pocketmine\lang\KnownTranslationFactory;
use pocketmine\lang\Translatable;
use pocketmine\permission\PermissionManager;
Expand Down Expand Up @@ -80,6 +81,13 @@ public function __construct(string $name, Translatable|string $description = "",
$this->setAliases($aliases);
}

public function executeRaw(CommandSender $sender, string $commandLabel, string $argLine) : void{
if($this->testPermission($sender)){
$args = CommandStringHelper::parseQuoteAware($argLine);
$this->execute($sender, $commandLabel, $args);
}
}

/**
* @param string[] $args
* @phpstan-param list<string> $args
Expand Down
32 changes: 16 additions & 16 deletions src/command/SimpleCommandMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
use function array_values;
use function count;
use function implode;
use function preg_split;
use function str_contains;
use function strcasecmp;
use function strtolower;
Expand Down Expand Up @@ -207,26 +208,25 @@ private function registerAlias(Command $command, bool $isAlias, string $fallback
}

public function dispatch(CommandSender $sender, string $commandLine) : bool{
$args = CommandStringHelper::parseQuoteAware($commandLine);

$sentCommandLabel = array_shift($args);
if($sentCommandLabel !== null && ($target = $this->getCommand($sentCommandLabel)) !== null){
$timings = Timings::getCommandDispatchTimings($target->getLabel());
$timings->startTiming();

try{
if($target->testPermission($sender)){
$target->execute($sender, $sentCommandLabel, $args);
$sentCommandLabel = "";
if(($parts = preg_split('/\s+/u', $commandLine, 2)) !== false){
$sentCommandLabel = $parts[0];
if(($target = $this->getCommand($sentCommandLabel)) !== null){
$timings = Timings::getCommandDispatchTimings($target->getLabel());
$timings->startTiming();

try{
$target->executeRaw($sender, $sentCommandLabel, $parts[1] ?? "");
}catch(InvalidCommandSyntaxException $e){
$sender->sendMessage($sender->getLanguage()->translate(KnownTranslationFactory::commands_generic_usage($target->getUsage())));
}finally{
$timings->stopTiming();
}
}catch(InvalidCommandSyntaxException $e){
$sender->sendMessage($sender->getLanguage()->translate(KnownTranslationFactory::commands_generic_usage($target->getUsage())));
}finally{
$timings->stopTiming();
return true;
}
return true;
}

$sender->sendMessage(KnownTranslationFactory::pocketmine_command_notFound($sentCommandLabel ?? "", "/help")->prefix(TextFormat::RED));
$sender->sendMessage(KnownTranslationFactory::pocketmine_command_notFound($sentCommandLabel, "/help")->prefix(TextFormat::RED));
return false;
}

Expand Down