diff --git a/src/Server.php b/src/Server.php index bd2761ad7..a46b2b4ab 100644 --- a/src/Server.php +++ b/src/Server.php @@ -177,6 +177,12 @@ class Server{ public const BROADCAST_CHANNEL_ADMINISTRATIVE = "pocketmine.broadcast.admin"; public const BROADCAST_CHANNEL_USERS = "pocketmine.broadcast.user"; + public const DEFAULT_SERVER_NAME = VersionInfo::NAME . " Server"; + public const DEFAULT_MAX_PLAYERS = 20; + public const DEFAULT_PORT_IPV4 = 19132; + public const DEFAULT_PORT_IPV6 = 19133; + public const DEFAULT_VIEW_DISTANCE = 8; + private static ?Server $instance = null; private SleeperHandler $tickSleeper; @@ -323,15 +329,15 @@ class Server{ } public function getPort() : int{ - return $this->configGroup->getConfigInt("server-port", 19132); + return $this->configGroup->getConfigInt("server-port", self::DEFAULT_PORT_IPV4); } public function getPortV6() : int{ - return $this->configGroup->getConfigInt("server-portv6", 19133); + return $this->configGroup->getConfigInt("server-portv6", self::DEFAULT_PORT_IPV6); } public function getViewDistance() : int{ - return max(2, $this->configGroup->getConfigInt("view-distance", 8)); + return max(2, $this->configGroup->getConfigInt("view-distance", self::DEFAULT_VIEW_DISTANCE)); } /** @@ -379,7 +385,7 @@ class Server{ } public function getMotd() : string{ - return $this->configGroup->getConfigString("motd", VersionInfo::NAME . " Server"); + return $this->configGroup->getConfigString("motd", self::DEFAULT_SERVER_NAME); } public function getLoader() : \DynamicClassLoader{ @@ -797,12 +803,12 @@ class Server{ $this->configGroup = new ServerConfigGroup( new Config($pocketmineYmlPath, Config::YAML, []), new Config(Path::join($this->dataPath, "server.properties"), Config::PROPERTIES, [ - "motd" => VersionInfo::NAME . " Server", - "server-port" => 19132, - "server-portv6" => 19133, + "motd" => self::DEFAULT_SERVER_NAME, + "server-port" => self::DEFAULT_PORT_IPV4, + "server-portv6" => self::DEFAULT_PORT_IPV6, "enable-ipv6" => true, "white-list" => false, - "max-players" => 20, + "max-players" => self::DEFAULT_MAX_PLAYERS, "gamemode" => GameMode::SURVIVAL()->name(), "force-gamemode" => false, "hardcore" => false, @@ -814,7 +820,7 @@ class Server{ "level-type" => "DEFAULT", "enable-query" => true, "auto-save" => true, - "view-distance" => 8, + "view-distance" => self::DEFAULT_VIEW_DISTANCE, "xbox-auth" => true, "language" => "eng" ]) @@ -911,7 +917,7 @@ class Server{ $this->banByIP = new BanList($bannedIpsTxt); $this->banByIP->load(); - $this->maxPlayers = $this->configGroup->getConfigInt("max-players", 20); + $this->maxPlayers = $this->configGroup->getConfigInt("max-players", self::DEFAULT_MAX_PLAYERS); $this->onlineMode = $this->configGroup->getConfigBool("xbox-auth", true); if($this->onlineMode){ diff --git a/src/wizard/SetupWizard.php b/src/wizard/SetupWizard.php index 97bf2fd58..0a48b71d3 100644 --- a/src/wizard/SetupWizard.php +++ b/src/wizard/SetupWizard.php @@ -32,6 +32,7 @@ use pocketmine\lang\KnownTranslationFactory; use pocketmine\lang\Language; use pocketmine\lang\LanguageNotFoundException; use pocketmine\player\GameMode; +use pocketmine\Server; use pocketmine\utils\Config; use pocketmine\utils\Internet; use pocketmine\utils\InternetException; @@ -46,9 +47,9 @@ use const PHP_EOL; use const STDIN; class SetupWizard{ - public const DEFAULT_NAME = VersionInfo::NAME . " Server"; - public const DEFAULT_PORT = 19132; - public const DEFAULT_PLAYERS = 20; + public const DEFAULT_NAME = Server::DEFAULT_SERVER_NAME; + public const DEFAULT_PORT = Server::DEFAULT_PORT_IPV4; + public const DEFAULT_PLAYERS = Server::DEFAULT_MAX_PLAYERS; /** @var Language */ private $lang;