From 904b0acfff97f4ecf2187c66c820ef97aa7aa2a7 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 8 Sep 2023 15:11:59 +0100 Subject: [PATCH] SetupWizard: replace hardcoded config keys --- src/wizard/SetupWizard.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/wizard/SetupWizard.php b/src/wizard/SetupWizard.php index 8c1906080..f068b3908 100644 --- a/src/wizard/SetupWizard.php +++ b/src/wizard/SetupWizard.php @@ -34,6 +34,7 @@ use pocketmine\lang\LanguageNotFoundException; use pocketmine\lang\Translatable; use pocketmine\player\GameMode; use pocketmine\Server; +use pocketmine\ServerProperties; use pocketmine\utils\Config; use pocketmine\utils\Internet; use pocketmine\utils\InternetException; @@ -91,7 +92,7 @@ class SetupWizard{ //this has to happen here to prevent user avoiding agreeing to license $config = new Config(Path::join($this->dataPath, "server.properties"), Config::PROPERTIES); - $config->set("language", $lang); + $config->set(ServerProperties::LANGUAGE, $lang); $config->save(); if(strtolower($this->getInput($this->lang->translate(KnownTranslationFactory::skip_installer()), "n", "y/N")) === "y"){ @@ -154,13 +155,12 @@ LICENSE; private function generateBaseConfig() : void{ $config = new Config(Path::join($this->dataPath, "server.properties"), Config::PROPERTIES); - $config->set("motd", ($name = $this->getInput($this->lang->translate(KnownTranslationFactory::name_your_server()), self::DEFAULT_NAME))); - $config->set("server-name", $name); + $config->set(ServerProperties::MOTD, ($name = $this->getInput($this->lang->translate(KnownTranslationFactory::name_your_server()), self::DEFAULT_NAME))); $this->message($this->lang->translate(KnownTranslationFactory::port_warning())); - $config->set("server-port", $this->askPort(KnownTranslationFactory::server_port_v4(), Server::DEFAULT_PORT_IPV4)); - $config->set("server-portv6", $this->askPort(KnownTranslationFactory::server_port_v6(), Server::DEFAULT_PORT_IPV6)); + $config->set(ServerProperties::SERVER_PORT_IPV4, $this->askPort(KnownTranslationFactory::server_port_v4(), Server::DEFAULT_PORT_IPV4)); + $config->set(ServerProperties::SERVER_PORT_IPV6, $this->askPort(KnownTranslationFactory::server_port_v6(), Server::DEFAULT_PORT_IPV6)); $this->message($this->lang->translate(KnownTranslationFactory::gamemode_info())); @@ -169,11 +169,11 @@ LICENSE; $gamemode = GameModeIdMap::getInstance()->fromId((int) $this->getInput($this->lang->translate(KnownTranslationFactory::default_gamemode()), (string) GameModeIdMap::getInstance()->toId(GameMode::SURVIVAL))); }while($gamemode === null); //TODO: this probably shouldn't use the enum name directly - $config->set("gamemode", $gamemode->name); + $config->set(ServerProperties::GAME_MODE, $gamemode->name); - $config->set("max-players", (int) $this->getInput($this->lang->translate(KnownTranslationFactory::max_players()), (string) self::DEFAULT_PLAYERS)); + $config->set(ServerProperties::MAX_PLAYERS, (int) $this->getInput($this->lang->translate(KnownTranslationFactory::max_players()), (string) self::DEFAULT_PLAYERS)); - $config->set("view-distance", (int) $this->getInput($this->lang->translate(KnownTranslationFactory::view_distance()), (string) Server::DEFAULT_MAX_VIEW_DISTANCE)); + $config->set(ServerProperties::VIEW_DISTANCE, (int) $this->getInput($this->lang->translate(KnownTranslationFactory::view_distance()), (string) Server::DEFAULT_MAX_VIEW_DISTANCE)); $config->save(); } @@ -195,9 +195,9 @@ LICENSE; $config = new Config(Path::join($this->dataPath, "server.properties"), Config::PROPERTIES); if(strtolower($this->getInput($this->lang->translate(KnownTranslationFactory::whitelist_enable()), "n", "y/N")) === "y"){ $this->error($this->lang->translate(KnownTranslationFactory::whitelist_warning())); - $config->set("white-list", true); + $config->set(ServerProperties::WHITELIST, true); }else{ - $config->set("white-list", false); + $config->set(ServerProperties::WHITELIST, false); } $config->save(); } @@ -207,9 +207,9 @@ LICENSE; $this->error($this->lang->translate(KnownTranslationFactory::query_warning1())); $this->error($this->lang->translate(KnownTranslationFactory::query_warning2())); if(strtolower($this->getInput($this->lang->translate(KnownTranslationFactory::query_disable()), "n", "y/N")) === "y"){ - $config->set("enable-query", false); + $config->set(ServerProperties::ENABLE_QUERY, false); }else{ - $config->set("enable-query", true); + $config->set(ServerProperties::ENABLE_QUERY, true); } $config->save();