From 022e25ff05d3292e9cca34f459bc5c68ad086cbe Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Mon, 24 Dec 2012 13:26:52 +0100 Subject: [PATCH] Removed seed and spawn from server.properties --- classes/API/ServerAPI.php | 35 +++---------------------- classes/Generator.class.php | 20 +++++++++++--- classes/PocketMinecraftServer.class.php | 1 + common/default.properties | 4 +-- 4 files changed, 22 insertions(+), 38 deletions(-) diff --git a/classes/API/ServerAPI.php b/classes/API/ServerAPI.php index 5689619cb..9b99e143d 100644 --- a/classes/API/ServerAPI.php +++ b/classes/API/ServerAPI.php @@ -90,7 +90,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run console("[DEBUG] Loading server.properties...", true, true, 2); $this->parseProperties(); define("DEBUG", $this->config["debug"]); - $this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), $this->getProperty("seed"), CURRENT_PROTOCOL, $this->getProperty("port"), $this->getProperty("server-id")); + $this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), false, CURRENT_PROTOCOL, $this->getProperty("port"), $this->getProperty("server-id")); $this->server->api = $this; if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){ console("[INFO] Checking for new server version"); @@ -130,21 +130,9 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run } $this->gen->init(); $this->gen->generate(); - $this->gen->save($this->server->mapDir."chunks.dat"); - $this->setProperty("seed", $this->server->seed); + $this->gen->save($this->server->mapDir, $this->server->mapName); $this->setProperty("level-name", $this->server->mapName); $this->setProperty("gamemode", 1); - $s = $this->gen->getSpawn(); - $this->setProperty("spawn", array("x" => $s[0], "y" => $s[1], "z" => $s[2])); - $array = array(); - file_put_contents($this->server->mapDir."entities.dat", serialize($array)); - file_put_contents($this->server->mapDir."tileEntities.dat", serialize($array)); - $level = array( - "LevelName" => $this->server->mapName, - "Time" => 0, - "RandomSeed" => $this->server->seed, - ); - file_put_contents($this->server->mapDir."level.dat", serialize($level)); } $this->loadProperties(); $this->server->loadMap(); @@ -220,7 +208,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run $this->setProperty("level-name", $level["LevelName"]); $this->setProperty("gamemode", $level["GameType"]); $this->server->seed = $level["RandomSeed"]; - $this->setProperty("spawn", array("x" => $level["SpawnX"], "y" => $level["SpawnY"], "z" => $level["SpawnZ"])); + $this->server->spawn = array("x" => $level["SpawnX"], "y" => $level["SpawnY"], "z" => $level["SpawnZ"]); $this->writeProperties(); } console("[INFO] Map \"".$level["LevelName"]."\" importing done!"); @@ -261,7 +249,6 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run $this->server->motd = $this->config["motd"]; $this->server->gamemode = $this->config["gamemode"]; $this->server->difficulty = $this->config["difficulty"]; - $this->server->spawn = $this->config["spawn"]; $this->server->whitelist = $this->config["white-list"]; $this->server->reloadConfig(); } @@ -269,7 +256,6 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run private function writeProperties(){ if(is_object($this->server)){ - $this->config["seed"] = $this->server->seed; $this->config["server-id"] = $this->server->serverID; } $config = $this->config; @@ -277,9 +263,6 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run $config["invisible"] = $config["invisible"] === true ? "true":"false"; $prop = "#Pocket Minecraft PHP server properties\r\n#".date("D M j H:i:s T Y")."\r\n"; foreach($config as $n => $v){ - if($n == "spawn"){ - $v = implode(";", $v); - } $prop .= $n."=".$v."\r\n"; } file_put_contents(FILE_PATH."server.properties", $prop); @@ -324,23 +307,11 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run case "time-per-second": $v = (int) $v; break; - case "seed": - if($v !== false and preg_match("/[^0-9\-]/", $v) > 0){ - $str = new Java_String($v); - $v = $str->hashCode(); - }else{ - $v = (int) $v; - } - break; case "server-id": if($v !== false){ $v = preg_match("/[^0-9\-]/", $v) > 0 ? Utils::readInt(substr(md5($v, true), 0, 4)):$v; } break; - case "spawn": - $v = explode(";", $v); - $v = array("x" => floatval($v[0]), "y" => floatval($v[1]), "z" => floatval($v[2])); - break; } $this->config[$n] = $v; } diff --git a/classes/Generator.class.php b/classes/Generator.class.php index 126a6cbf2..ffd1b88e5 100644 --- a/classes/Generator.class.php +++ b/classes/Generator.class.php @@ -334,9 +334,23 @@ class Generator{ return $chunk; } - public function save($file){ - @mkdir(dirname($file), 0777, true); - return file_put_contents($file, $this->raw); + public function save($dir, $name){ + @mkdir($dir, 0777, true); + file_put_contents($dir."chunks.dat", $this->raw); + $s = $this->getSpawn(); + $array = array(); + file_put_contents($dir."entities.dat", serialize($array)); + file_put_contents($dir."tileEntities.dat", serialize($array)); + $level = array( + "LevelName" => $name, + "Time" => 0, + "Gamemode" => 1, + "RandomSeed" => $this->seed, + "SpawnX" => $s[0], + "SpawnY" => $s[1], + "SpawnX" => $s[2], + ); + file_put_contents($dir."level.dat", serialize($level)); } } \ No newline at end of file diff --git a/classes/PocketMinecraftServer.class.php b/classes/PocketMinecraftServer.class.php index be5a44e5e..46d353809 100644 --- a/classes/PocketMinecraftServer.class.php +++ b/classes/PocketMinecraftServer.class.php @@ -224,6 +224,7 @@ class PocketMinecraftServer extends stdClass{ console("[INFO] Map: ".$this->level["LevelName"]); $this->time = (int) $this->level["Time"]; $this->seed = (int) $this->level["RandomSeed"]; + $this->spawn = array("x" => $level["SpawnX"], "y" => $level["SpawnY"], "z" => $level["SpawnZ"]); $this->level["Time"] = &$this->time; console("[INFO] Time: ".$this->time); console("[INFO] Seed: ".$this->seed); diff --git a/common/default.properties b/common/default.properties index d80e2017a..01153a908 100644 --- a/common/default.properties +++ b/common/default.properties @@ -14,7 +14,5 @@ time-per-second=20 gamemode=1 difficulty=1 generator-settings= -seed=false level-name=false -server-id=false -spawn=128.5;100;128.5 \ No newline at end of file +server-id=false \ No newline at end of file