Beispiel #1
0
 public function command(Command\CommandInterface $command, array $args, CommandSender $sender, CommandSender $room)
 {
     $executor = $command->getExecutor();
     if ($executor instanceof Plugin) {
         return $this->getPlugin($executor->name)->command($command, $sender, $room, $args);
     } else {
         $reflection = new \ReflectionClass($executor);
         if ($reflection->hasMethod("onCommand")) {
             return $executor->onCommand($command, $sender, $room, $args);
         }
     }
     return false;
 }
Beispiel #2
0
 /**
  * @param CommandInterface $command
  * @param Plugin|null $plugin
  * @return bool
  */
 public function registerCommand(CommandInterface $command, Plugin $plugin = null) : bool
 {
     if (!$this->hasCommand($command->getCommand())) {
         $ev = new CommandRegisterEvent($command);
         $this->connection->getEventHandler()->callEvent($ev);
         if (!$ev->isCancelled()) {
             $this->commands[$command->getCommand()] = $command;
             foreach ($command->getAliases() as $alias) {
                 if (!$this->hasCommand($alias)) {
                     $this->commands[$alias] = $command;
                 }
             }
             if ($plugin instanceof Plugin) {
                 $this->plugins[$plugin->name][$command->getCommand()] = $command;
             }
             return true;
         }
     }
     return false;
 }