From 90c8ac1461cd5988f47ef5895220358cd877e231 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Fri, 8 Feb 2013 17:46:05 +0100 Subject: [PATCH] Better Console Alias --- src/API/BanAPI.php | 4 ++++ src/API/ConsoleAPI.php | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/API/BanAPI.php b/src/API/BanAPI.php index 4fedca38d..2fb16f0f7 100644 --- a/src/API/BanAPI.php +++ b/src/API/BanAPI.php @@ -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); } diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index e113781b8..ef9d0c27f 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -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); } }