| 10 | import org.bukkit.plugin.PluginDescriptionFile; |
| 11 | |
| 12 | public class VersionCommand extends Command { |
| 13 | public VersionCommand(String name) { |
| 14 | super(name); |
| 15 | |
| 16 | this.description = "Gets the version of this server including any plugins in use"; |
| 17 | this.usageMessage = "/version [plugin name]"; |
| 18 | this.setPermission("bukkit.command.version"); |
| 19 | this.setAliases(Arrays.asList("ver", "about")); |
| 20 | } |
| 21 | |
| 22 | @Override |
| 23 | public boolean execute(CommandSender sender, String currentAlias, String[] args) { |
| 24 | if (!testPermission(sender)) return true; |
| 25 | |
| 26 | if (args.length == 0) { |
| 27 | sender.sendMessage("This server is running " + ChatColor.GREEN + Bukkit.getName() + ChatColor.WHITE + " version " + ChatColor.GREEN + Bukkit.getVersion()); |
| 28 | sender.sendMessage("This server is also sporting some funky dev build of Bukkit!"); |
| 29 | } else { |
| 30 | StringBuilder name = new StringBuilder(); |
| 31 | |
| 32 | for (String arg : args) { |
| 33 | if (name.length() > 0) { |
| 34 | name.append(' '); |
| 35 | } |
| 36 | |
| 37 | name.append(arg); |
| 38 | } |
| 39 | |
| 40 | Plugin plugin = Bukkit.getPluginManager().getPlugin(name.toString()); |
| 41 | |
| 42 | if (plugin != null) { |
| 43 | PluginDescriptionFile desc = plugin.getDescription(); |
| 44 | sender.sendMessage(ChatColor.GREEN + desc.getName() + ChatColor.WHITE + " version " + ChatColor.GREEN + desc.getVersion()); |
| 45 | |
| 46 | if (desc.getDescription() != null) { |
| 47 | sender.sendMessage(desc.getDescription()); |
| 48 | } |
| 49 | |
| 50 | if (desc.getWebsite() != null) { |
| 51 | sender.sendMessage("Website: " + ChatColor.GREEN + desc.getWebsite()); |
| 52 | } |
| 53 | |
| 54 | if (!desc.getAuthors().isEmpty()) { |
| 55 | if (desc.getAuthors().size() == 1) { |
| 56 | sender.sendMessage("Author: " + getAuthors(desc)); |
| 57 | } else { |
| 58 | sender.sendMessage("Authors: " + getAuthors(desc)); |
| 59 | } |
| 60 | } |
| 61 | } else { |
| 62 | sender.sendMessage("This server is not running any plugin by that name."); |
| 63 | sender.sendMessage("Use /plugins to get a list of plugins."); |
| 64 | } |
| 65 | } |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | private String getAuthors(final PluginDescriptionFile desc) { |
nothing calls this directly
no outgoing calls
no test coverage detected