PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
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 
22 namespace pocketmine\command\defaults;
23 
28 
30 
31  public function __construct($name){
32  parent::__construct(
33  $name,
34  "Gets the version of this server including any plugins in use",
35  "/version [plugin name]",
36  ["ver", "about"]
37  );
38  $this->setPermission("pocketmine.command.version");
39  }
40 
41  public function execute(CommandSender $sender, $currentAlias, array $args){
42  if(!$this->testPermission($sender)){
43  return true;
44  }
45 
46  if(count($args) === 0){
47  $output = "This server is running " . $sender->getServer()->getName() . " version " . $sender->getServer()->getPocketMineVersion() . " 「" . $sender->getServer()->getCodename() . "」 (Implementing API version " . $sender->getServer()->getApiVersion() . " for Minecraft: PE " . $sender->getServer()->getVersion() . " protocol version " . Info::CURRENT_PROTOCOL . ")";
48  if(\pocketmine\GIT_COMMIT !== str_repeat("00", 20)){
49  $output .= " [git " . \pocketmine\GIT_COMMIT . "]";
50  }
51  $sender->sendMessage($output);
52  }else{
53  $pluginName = implode(" ", $args);
54  $exactPlugin = $sender->getServer()->getPluginManager()->getPlugin($pluginName);
55 
56  if($exactPlugin instanceof Plugin){
57  $this->describeToSender($exactPlugin, $sender);
58 
59  return true;
60  }
61 
62  $found = false;
63  $pluginName = strtolower($pluginName);
64  foreach($sender->getServer()->getPluginManager()->getPlugins() as $plugin){
65  if(stripos($plugin->getName(), $pluginName) !== false){
66  $this->describeToSender($plugin, $sender);
67  $found = true;
68  }
69  }
70 
71  if(!$found){
72  $sender->sendMessage("This server is not running any plugin by that name.\nUse /plugins to get a list of plugins.");
73  }
74  }
75 
76  return true;
77  }
78 
79  private function describeToSender(Plugin $plugin, CommandSender $sender){
80  $desc = $plugin->getDescription();
81  $sender->sendMessage(TextFormat::DARK_GREEN . $desc->getName() . TextFormat::WHITE . " version " . TextFormat::DARK_GREEN . $desc->getVersion());
82 
83  if($desc->getDescription() != null){
84  $sender->sendMessage($desc->getDescription());
85  }
86 
87  if($desc->getWebsite() != null){
88  $sender->sendMessage("Website: " . $desc->getWebsite());
89  }
90 
91  if(count($authors = $desc->getAuthors()) > 0){
92  if(count($authors) === 1){
93  $sender->sendMessage("Author: " . implode(", ", $authors));
94  }else{
95  $sender->sendMessage("Authors: " . implode(", ", $authors));
96  }
97  }
98  }
99 }
testPermission(CommandSender $target)
Definition: Command.php:121
setPermission($permission)
Definition: Command.php:112