Move some configuration constants to .. well .. constants

This commit is contained in:
Dylan K. Taylor 2021-12-15 01:40:29 +00:00
parent 60938c8c9d
commit 79b5109953
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 20 additions and 13 deletions

View File

@ -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){

View File

@ -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;