mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2026-11-22 07:22:18 +00:00
Add tab completion
This commit is contained in:
1 parent
874a90253b
commit
d33a3ffcea
35 files changed
+348
-24
No files matched your search
@@ -2,8 +2,15 @@ package me.lucko.luckperms.commands;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import me.lucko.luckperms.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.constants.Permission;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public abstract class SubCommand {
|
||||
@@ -12,6 +19,34 @@ public abstract class SubCommand {
|
||||
private final String usage;
|
||||
private final Permission permission;
|
||||
|
||||
protected static List<String> getGroupTabComplete(List<String> args, LuckPermsPlugin plugin) {
|
||||
return getTabComplete(new ArrayList<>(plugin.getGroupManager().getGroups().keySet()), args);
|
||||
}
|
||||
|
||||
protected static List<String> getTrackTabComplete(List<String> args, LuckPermsPlugin plugin) {
|
||||
return getTabComplete(new ArrayList<>(plugin.getTrackManager().getTracks().keySet()), args);
|
||||
}
|
||||
|
||||
private static List<String> getTabComplete(List<String> options, List<String> args) {
|
||||
if (args.size() <= 1) {
|
||||
if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) {
|
||||
return options;
|
||||
}
|
||||
|
||||
return options.stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
protected static List<String> getBoolTabComplete(List<String> args) {
|
||||
if (args.size() == 2) {
|
||||
return Arrays.asList("true", "false");
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAuthorized(Sender sender) {
|
||||
return permission.isAuthorized(sender);
|
||||
}
|
||||
@@ -20,5 +55,9 @@ public abstract class SubCommand {
|
||||
Util.sendPluginMessage(sender, "&e-> &d" + getUsage());
|
||||
}
|
||||
|
||||
public List<String> onTabComplete(Sender sender, List<String> args, LuckPermsPlugin plugin) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public abstract boolean isArgLengthInvalid(int argLength);
|
||||
}
|
||||
Reference in new issue
Block a user