Add SWCommand.subCommandTabCompletes
Dieser Commit ist enthalten in:
Ursprung
9d14916940
Commit
811bc921a4
@ -35,6 +35,7 @@ public abstract class SWCommand {
|
|||||||
|
|
||||||
private final Set<InternalCommand> commandSet = new HashSet<>();
|
private final Set<InternalCommand> commandSet = new HashSet<>();
|
||||||
private final Set<InternalTabComplete> tabCompleteSet = new HashSet<>();
|
private final Set<InternalTabComplete> tabCompleteSet = new HashSet<>();
|
||||||
|
private final Map<Integer, Set<String>> subCommandTabCompletes = new HashMap<>();
|
||||||
private Consumer<CommandSender> helpMessage = sender -> {};
|
private Consumer<CommandSender> helpMessage = sender -> {};
|
||||||
|
|
||||||
protected SWCommand(String command) {
|
protected SWCommand(String command) {
|
||||||
@ -55,19 +56,30 @@ public abstract class SWCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
|
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
|
||||||
List<String> strings = new ArrayList<>();
|
List<String> strings = new ArrayList<>(subCommandTabCompletes.getOrDefault(args.length, new HashSet<>()));
|
||||||
for (InternalTabComplete internalTabComplete : tabCompleteSet) {
|
for (InternalTabComplete internalTabComplete : tabCompleteSet) {
|
||||||
SWCommandUtils.TabComplete tabComplete = internalTabComplete.invoke(sender, args);
|
SWCommandUtils.TabComplete tabComplete = internalTabComplete.invoke(sender, args);
|
||||||
if (tabComplete != null) {
|
if (tabComplete != null) {
|
||||||
strings.addAll(tabComplete.tabCompletes);
|
strings.addAll(tabComplete.tabCompletes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
strings = new ArrayList<>(strings);
|
||||||
|
for (int i = strings.size() - 1; i >= 0; i--) {
|
||||||
|
if (!strings.get(i).startsWith(args[args.length - 1])) {
|
||||||
|
strings.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
return strings;
|
return strings;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (Method method : getClass().getDeclaredMethods()) {
|
for (Method method : getClass().getDeclaredMethods()) {
|
||||||
if (method.getDeclaredAnnotation(Register.class) == null) continue;
|
Register register = method.getDeclaredAnnotation(Register.class);
|
||||||
|
if (register == null) continue;
|
||||||
|
for (int i = 0; i < register.subCommand().length; i++) {
|
||||||
|
subCommandTabCompletes.computeIfAbsent(i, integer -> new HashSet<>()).add(register.subCommand()[i]);
|
||||||
|
}
|
||||||
|
|
||||||
if (!validMethod(method)) continue;
|
if (!validMethod(method)) continue;
|
||||||
if (method.getReturnType() == Void.TYPE) {
|
if (method.getReturnType() == Void.TYPE) {
|
||||||
commandSet.add(new InternalCommand(this, method));
|
commandSet.add(new InternalCommand(this, method));
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren