mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
Added a way to call custom commands in ConsoleAPI
This commit is contained in:
parent
1409a1f7b5
commit
ed61111aca
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user