From e2f17f11d3ec415ce7008cc34e4d163c7c4259ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Wed, 7 Oct 2020 20:54:30 +0200 Subject: [PATCH] Tab-complete plugin names in /help (#3713) Plugin names are accepted as input to `/essentials:help`, but they are not completed. This makes it easier to lookup plugin commands. --- .../earth2me/essentials/commands/Commandhelp.java | 5 ++++- .../essentials/commands/EssentialsCommand.java | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java index 400785b5f..e86491b0a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java @@ -10,6 +10,7 @@ import com.earth2me.essentials.textreader.TextPager; import com.earth2me.essentials.utils.NumberUtil; import org.bukkit.Server; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Locale; @@ -57,7 +58,9 @@ public class Commandhelp extends EssentialsCommand { @Override protected List getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) { if (args.length == 1) { - return getCommands(server); + final List suggestions = new ArrayList<>(getCommands(server)); + suggestions.addAll(getPlugins(server)); + return suggestions; } else { return Collections.emptyList(); } diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java index 57fdf632c..5af932a6d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java @@ -324,6 +324,20 @@ public abstract class EssentialsCommand implements IEssentialsCommand { return commands; } + /** + * Lists all plugin names + * + * @param server Server instance + * @return List of plugin names + */ + protected final List getPlugins(final Server server) { + final List plugins = Lists.newArrayList(); + for (final Plugin p : server.getPluginManager().getPlugins()) { + plugins.add(p.getName()); + } + return plugins; + } + /** * Attempts to tab-complete a command or its arguments. */