Better Console Alias

This commit is contained in:
Shoghi Cervantes Pueyo 2013-02-08 17:46:05 +01:00
parent 967a929723
commit 90c8ac1461
2 changed files with 15 additions and 9 deletions

View File

@ -47,6 +47,10 @@ class BanAPI{
$this->server->api->console->register("whitelist", "Manages White-listing", array($this, "commandHandler"));
$this->server->api->console->register("op", "Ops a player", array($this, "commandHandler"));
$this->server->api->console->register("deop", "Deops a player", array($this, "commandHandler"));
$this->server->api->console->alias("ban-ip", "banip add");
$this->server->api->console->alias("banlist", "ban list");
$this->server->api->console->alias("pardon", "ban remove");
$this->server->api->console->alias("pardon-ip", "banip remove");
$this->server->addHandler("console.command", array($this, "opCheck"), 1);
}

View File

@ -26,10 +26,11 @@ the Free Software Foundation, either version 3 of the License, or
*/
class ConsoleAPI{
private $loop, $server, $event, $help, $cmds;
private $loop, $server, $event, $help, $cmds, $alias;
function __construct(PocketMinecraftServer $server){
$this->help = array();
$this->cmds = array();
$this->alias = array();
$this->server = $server;
$this->last = microtime(true);
}
@ -143,10 +144,7 @@ class ConsoleAPI{
}
public function alias($alias, $cmd){
if(!isset($this->cmds[$cmd])){
return false;
}
$this->cmds[strtolower(trim($alias))] = &$this->cmds[$cmd];
$this->alias[strtolower(trim($alias))] = trim($cmd);
return true;
}
@ -163,6 +161,10 @@ class ConsoleAPI{
if($line != ""){
$params = explode(" ", $line);
$cmd = strtolower(array_shift($params));
if(isset($this->alias[$cmd])){
$this->run($this->alias[$cmd] . " " .implode(" ", $params), $issuer);
return;
}
if($issuer instanceof Player){
console("[INFO] \"".$issuer->username."\" issued server command: /$cmd ".implode(" ", $params));
}else{
@ -179,11 +181,11 @@ class ConsoleAPI{
}
}
if($output != "" and ($issuer instanceof Player)){
$issuer->sendChat($output);
}elseif($output != ""){
$mes = explode("\n", $output);
$issuer->sendChat(trim($output));
}elseif($output != "" and $issuer === "console"){
$mes = explode("\n", trim($output));
foreach($mes as $m){
console($m);
console("[CMD] ".$m);
}
}