From 99cde1402bf494cc717566fe3973766b18d0785f Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Fri, 28 Sep 2012 03:01:40 -0500 Subject: [PATCH] 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 --- .../command/defaults/VersionCommand.java | 55 ++++++++++++------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/paper-api/src/main/java/org/bukkit/command/defaults/VersionCommand.java b/paper-api/src/main/java/org/bukkit/command/defaults/VersionCommand.java index 4dc7a076ff..4d3ba15b09 100644 --- a/paper-api/src/main/java/org/bukkit/command/defaults/VersionCommand.java +++ b/paper-api/src/main/java/org/bukkit/command/defaults/VersionCommand.java @@ -5,7 +5,6 @@ import java.util.List; import org.bukkit.ChatColor; import org.bukkit.Bukkit; -import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; @@ -37,28 +36,23 @@ public class VersionCommand extends BukkitCommand { 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) { - 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()); + boolean found = false; + pluginName = pluginName.toLowerCase(); + for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { + if (plugin.getName().toLowerCase().contains(pluginName)) { + describeToSender(plugin, sender); + found = true; } + } - 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)); - } - } - } else { + if (!found) { sender.sendMessage("This server is not running any plugin by that name."); sender.sendMessage("Use /plugins to get a list of plugins."); } @@ -66,6 +60,27 @@ public class VersionCommand extends BukkitCommand { 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) { StringBuilder result = new StringBuilder(); List authors = desc.getAuthors();