From 9b03b082ab4b2b18a194419fb49066198d24ad1b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 9 Jan 2024 13:04:14 +0000 Subject: [PATCH] Added --version option --- src/BootstrapOptions.php | 2 ++ src/PocketMine.php | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/src/BootstrapOptions.php b/src/BootstrapOptions.php index 879c502a6..c34dda94b 100644 --- a/src/BootstrapOptions.php +++ b/src/BootstrapOptions.php @@ -45,4 +45,6 @@ final class BootstrapOptions{ public const PLUGINS = "plugins"; /** Path to store and load server data */ public const DATA = "data"; + /** Shows basic server version information and exits */ + public const VERSION = "version"; } diff --git a/src/PocketMine.php b/src/PocketMine.php index 1209b28f0..d13cf33a1 100644 --- a/src/PocketMine.php +++ b/src/PocketMine.php @@ -25,6 +25,7 @@ namespace pocketmine { use Composer\InstalledVersions; use pocketmine\errorhandler\ErrorToExceptionHandler; + use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\thread\ThreadManager; use pocketmine\thread\ThreadSafeClassLoader; use pocketmine\utils\Filesystem; @@ -40,14 +41,17 @@ namespace pocketmine { use function extension_loaded; use function function_exists; use function getcwd; + use function getopt; use function is_dir; use function mkdir; use function phpversion; use function preg_match; use function preg_quote; + use function printf; use function realpath; use function version_compare; use const DIRECTORY_SEPARATOR; + use const PHP_EOL; require_once __DIR__ . '/VersionInfo.php'; @@ -273,6 +277,11 @@ JIT_WARNING ErrorToExceptionHandler::set(); + if(count(getopt("", [BootstrapOptions::VERSION])) > 0){ + printf("%s %s (git hash %s) for Minecraft: Bedrock Edition %s\n", VersionInfo::NAME, VersionInfo::VERSION()->getFullVersion(true), VersionInfo::GIT_HASH(), ProtocolInfo::MINECRAFT_VERSION); + exit(0); + } + $cwd = Utils::assumeNotFalse(realpath(Utils::assumeNotFalse(getcwd()))); $dataPath = getopt_string(BootstrapOptions::DATA) ?? $cwd; $pluginPath = getopt_string(BootstrapOptions::PLUGINS) ?? $cwd . DIRECTORY_SEPARATOR . "plugins";