Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package org.bukkit.command.defaults;
2
3import org.bukkit.Bukkit;
4import org.bukkit.ChatColor;
5import org.bukkit.command.Command;
6import org.bukkit.command.CommandSender;
7import org.bukkit.plugin.Plugin;
8import org.bukkit.plugin.PluginDescriptionFile;
9
10import java.util.ArrayList;
11import java.util.Arrays;
12
13public class VersionCommand extends Command {
14 public VersionCommand(String name) {
15 super(name);
16
17 this.description = "Gets the version of this server including any plugins in use";
18 this.usageMessage = "/version [plugin name]";
19 this.setPermission("bukkit.command.version");
20 this.setAliases(Arrays.asList("ver", "about"));
21 }
22
23 @Override
24 public boolean execute(CommandSender sender, String currentAlias, String[] args) {
25 if (!testPermission(sender)) return true;
26
27 if (args.length == 0) {
28 sender.sendMessage(ChatColor.GRAY + "This server is running " + ChatColor.AQUA + Bukkit.getName());
29 sender.sendMessage(ChatColor.GRAY + "Version: " + ChatColor.RED + Bukkit.getVersion());
30 } else {
31 StringBuilder name = new StringBuilder();
32
33 for (String arg : args) {
34 if (name.length() > 0) {
35 name.append(' ');
36 }
37
38 name.append(arg);
39 }
40
41 Plugin plugin = Bukkit.getPluginManager().getPlugin(name.toString());
42
43 if (plugin != null) {
44 PluginDescriptionFile desc = plugin.getDescription();
45 sender.sendMessage(ChatColor.GREEN + desc.getName() + ChatColor.WHITE + " version " + ChatColor.GREEN + desc.getVersion());
46
47 if (desc.getDescription() != null) {
48 sender.sendMessage(desc.getDescription());
49 }
50
51 if (desc.getWebsite() != null) {
52 sender.sendMessage("Website: " + ChatColor.GREEN + desc.getWebsite());
53 }
54
55 if (!desc.getAuthors().isEmpty()) {
56 if (desc.getAuthors().size() == 1) {
57 sender.sendMessage("Author: " + getAuthors(desc));
58 } else {
59 sender.sendMessage("Authors: " + getAuthors(desc));
60 }
61 }
62 } else {
63 sender.sendMessage("This server is not running any plugin by that name.");
64 sender.sendMessage("Use /plugins to get a list of plugins.");
65 }
66 }
67 return true;
68 }
69
70 private String getAuthors(final PluginDescriptionFile desc) {
71 StringBuilder result = new StringBuilder();
72 ArrayList<String> authors = desc.getAuthors();
73
74 for (int i = 0; i < authors.size(); i++) {
75 if (result.length() > 0) {
76 result.append(ChatColor.WHITE);
77
78 if (i < authors.size() - 1) {
79 result.append(", ");
80 } else {
81 result.append(" and ");
82 }
83 }
84
85 result.append(ChatColor.GREEN);
86 result.append(authors.get(i));
87 }
88
89 return result.toString();
90 }
91}