Let version print partial matches for plugin name. Addresses BUKKIT-2383

If no plugin is found with the given name, the version command will
search all loaded plugins to find a case insensitive partial match for
the specified name and print to the sender all matches.

By: Wesley Wolfe <weswolf@aol.com>
This commit is contained in:
Bukkit/Spigot 2012-09-28 03:01:40 -05:00
parent bce3782ec1
commit 99cde1402b

View file

@ -5,7 +5,6 @@ import java.util.List;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
@ -37,28 +36,23 @@ public class VersionCommand extends BukkitCommand {
name.append(arg); name.append(arg);
} }
Plugin plugin = Bukkit.getPluginManager().getPlugin(name.toString()); String pluginName = name.toString();
Plugin exactPlugin = Bukkit.getPluginManager().getPlugin(pluginName);
if (exactPlugin != null) {
describeToSender(exactPlugin, sender);
return true;
}
if (plugin != null) { boolean found = false;
PluginDescriptionFile desc = plugin.getDescription(); pluginName = pluginName.toLowerCase();
sender.sendMessage(ChatColor.GREEN + desc.getName() + ChatColor.WHITE + " version " + ChatColor.GREEN + desc.getVersion()); for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
if (plugin.getName().toLowerCase().contains(pluginName)) {
if (desc.getDescription() != null) { describeToSender(plugin, sender);
sender.sendMessage(desc.getDescription()); found = true;
} }
}
if (desc.getWebsite() != null) { if (!found) {
sender.sendMessage("Website: " + ChatColor.GREEN + desc.getWebsite());
}
if (!desc.getAuthors().isEmpty()) {
if (desc.getAuthors().size() == 1) {
sender.sendMessage("Author: " + getAuthors(desc));
} else {
sender.sendMessage("Authors: " + getAuthors(desc));
}
}
} else {
sender.sendMessage("This server is not running any plugin by that name."); sender.sendMessage("This server is not running any plugin by that name.");
sender.sendMessage("Use /plugins to get a list of plugins."); sender.sendMessage("Use /plugins to get a list of plugins.");
} }
@ -66,6 +60,27 @@ public class VersionCommand extends BukkitCommand {
return true; return true;
} }
private void describeToSender(Plugin plugin, CommandSender sender) {
PluginDescriptionFile desc = plugin.getDescription();
sender.sendMessage(ChatColor.GREEN + desc.getName() + ChatColor.WHITE + " version " + ChatColor.GREEN + desc.getVersion());
if (desc.getDescription() != null) {
sender.sendMessage(desc.getDescription());
}
if (desc.getWebsite() != null) {
sender.sendMessage("Website: " + ChatColor.GREEN + desc.getWebsite());
}
if (!desc.getAuthors().isEmpty()) {
if (desc.getAuthors().size() == 1) {
sender.sendMessage("Author: " + getAuthors(desc));
} else {
sender.sendMessage("Authors: " + getAuthors(desc));
}
}
}
private String getAuthors(final PluginDescriptionFile desc) { private String getAuthors(final PluginDescriptionFile desc) {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
List<String> authors = desc.getAuthors(); List<String> authors = desc.getAuthors();