pocketmine\command\SimpleCommandMap::dispatch PHP Метод

dispatch() публичный Метод

public dispatch ( pocketmine\command\CommandSender $sender, $commandLine )
$sender pocketmine\command\CommandSender
    public function dispatch(CommandSender $sender, $commandLine)
    {
        $args = explode(" ", $commandLine);
        if (count($args) === 0) {
            return false;
        }
        $sentCommandLabel = strtolower(array_shift($args));
        $target = $this->getCommand($sentCommandLabel);
        if ($target === null) {
            return false;
        }
        $target->timings->startTiming();
        try {
            if ($this->server->advancedCommandSelector) {
                $this->dispatchAdvanced($sender, $target, $sentCommandLabel, $args);
            } else {
                $target->execute($sender, $sentCommandLabel, $args);
            }
        } catch (\Throwable $e) {
            $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.exception"));
            $this->server->getLogger()->critical($this->server->getLanguage()->translateString("pocketmine.command.exception", [$commandLine, (string) $target, $e->getMessage()]));
            $logger = $sender->getServer()->getLogger();
            if ($logger instanceof MainLogger) {
                $logger->logException($e);
            }
        }
        $target->timings->stopTiming();
        return true;
    }

Usage Example

Пример #1
1
 /**
  * Executes a command from a CommandSender
  *
  * @param CommandSender $sender
  * @param string        $commandLine
  *
  * @return bool
  *
  * @throws \Exception
  */
 public function dispatchCommand(CommandSender $sender, $commandLine)
 {
     if (!$sender instanceof CommandSender) {
         throw new ServerException("CommandSender is not valid");
     }
     if ($this->commandMap->dispatch($sender, $commandLine)) {
         return true;
     }
     if ($sender instanceof Player) {
         $sender->sendMessage("Unknown command. Type \"/help\" for help.");
     } else {
         $sender->sendMessage("Unknown command. Type \"help\" for help.");
     }
     return false;
 }
All Usage Examples Of pocketmine\command\SimpleCommandMap::dispatch