diff --git a/build/make-release.php b/build/make-release.php index eed343d89..a89b22383 100644 --- a/build/make-release.php +++ b/build/make-release.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\build\make_release; use pocketmine\utils\VersionString; +use pocketmine\VersionInfo; use function dirname; use function fgets; use function file_get_contents; @@ -32,7 +33,6 @@ use function preg_replace; use function sleep; use function sprintf; use function system; -use const pocketmine\BASE_VERSION; use const STDIN; require_once dirname(__DIR__) . '/vendor/autoload.php'; @@ -41,13 +41,13 @@ require_once dirname(__DIR__) . '/vendor/autoload.php'; function replaceVersion(string $versionInfoPath, string $newVersion, bool $isDev) : void{ $versionInfo = file_get_contents($versionInfoPath); $versionInfo = preg_replace( - $pattern = '/^const BASE_VERSION = "(\d+)\.(\d+)\.(\d+)(?:-(.*))?";$/m', - 'const BASE_VERSION = "' . $newVersion . '";', + $pattern = '/^([\t ]*public )?const BASE_VERSION = "(\d+)\.(\d+)\.(\d+)(?:-(.*))?";$/m', + '$1const BASE_VERSION = "' . $newVersion . '";', $versionInfo ); $versionInfo = preg_replace( - '/^const IS_DEVELOPMENT_BUILD = (?:true|false);$/m', - 'const IS_DEVELOPMENT_BUILD = ' . ($isDev ? 'true' : 'false') . ';', + '/^([\t ]*public )?const IS_DEVELOPMENT_BUILD = (?:true|false);$/m', + '$1const IS_DEVELOPMENT_BUILD = ' . ($isDev ? 'true' : 'false') . ';', $versionInfo ); file_put_contents($versionInfoPath, $versionInfo); @@ -61,7 +61,7 @@ function main(array $argv) : void{ if(isset($argv[1])){ $currentVer = new VersionString($argv[1]); }else{ - $currentVer = new VersionString(BASE_VERSION); + $currentVer = new VersionString(VersionInfo::BASE_VERSION); } $nextVer = new VersionString(sprintf( "%u.%u.%u", diff --git a/composer.json b/composer.json index a00691351..2facf1018 100644 --- a/composer.json +++ b/composer.json @@ -60,8 +60,7 @@ "pocketmine\\": "src/" }, "files": [ - "src/CoreConstants.php", - "src/VersionInfo.php" + "src/CoreConstants.php" ] }, "autoload-dev": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 75f06d92e..3f7c79404 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -35,7 +35,7 @@ parameters: - build/server-phar.php - tests/phpunit dynamicConstantNames: - - pocketmine\IS_DEVELOPMENT_BUILD + - pocketmine\VersionInfo::IS_DEVELOPMENT_BUILD - pocketmine\DEBUG stubFiles: - tests/phpstan/stubs/JsonMapper.stub diff --git a/src/CrashDump.php b/src/CrashDump.php index 469b3e4b8..adea192f9 100644 --- a/src/CrashDump.php +++ b/src/CrashDump.php @@ -308,12 +308,12 @@ class CrashDump{ } private function generalData() : void{ - $version = new VersionString(\pocketmine\BASE_VERSION, \pocketmine\IS_DEVELOPMENT_BUILD, \pocketmine\BUILD_NUMBER); + $version = new VersionString(VersionInfo::BASE_VERSION, VersionInfo::IS_DEVELOPMENT_BUILD, VersionInfo::BUILD_NUMBER); $this->data["general"] = []; $this->data["general"]["name"] = $this->server->getName(); - $this->data["general"]["base_version"] = \pocketmine\BASE_VERSION; - $this->data["general"]["build"] = \pocketmine\BUILD_NUMBER; - $this->data["general"]["is_dev"] = \pocketmine\IS_DEVELOPMENT_BUILD; + $this->data["general"]["base_version"] = VersionInfo::BASE_VERSION; + $this->data["general"]["build"] = VersionInfo::BUILD_NUMBER; + $this->data["general"]["is_dev"] = VersionInfo::IS_DEVELOPMENT_BUILD; $this->data["general"]["protocol"] = ProtocolInfo::CURRENT_PROTOCOL; $this->data["general"]["git"] = \pocketmine\GIT_COMMIT; $this->data["general"]["uname"] = php_uname("a"); diff --git a/src/PocketMine.php b/src/PocketMine.php index 530815eb6..78c3f6cda 100644 --- a/src/PocketMine.php +++ b/src/PocketMine.php @@ -197,7 +197,7 @@ namespace pocketmine { ErrorToExceptionHandler::set(); - $version = new VersionString(\pocketmine\BASE_VERSION, \pocketmine\IS_DEVELOPMENT_BUILD, \pocketmine\BUILD_NUMBER); + $version = new VersionString(VersionInfo::BASE_VERSION, VersionInfo::IS_DEVELOPMENT_BUILD, VersionInfo::BUILD_NUMBER); define('pocketmine\VERSION', $version->getFullVersion(true)); $gitHash = str_repeat("00", 20); @@ -225,7 +225,7 @@ namespace pocketmine { $lockFilePath = $dataPath . '/server.lock'; if(($pid = Filesystem::createLockFile($lockFilePath)) !== null){ - critical_error("Another " . \pocketmine\NAME . " instance (PID $pid) is already using this folder (" . realpath($dataPath) . ")."); + critical_error("Another " . VersionInfo::NAME . " instance (PID $pid) is already using this folder (" . realpath($dataPath) . ")."); critical_error("Please stop the other server first before running a new one."); exit(1); } diff --git a/src/Server.php b/src/Server.php index fd7183715..e4e025b9e 100644 --- a/src/Server.php +++ b/src/Server.php @@ -280,7 +280,7 @@ class Server{ private $playerList = []; public function getName() : string{ - return \pocketmine\NAME; + return VersionInfo::NAME; } public function isRunning() : bool{ @@ -296,7 +296,7 @@ class Server{ } public function getApiVersion() : string{ - return \pocketmine\BASE_VERSION; + return VersionInfo::BASE_VERSION; } public function getFilePath() : string{ @@ -385,7 +385,7 @@ class Server{ } public function getMotd() : string{ - return $this->configGroup->getConfigString("motd", \pocketmine\NAME . " Server"); + return $this->configGroup->getConfigString("motd", VersionInfo::NAME . " Server"); } /** @@ -778,7 +778,7 @@ class Server{ $this->logger->info("Loading server configuration"); if(!file_exists($this->dataPath . "pocketmine.yml")){ $content = file_get_contents(\pocketmine\RESOURCE_PATH . "pocketmine.yml"); - if(\pocketmine\IS_DEVELOPMENT_BUILD){ + if(VersionInfo::IS_DEVELOPMENT_BUILD){ $content = str_replace("preferred-channel: stable", "preferred-channel: beta", $content); } @file_put_contents($this->dataPath . "pocketmine.yml", $content); @@ -787,7 +787,7 @@ class Server{ $this->configGroup = new ServerConfigGroup( new Config($this->dataPath . "pocketmine.yml", Config::YAML, []), new Config($this->dataPath . "server.properties", Config::PROPERTIES, [ - "motd" => \pocketmine\NAME . " Server", + "motd" => VersionInfo::NAME . " Server", "server-port" => 19132, "white-list" => false, "max-players" => 20, @@ -829,9 +829,9 @@ class Server{ $this->logger->info($this->getLanguage()->translateString("language.selected", [$this->getLanguage()->getName(), $this->getLanguage()->getLang()])); - if(\pocketmine\IS_DEVELOPMENT_BUILD){ + if(VersionInfo::IS_DEVELOPMENT_BUILD){ if(!((bool) $this->configGroup->getProperty("settings.enable-dev-builds", false))){ - $this->logger->emergency($this->language->translateString("pocketmine.server.devBuild.error1", [\pocketmine\NAME])); + $this->logger->emergency($this->language->translateString("pocketmine.server.devBuild.error1", [VersionInfo::NAME])); $this->logger->emergency($this->language->translateString("pocketmine.server.devBuild.error2")); $this->logger->emergency($this->language->translateString("pocketmine.server.devBuild.error3")); $this->logger->emergency($this->language->translateString("pocketmine.server.devBuild.error4", ["settings.enable-dev-builds"])); @@ -842,7 +842,7 @@ class Server{ } $this->logger->warning(str_repeat("-", 40)); - $this->logger->warning($this->language->translateString("pocketmine.server.devBuild.warning1", [\pocketmine\NAME])); + $this->logger->warning($this->language->translateString("pocketmine.server.devBuild.warning1", [VersionInfo::NAME])); $this->logger->warning($this->language->translateString("pocketmine.server.devBuild.warning2")); $this->logger->warning($this->language->translateString("pocketmine.server.devBuild.warning3")); $this->logger->warning(str_repeat("-", 40)); @@ -923,7 +923,7 @@ class Server{ $this->logger->info($this->getLanguage()->translateString("pocketmine.server.info", [ $this->getName(), - (\pocketmine\IS_DEVELOPMENT_BUILD ? TextFormat::YELLOW : "") . $this->getPocketMineVersion() . TextFormat::RESET + (VersionInfo::IS_DEVELOPMENT_BUILD ? TextFormat::YELLOW : "") . $this->getPocketMineVersion() . TextFormat::RESET ])); $this->logger->info($this->getLanguage()->translateString("pocketmine.server.license", [$this->getName()])); diff --git a/src/VersionInfo.php b/src/VersionInfo.php index 4a8f59fb7..67ac227ac 100644 --- a/src/VersionInfo.php +++ b/src/VersionInfo.php @@ -23,16 +23,13 @@ declare(strict_types=1); namespace pocketmine; -use function defined; +final class VersionInfo{ + public const NAME = "PocketMine-MP"; + public const BASE_VERSION = "4.0.0"; + public const IS_DEVELOPMENT_BUILD = true; + public const BUILD_NUMBER = 0; -// composer autoload doesn't use require_once and also pthreads can inherit things -// TODO: drop this file and use a final class with constants -if(defined('pocketmine\_VERSION_INFO_INCLUDED')){ - return; + private function __construct(){ + //NOOP + } } -const _VERSION_INFO_INCLUDED = true; - -const NAME = "PocketMine-MP"; -const BASE_VERSION = "4.0.0"; -const IS_DEVELOPMENT_BUILD = true; -const BUILD_NUMBER = 0; diff --git a/src/stats/SendUsageTask.php b/src/stats/SendUsageTask.php index b88e517b4..15753ff52 100644 --- a/src/stats/SendUsageTask.php +++ b/src/stats/SendUsageTask.php @@ -33,6 +33,7 @@ use pocketmine\utils\Process; use pocketmine\utils\Utils; use pocketmine\utils\VersionString; use pocketmine\uuid\UUID; +use pocketmine\VersionInfo; use function array_map; use function array_values; use function count; @@ -71,7 +72,7 @@ class SendUsageTask extends AsyncTask{ case self::TYPE_OPEN: $data["event"] = "open"; - $version = new VersionString(\pocketmine\BASE_VERSION, \pocketmine\IS_DEVELOPMENT_BUILD, \pocketmine\BUILD_NUMBER); + $version = new VersionString(VersionInfo::BASE_VERSION, VersionInfo::IS_DEVELOPMENT_BUILD, VersionInfo::BUILD_NUMBER); $data["server"] = [ "port" => $server->getPort(), diff --git a/src/updater/AutoUpdater.php b/src/updater/AutoUpdater.php index 662dc3d77..51497ee33 100644 --- a/src/updater/AutoUpdater.php +++ b/src/updater/AutoUpdater.php @@ -28,6 +28,7 @@ use pocketmine\player\Player; use pocketmine\Server; use pocketmine\utils\TextFormat; use pocketmine\utils\VersionString; +use pocketmine\VersionInfo; use function date; use function sprintf; use function str_repeat; @@ -75,9 +76,9 @@ class AutoUpdater{ $this->showConsoleUpdate(); } }else{ - if(!\pocketmine\IS_DEVELOPMENT_BUILD and $this->getChannel() !== "stable"){ + if(!VersionInfo::IS_DEVELOPMENT_BUILD and $this->getChannel() !== "stable"){ $this->showChannelSuggestionStable(); - }elseif(\pocketmine\IS_DEVELOPMENT_BUILD and $this->getChannel() === "stable"){ + }elseif(VersionInfo::IS_DEVELOPMENT_BUILD and $this->getChannel() === "stable"){ $this->showChannelSuggestionBeta(); } } @@ -159,7 +160,7 @@ class AutoUpdater{ if($this->updateInfo === null){ return; } - $currentVersion = new VersionString(\pocketmine\BASE_VERSION, \pocketmine\IS_DEVELOPMENT_BUILD, \pocketmine\BUILD_NUMBER); + $currentVersion = new VersionString(VersionInfo::BASE_VERSION, VersionInfo::IS_DEVELOPMENT_BUILD, VersionInfo::BUILD_NUMBER); try{ $newVersion = new VersionString($this->updateInfo->base_version, $this->updateInfo->is_dev, $this->updateInfo->build); }catch(\InvalidArgumentException $e){ diff --git a/src/utils/Internet.php b/src/utils/Internet.php index 1fba58924..de66a8a31 100644 --- a/src/utils/Internet.php +++ b/src/utils/Internet.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\utils; +use pocketmine\VersionInfo; use function array_merge; use function curl_close; use function curl_error; @@ -223,7 +224,7 @@ class Internet{ CURLOPT_RETURNTRANSFER => true, CURLOPT_CONNECTTIMEOUT_MS => (int) ($timeout * 1000), CURLOPT_TIMEOUT_MS => (int) ($timeout * 1000), - CURLOPT_HTTPHEADER => array_merge(["User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 " . \pocketmine\NAME . "/" . \pocketmine\VERSION], $extraHeaders), + CURLOPT_HTTPHEADER => array_merge(["User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 " . VersionInfo::NAME . "/" . \pocketmine\VERSION], $extraHeaders), CURLOPT_HEADER => true ]); try{ diff --git a/src/wizard/SetupWizard.php b/src/wizard/SetupWizard.php index 66862b9f9..1fb63b3de 100644 --- a/src/wizard/SetupWizard.php +++ b/src/wizard/SetupWizard.php @@ -33,6 +33,7 @@ use pocketmine\player\GameMode; use pocketmine\utils\Config; use pocketmine\utils\Internet; use pocketmine\utils\InternetException; +use pocketmine\VersionInfo; use function fgets; use function sleep; use function strtolower; @@ -41,7 +42,7 @@ use const PHP_EOL; use const STDIN; class SetupWizard{ - public const DEFAULT_NAME = \pocketmine\NAME . " Server"; + public const DEFAULT_NAME = VersionInfo::NAME . " Server"; public const DEFAULT_PORT = 19132; public const DEFAULT_PLAYERS = 20; @@ -55,7 +56,7 @@ class SetupWizard{ } public function run() : bool{ - $this->message(\pocketmine\NAME . " set-up wizard"); + $this->message(VersionInfo::NAME . " set-up wizard"); try{ $langs = Language::getLanguageList(); @@ -107,7 +108,7 @@ class SetupWizard{ } private function showLicense() : bool{ - $this->message($this->lang->translateString("welcome_to_pocketmine", [\pocketmine\NAME])); + $this->message($this->lang->translateString("welcome_to_pocketmine", [VersionInfo::NAME])); echo <<writeLine(); if(strtolower($this->getInput($this->lang->get("accept_license"), "n", "y/N")) !== "y"){ - $this->error($this->lang->translateString("you_have_to_accept_the_license", [\pocketmine\NAME])); + $this->error($this->lang->translateString("you_have_to_accept_the_license", [VersionInfo::NAME])); sleep(5); return false; @@ -220,7 +221,7 @@ LICENSE; private function endWizard() : void{ $this->message($this->lang->get("you_have_finished")); $this->message($this->lang->get("pocketmine_plugins")); - $this->message($this->lang->translateString("pocketmine_will_start", [\pocketmine\NAME])); + $this->message($this->lang->translateString("pocketmine_will_start", [VersionInfo::NAME])); $this->writeLine(); $this->writeLine();