Search in sources :

Example 1 with TreeNode

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();
}
Also used : PermissionVault(me.lucko.luckperms.common.treeview.PermissionVault) TreeNode(me.lucko.luckperms.common.treeview.TreeNode) Arrays(java.util.Arrays) List(java.util.List) Map(java.util.Map) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) Splitter(com.google.common.base.Splitter) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TreeNode(me.lucko.luckperms.common.treeview.TreeNode) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Aggregations

Splitter (com.google.common.base.Splitter)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)1 PermissionVault (me.lucko.luckperms.common.treeview.PermissionVault)1 TreeNode (me.lucko.luckperms.common.treeview.TreeNode)1