use of me.lucko.luckperms.common.treeview.TreeNode in project LuckPerms by lucko.
the class TabCompletions method getPermissionTabComplete.
public static List<String> getPermissionTabComplete(List<String> args, PermissionVault cache) {
if (args.size() <= 1) {
if (args.isEmpty() || args.get(0).equals("")) {
return cache.getRootNode().getChildren().map(Map::keySet).map(s -> (List<String>) new ArrayList<>(s)).orElse(Collections.emptyList());
}
String start = args.get(0).toLowerCase();
List<String> parts = new ArrayList<>(Splitter.on('.').splitToList(start));
TreeNode root = cache.getRootNode();
if (parts.size() <= 1) {
if (!root.getChildren().isPresent()) {
return Collections.emptyList();
}
return root.getChildren().get().keySet().stream().filter(s -> s.startsWith(start)).collect(Collectors.toList());
}
String incomplete = parts.remove(parts.size() - 1);
for (String s : parts) {
if (!root.getChildren().isPresent()) {
return Collections.emptyList();
}
TreeNode n = root.getChildren().get().get(s);
if (n == null) {
return Collections.emptyList();
}
root = n;
}
if (!root.getChildren().isPresent()) {
return Collections.emptyList();
}
return root.getChildren().get().keySet().stream().filter(s -> s.startsWith(incomplete)).map(s -> parts.stream().collect(Collectors.joining(".")) + "." + s).collect(Collectors.toList());
}
return Collections.emptyList();
}
Aggregations