When you forgot to commit...

This commit is contained in:
Ad5001 2017-11-08 20:37:34 +01:00
parent 0cb3975928
commit c027a1712a
1 changed files with 7 additions and 7 deletions

View File

@ -51,8 +51,7 @@ class Main extends PluginBase implements Listener {
*/ */
public function onCommandPreProcess(PlayerCommandPreProcessEvent $event): void{ public function onCommandPreProcess(PlayerCommandPreProcessEvent $event): void{
$m = $event->getMessage(); $m = $event->getMessage();
$this->execSelectors($m, $event->getPlayer()); if($this->execSelectors($m, $event->getPlayer())) $event->setCancelled();
$event->setCancelled();
} }
@ -65,8 +64,7 @@ class Main extends PluginBase implements Listener {
*/ */
public function onServerCommand(ServerCommandEvent $event): void{ public function onServerCommand(ServerCommandEvent $event): void{
$m = $event->getCommand(); $m = $event->getCommand();
$this->execSelectors($m, $event->getSender()); if($this->execSelectors($m, $event->getSender())) $event->setCancelled();
$event->setCancelled();
} }
/** /**
@ -74,9 +72,9 @@ class Main extends PluginBase implements Listener {
* *
* @param string $m The command * @param string $m The command
* @param CommandSender $sender * @param CommandSender $sender
* @return void * @return bool - If selectors were found or not.
*/ */
public function execSelectors(string $m, CommandSender $sender): void{ public function execSelectors(string $m, CommandSender $sender): bool{
preg_match_all($this->buildRegExr(), $m, $matches); preg_match_all($this->buildRegExr(), $m, $matches);
$commandsToExecute = [$m]; $commandsToExecute = [$m];
foreach($matches[0] as $index => $match){ foreach($matches[0] as $index => $match){
@ -93,16 +91,18 @@ class Main extends PluginBase implements Listener {
} }
if(count($newCommandsToExecute) == 0) { if(count($newCommandsToExecute) == 0) {
$sender->sendMessage("§cYour selector $match (" . self::$selectors[$matches[1][$index]]->getName() . ") did not mactch any player/entity."); $sender->sendMessage("§cYour selector $match (" . self::$selectors[$matches[1][$index]]->getName() . ") did not mactch any player/entity.");
return; return true;
} }
} }
$commandsToExecute = $newCommandsToExecute; $commandsToExecute = $newCommandsToExecute;
} }
} }
if(!isset($matches[0][0])) return false;
// Then we have all the commands here and we can execute them // Then we have all the commands here and we can execute them
foreach($commandsToExecute as $cmd){ foreach($commandsToExecute as $cmd){
$this->getServer()->dispatchCommand($sender, $cmd); $this->getServer()->dispatchCommand($sender, $cmd);
} }
return true;
} }
/** /**