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.
This commit is contained in:
Alexander Söderberg 2020-10-07 20:54:30 +02:00 committed by GitHub
parent 4f8c040d06
commit e2f17f11d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -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<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
if (args.length == 1) {
return getCommands(server);
final List<String> suggestions = new ArrayList<>(getCommands(server));
suggestions.addAll(getPlugins(server));
return suggestions;
} else {
return Collections.emptyList();
}

View File

@ -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<String> getPlugins(final Server server) {
final List<String> 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.
*/