mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-06 01:51:51 +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){
|
public function alias($alias, $cmd){
|
||||||
|
if(!isset($this->cmds[$cmd])){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$this->cmds[strtolower(trim($alias))] = &$this->cmds[$cmd];
|
$this->cmds[strtolower(trim($alias))] = &$this->cmds[$cmd];
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function register($cmd, $help, $callback){
|
public function register($cmd, $help, $callback){
|
||||||
@ -162,20 +166,24 @@ class ConsoleAPI{
|
|||||||
$this->help[$cmd] = $help;
|
$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){
|
public function handle($time){
|
||||||
if($this->loop->line !== false){
|
if($this->loop->line !== false){
|
||||||
$line = trim($this->loop->line);
|
$line = trim($this->loop->line);
|
||||||
$this->loop->line = false;
|
$this->loop->line = false;
|
||||||
if($line !== ""){
|
$this->run($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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
$this->loop->notify();
|
$this->loop->notify();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user