From bcbc65ed5e9323548aa5ee455312e009d8aa1636 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Wed, 15 May 2013 19:31:53 +0200 Subject: [PATCH] Added /spawn [world] [player] --- src/API/ConsoleAPI.php | 6 ++++-- src/API/PlayerAPI.php | 30 +++++++++++++++++++++++++++--- src/utils/Utils.php | 1 - 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index 66f67a678..42a44baf0 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -199,7 +199,7 @@ class ConsoleAPI{ $end = strlen($line); } $cmd = strtolower(substr($line, 0, $end)); - $params = substr($line, $end + 1); + $params = (string) substr($line, $end + 1); if(isset($this->alias[$cmd])){ $this->run($this->alias[$cmd] . " " .$params, $issuer, $cmd); @@ -249,8 +249,10 @@ class ConsoleAPI{ } } } - $params = explode(" ", $params); + if(count($params) === 1 and $params[0] === ""){ + $params = array(); + } if($this->server->api->dhandle("console.command.".$cmd, array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias)) === false or $this->server->api->dhandle("console.command", array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias)) === false){ diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index e34f9f686..88b61e342 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -39,6 +39,7 @@ class PlayerAPI{ $this->server->api->console->register("gamemode", " [player]", array($this, "commandHandler")); $this->server->api->console->register("tppos", "[target player] ", array($this, "commandHandler")); $this->server->api->console->register("tp", "[target player] ", array($this, "commandHandler")); + $this->server->api->console->register("spawn", "[world]", array($this, "commandHandler")); $this->server->api->console->register("lag", "", array($this, "commandHandler")); $this->server->api->console->alias("suicide", "kill"); $this->server->api->ban->cmdWhitelist("list"); @@ -114,6 +115,29 @@ class PlayerAPI{ public function commandHandler($cmd, $params, $issuer, $alias){ $output = ""; switch($cmd){ + case "spawn": + if(count($params) > 1){ + $player = $this->server->api->player->get(array_pop($params)); + }else{ + $player = $issuer; + } + if(isset($params[0])){ + $lv = $this->server->api->level->get(trim(implode(" ",$params))); + if($lv === false){ + $output .= "Couldn't respawn.\n"; + break; + } + $spawn = $lv->getSpawn(); + }else{ + $spawn = $this->server->api->level->getDefault()->getSpawn(); + } + + if(!($player instanceof Player)){ + $output .= "Couldn't respawn.\n"; + break; + } + $player->teleport($spawn); + break; case "lag": if(!($issuer instanceof Player)){ $output .= "Please run this command in-game.\n"; @@ -161,13 +185,13 @@ class PlayerAPI{ $name = $params[0]; $target = $params[1]; }else{ - $output .= "Usage: /$cmd [player] \n"; + $output .= "Usage: /$cmd [target player] \n"; break; } if($this->teleport($name, $target)){ $output .= "\"$name\" teleported to \"$target\"\n"; }else{ - $output .= "Couldn't teleport\n"; + $output .= "Couldn't teleport.\n"; } break; case "tppos": @@ -188,7 +212,7 @@ class PlayerAPI{ if($this->tppos($name, $x, $y, $z)){ $output .= "\"$name\" teleported to ($x, $y, $z)\n"; }else{ - $output .= "Couldn't teleport\n"; + $output .= "Couldn't teleport.\n"; } break; case "kill": diff --git a/src/utils/Utils.php b/src/utils/Utils.php index d5d1cc8f1..ba500d0a8 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -138,7 +138,6 @@ class Utils{ $m .= Utils::writeLInt($d["value"][$i]); } break; - } } $m .= "\x7f";