Rewrite /defaultgamemode command to allow multiple values

This commit is contained in:
Shoghi Cervantes Pueyo 2013-04-20 21:00:52 +02:00
parent d0d8d281d2
commit 269e63ab50
2 changed files with 24 additions and 24 deletions

View File

@ -46,7 +46,7 @@ class ConsoleAPI{
$this->register("say", "<message ...>", array($this, "defaultCommands")); $this->register("say", "<message ...>", array($this, "defaultCommands"));
$this->register("save-all", "", array($this, "defaultCommands")); $this->register("save-all", "", array($this, "defaultCommands"));
$this->register("stop", "", array($this, "defaultCommands")); $this->register("stop", "", array($this, "defaultCommands"));
$this->register("defaultgamemode", "<CREATIVE|SURVIVAL|ADVENTURE|VIEW>", array($this, "defaultCommands")); $this->register("defaultgamemode", "<mode>", array($this, "defaultCommands"));
$this->server->api->ban->cmdWhitelist("help"); $this->server->api->ban->cmdWhitelist("help");
} }
@ -61,28 +61,28 @@ class ConsoleAPI{
$output = ""; $output = "";
switch($cmd){ switch($cmd){
case "defaultgamemode": case "defaultgamemode":
$p = strtolower(array_shift($params)); $gms = array(
switch($p){ "0" => SURVIVAL,
case "creative": "survival" => SURVIVAL,
$output .= "Default Gamemode is now Creative\n"; "s" => SURVIVAL,
$this->server->gamemode = CREATIVE; "1" => CREATIVE,
break; "creative" => CREATIVE,
case "survival": "c" => CREATIVE,
$output .= "Default Gamemode is now Survival\n"; "2" => ADVENTURE,
$this->server->gamemode = SURVIVAL; "adventure" => ADVENTURE,
break; "a" => ADVENTURE,
case "adventure": "3" => VIEW,
$output .= "Default Gamemode is now Adventure\n"; "view" => VIEW,
$this->server->gamemode = ADVENTURE; "viewer" => VIEW,
break; "spectator" => VIEW,
case "view": "v" => VIEW,
$output .= "Default Gamemode is now View\n"; );
$this->server->gamemode = VIEW; if(!isset($gms[strtolower($params[0])])){
break; $output .= "Usage: /$cmd <mode>\n";
default:
$output .= "Usage: /defaultgamemode <CREATIVE|SURVIVAL|ADVENTURE|VIEW>\n";
break; break;
} }
$this->server->api->setProperty("gamemode", $gms[strtolower($params[0])]);
$output .= "Default Gamemode is now ".strtoupper($this->server->getGamemode()).".\n";
break; break;
case "invisible": case "invisible":
$p = strtolower(array_shift($params)); $p = strtolower(array_shift($params));

View File

@ -146,7 +146,7 @@ class PlayerAPI{
$player = $this->server->api->player->get($params[1]); $player = $this->server->api->player->get($params[1]);
} }
if(!($player instanceof Player) or !isset($gms[strtolower($params[0])])){ if(!($player instanceof Player) or !isset($gms[strtolower($params[0])])){
$output .= "Usage: /$cmd <survival | creative | adventure> [player]\n"; $output .= "Usage: /$cmd <mode> [player]\n";
break; break;
} }
if($player->setGamemode($gms[strtolower($params[0])])){ if($player->setGamemode($gms[strtolower($params[0])])){