diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index ed65cfce..e6cae7ba 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -150,7 +150,11 @@ class ConsoleAPI{ } public function alias($alias, $cmd){ + if(!isset($this->cmds[$cmd])){ + return false; + } $this->cmds[strtolower(trim($alias))] = &$this->cmds[$cmd]; + return true; } public function register($cmd, $help, $callback){ @@ -161,21 +165,25 @@ class ConsoleAPI{ $this->cmds[$cmd] = $callback; $this->help[$cmd] = $help; } + + public function run($line = ""){ + if($line != ""){ + $params = explode(" ", $line); + $cmd = strtolower(array_shift($params)); + console("[INFO] Issued server command: /$cmd ".implode(" ", $params)); + if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){ + call_user_func($this->cmds[$cmd], $cmd, $params); + }elseif($this->server->api->dhandle("api.console.command", array("cmd" => $cmd, "params" => $params)) !== false){ + $this->defaultCommands($cmd, $params); + } + } + } public function handle($time){ if($this->loop->line !== false){ $line = trim($this->loop->line); $this->loop->line = false; - if($line !== ""){ - $params = explode(" ", $line); - $cmd = strtolower(array_shift($params)); - console("[INFO] Issued server command: /$cmd ".implode(" ", $params)); - if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){ - call_user_func($this->cmds[$cmd], $cmd, $params); - }elseif($this->server->api->dhandle("api.console.command", array("cmd" => $cmd, "params" => $params)) !== false){ - $this->defaultCommands($cmd, $params); - } - } + $this->run($line); }else{ $this->loop->notify(); }