Replace commands.generic.notFound with a custom PM version

this also fixes #4379.
This commit is contained in:
Dylan K. Taylor
2021-10-02 20:42:59 +01:00
parent d63b9d1648
commit 05dc675d5b
5 changed files with 25 additions and 25 deletions

View File

@ -67,6 +67,7 @@ use pocketmine\command\defaults\WhitelistCommand;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\KnownTranslationFactory;
use pocketmine\Server;
use pocketmine\utils\TextFormat;
use function array_shift;
use function count;
use function explode;
@ -210,26 +211,23 @@ class SimpleCommandMap implements CommandMap{
}
}
}
$sentCommandLabel = array_shift($args);
if($sentCommandLabel === null){
return false;
}
$target = $this->getCommand($sentCommandLabel);
if($target === null){
return false;
if($sentCommandLabel !== null && ($target = $this->getCommand($sentCommandLabel)) !== null){
$target->timings->startTiming();
try{
$target->execute($sender, $sentCommandLabel, $args);
}catch(InvalidCommandSyntaxException $e){
$sender->sendMessage($sender->getLanguage()->translate(KnownTranslationFactory::commands_generic_usage($target->getUsage())));
}finally{
$target->timings->stopTiming();
}
return true;
}
$target->timings->startTiming();
try{
$target->execute($sender, $sentCommandLabel, $args);
}catch(InvalidCommandSyntaxException $e){
$sender->sendMessage($sender->getLanguage()->translate(KnownTranslationFactory::commands_generic_usage($target->getUsage())));
}finally{
$target->timings->stopTiming();
}
return true;
$sender->sendMessage(KnownTranslationFactory::pocketmine_command_notFound($sentCommandLabel ?? "", "/help")->prefix(TextFormat::RED));
return false;
}
public function clearCommands() : void{