Improves tab completion for Stargate commands by taking into account typed text
Sends tab completion for the config command to the config tab completer
This commit is contained in:
parent
8546fd4f78
commit
b4d908eaa0
@ -1,6 +1,7 @@
|
||||
package net.knarcraft.stargate.command;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -24,7 +25,8 @@ public class CommandStarGate implements CommandExecutor {
|
||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||
return new CommandReload().onCommand(commandSender, command, s, args);
|
||||
} else if (args[0].equalsIgnoreCase("config")) {
|
||||
return new CommandConfig().onCommand(commandSender, command, s, args);
|
||||
String[] subArgs = (String[]) ArrayUtils.remove(args, 0);
|
||||
return new CommandConfig().onCommand(commandSender, command, s, subArgs);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.knarcraft.stargate.command;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
@ -18,6 +19,30 @@ public class StarGateTabCompleter implements TabCompleter {
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command,
|
||||
@NotNull String s, @NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
List<String> commands = getAvailableCommands(commandSender);
|
||||
List<String> matchingCommands = new ArrayList<>();
|
||||
for (String availableCommand : commands) {
|
||||
if (availableCommand.startsWith(args[0])) {
|
||||
matchingCommands.add(availableCommand);
|
||||
}
|
||||
}
|
||||
return matchingCommands;
|
||||
} else if (args.length > 1 && args[0].equalsIgnoreCase("config")) {
|
||||
String[] subArgs = (String[]) ArrayUtils.remove(args, 0);
|
||||
return new ConfigTabCompleter().onTabComplete(commandSender, command, s, subArgs);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the available commands
|
||||
*
|
||||
* @param commandSender <p>The command sender to get available commands for</p>
|
||||
* @return <p>The commands available to the command sender</p>
|
||||
*/
|
||||
private List<String> getAvailableCommands(CommandSender commandSender) {
|
||||
List<String> commands = new ArrayList<>();
|
||||
commands.add("about");
|
||||
if (!(commandSender instanceof Player player) || player.hasPermission("stargate.admin.reload")) {
|
||||
@ -26,13 +51,7 @@ public class StarGateTabCompleter implements TabCompleter {
|
||||
if (!(commandSender instanceof Player player) || player.hasPermission("stargate.admin")) {
|
||||
commands.add("config");
|
||||
}
|
||||
|
||||
|
||||
if (args.length == 1) {
|
||||
return commands;
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user