PocketMine-MP 5.15.1 git-5ef247620a7c6301a849b54e5ef1009217729fc8
VersionCommand.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\command\defaults;
25
34use function count;
35use function implode;
36use function sprintf;
37use function stripos;
38use function strtolower;
39use const PHP_VERSION;
40
42
43 public function __construct(){
44 parent::__construct(
45 "version",
46 KnownTranslationFactory::pocketmine_command_version_description(),
47 KnownTranslationFactory::pocketmine_command_version_usage(),
48 ["ver", "about"]
49 );
50 $this->setPermission(DefaultPermissionNames::COMMAND_VERSION);
51 }
52
53 public function execute(CommandSender $sender, string $commandLabel, array $args){
54 if(count($args) === 0){
55 $sender->sendMessage(KnownTranslationFactory::pocketmine_command_version_serverSoftwareName(
56 TextFormat::GREEN . VersionInfo::NAME . TextFormat::RESET
57 ));
58 $versionColor = VersionInfo::IS_DEVELOPMENT_BUILD ? TextFormat::YELLOW : TextFormat::GREEN;
59 $sender->sendMessage(KnownTranslationFactory::pocketmine_command_version_serverSoftwareVersion(
60 $versionColor . VersionInfo::VERSION()->getFullVersion() . TextFormat::RESET,
61 TextFormat::GREEN . VersionInfo::GIT_HASH() . TextFormat::RESET
62 ));
63 $sender->sendMessage(KnownTranslationFactory::pocketmine_command_version_minecraftVersion(
64 TextFormat::GREEN . ProtocolInfo::MINECRAFT_VERSION_NETWORK . TextFormat::RESET,
65 TextFormat::GREEN . ProtocolInfo::CURRENT_PROTOCOL . TextFormat::RESET
66 ));
67 $sender->sendMessage(KnownTranslationFactory::pocketmine_command_version_phpVersion(TextFormat::GREEN . PHP_VERSION . TextFormat::RESET));
68
69 $jitMode = Utils::getOpcacheJitMode();
70 if($jitMode !== null){
71 if($jitMode !== 0){
72 $jitStatus = KnownTranslationFactory::pocketmine_command_version_phpJitEnabled(sprintf("CRTO: %d", $jitMode));
73 }else{
74 $jitStatus = KnownTranslationFactory::pocketmine_command_version_phpJitDisabled();
75 }
76 }else{
77 $jitStatus = KnownTranslationFactory::pocketmine_command_version_phpJitNotSupported();
78 }
79 $sender->sendMessage(KnownTranslationFactory::pocketmine_command_version_phpJitStatus($jitStatus->format(TextFormat::GREEN, TextFormat::RESET)));
80 $sender->sendMessage(KnownTranslationFactory::pocketmine_command_version_operatingSystem(TextFormat::GREEN . Utils::getOS() . TextFormat::RESET));
81 }else{
82 $pluginName = implode(" ", $args);
83 $exactPlugin = $sender->getServer()->getPluginManager()->getPlugin($pluginName);
84
85 if($exactPlugin instanceof Plugin){
86 $this->describeToSender($exactPlugin, $sender);
87
88 return true;
89 }
90
91 $found = false;
92 $pluginName = strtolower($pluginName);
93 foreach($sender->getServer()->getPluginManager()->getPlugins() as $plugin){
94 if(stripos($plugin->getName(), $pluginName) !== false){
95 $this->describeToSender($plugin, $sender);
96 $found = true;
97 }
98 }
99
100 if(!$found){
101 $sender->sendMessage(KnownTranslationFactory::pocketmine_command_version_noSuchPlugin());
102 }
103 }
104
105 return true;
106 }
107
108 private function describeToSender(Plugin $plugin, CommandSender $sender) : void{
109 $desc = $plugin->getDescription();
110 $sender->sendMessage(TextFormat::DARK_GREEN . $desc->getName() . TextFormat::RESET . " version " . TextFormat::DARK_GREEN . $desc->getVersion());
111
112 if($desc->getDescription() !== ""){
113 $sender->sendMessage($desc->getDescription());
114 }
115
116 if($desc->getWebsite() !== ""){
117 $sender->sendMessage("Website: " . $desc->getWebsite());
118 }
119
120 if(count($authors = $desc->getAuthors()) > 0){
121 if(count($authors) === 1){
122 $sender->sendMessage("Author: " . implode(", ", $authors));
123 }else{
124 $sender->sendMessage("Authors: " . implode(", ", $authors));
125 }
126 }
127 }
128}
execute(CommandSender $sender, string $commandLabel, array $args)
static getOS(bool $recalculate=false)
Definition: Utils.php:275
static getOpcacheJitMode()
Definition: Utils.php:657