Search in sources :

Example 1 with NodeEntry

use of me.lucko.luckperms.common.storage.misc.NodeEntry in project LuckPerms by lucko.

the class CombinedConfigurateStorage method searchGroupNodes.

@Override
public <N extends Node> List<NodeEntry<String, N>> searchGroupNodes(ConstraintNodeMatcher<N> constraint) throws Exception {
    List<NodeEntry<String, N>> held = new ArrayList<>();
    this.groups.apply(false, true, root -> {
        for (Map.Entry<Object, ? extends ConfigurationNode> entry : root.getChildrenMap().entrySet()) {
            try {
                String holder = entry.getKey().toString();
                ConfigurationNode object = entry.getValue();
                Set<Node> nodes = readNodes(object);
                for (Node e : nodes) {
                    N match = constraint.match(e);
                    if (match != null) {
                        held.add(NodeEntry.of(holder, match));
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    return held;
}
Also used : NodeEntry(me.lucko.luckperms.common.storage.misc.NodeEntry) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) Node(net.luckperms.api.node.Node) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) ArrayList(java.util.ArrayList) Map(java.util.Map) IOException(java.io.IOException)

Example 2 with NodeEntry

use of me.lucko.luckperms.common.storage.misc.NodeEntry in project LuckPerms by lucko.

the class CombinedConfigurateStorage method searchUserNodes.

@Override
public <N extends Node> List<NodeEntry<UUID, N>> searchUserNodes(ConstraintNodeMatcher<N> constraint) throws Exception {
    List<NodeEntry<UUID, N>> held = new ArrayList<>();
    this.users.apply(false, true, root -> {
        for (Map.Entry<Object, ? extends ConfigurationNode> entry : root.getChildrenMap().entrySet()) {
            try {
                UUID holder = UUID.fromString(entry.getKey().toString());
                ConfigurationNode object = entry.getValue();
                Set<Node> nodes = readNodes(object);
                for (Node e : nodes) {
                    N match = constraint.match(e);
                    if (match != null) {
                        held.add(NodeEntry.of(holder, match));
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    return held;
}
Also used : NodeEntry(me.lucko.luckperms.common.storage.misc.NodeEntry) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) Node(net.luckperms.api.node.Node) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Map(java.util.Map) IOException(java.io.IOException)

Example 3 with NodeEntry

use of me.lucko.luckperms.common.storage.misc.NodeEntry in project LuckPerms by lucko.

the class SeparatedConfigurateStorage method searchUserNodes.

@Override
public <N extends Node> List<NodeEntry<UUID, N>> searchUserNodes(ConstraintNodeMatcher<N> constraint) throws IOException {
    List<NodeEntry<UUID, N>> held = new ArrayList<>();
    try (Stream<Path> stream = Files.list(getDirectory(StorageLocation.USERS))) {
        stream.filter(this.fileExtensionFilter).forEach(file -> {
            String fileName = file.getFileName().toString();
            try {
                registerFileAction(StorageLocation.USERS, file);
                ConfigurationNode object = readFile(file);
                UUID holder = UUID.fromString(fileName.substring(0, fileName.length() - this.fileExtension.length()));
                Set<Node> nodes = readNodes(object);
                for (Node e : nodes) {
                    N match = constraint.match(e);
                    if (match != null) {
                        held.add(NodeEntry.of(holder, match));
                    }
                }
            } catch (Exception e) {
                this.plugin.getLogger().severe("Exception whilst searching user nodes", new FileIOException(file.getFileName().toString(), e));
            }
        });
    }
    return held;
}
Also used : Path(java.nio.file.Path) Node(net.luckperms.api.node.Node) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) ArrayList(java.util.ArrayList) IOException(java.io.IOException) NodeEntry(me.lucko.luckperms.common.storage.misc.NodeEntry) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) UUID(java.util.UUID)

Example 4 with NodeEntry

use of me.lucko.luckperms.common.storage.misc.NodeEntry in project LuckPerms by lucko.

the class SearchCommand method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, ArgumentList args, String label) {
    Comparison comparison = StandardComparison.parseComparison(args.get(0));
    if (comparison == null) {
        comparison = StandardComparison.EQUAL;
        args.add(0, "==");
    }
    ConstraintNodeMatcher<Node> matcher = StandardNodeMatchers.of(Constraint.of(comparison, args.get(1)));
    int page = args.getIntOrDefault(2, 1);
    Message.SEARCH_SEARCHING.send(sender, matcher.toString());
    List<NodeEntry<UUID, Node>> matchedUsers = plugin.getStorage().searchUserNodes(matcher).join();
    List<NodeEntry<String, Node>> matchedGroups = plugin.getStorage().searchGroupNodes(matcher).join();
    int users = matchedUsers.size();
    int groups = matchedGroups.size();
    Message.SEARCH_RESULT.send(sender, users + groups, users, groups);
    if (!matchedUsers.isEmpty()) {
        Map<UUID, String> uuidLookups = LoadingMap.of(u -> plugin.lookupUsername(u).orElseGet(u::toString));
        sendResult(sender, matchedUsers, uuidLookups::get, Message.SEARCH_SHOWING_USERS, HolderType.USER, label, page, comparison);
    }
    if (!matchedGroups.isEmpty()) {
        sendResult(sender, matchedGroups, Function.identity(), Message.SEARCH_SHOWING_GROUPS, HolderType.GROUP, label, page, comparison);
    }
}
Also used : NodeEntry(me.lucko.luckperms.common.storage.misc.NodeEntry) StandardComparison(me.lucko.luckperms.common.bulkupdate.comparison.StandardComparison) Comparison(me.lucko.luckperms.common.bulkupdate.comparison.Comparison) Node(net.luckperms.api.node.Node) UUID(java.util.UUID) Constraint(me.lucko.luckperms.common.bulkupdate.comparison.Constraint)

Example 5 with NodeEntry

use of me.lucko.luckperms.common.storage.misc.NodeEntry in project LuckPerms by lucko.

the class WebEditorRequest method findMatchingOfflineUsers.

private static void findMatchingOfflineUsers(Map<UUID, User> users, ConstraintNodeMatcher<Node> matcher, LuckPermsPlugin plugin) {
    Stream<UUID> stream;
    if (matcher == null) {
        stream = plugin.getStorage().getUniqueUsers().join().stream();
    } else {
        stream = plugin.getStorage().searchUserNodes(matcher).join().stream().map(NodeEntry::getHolder).distinct();
    }
    Set<UUID> uuids = stream.filter(uuid -> !users.containsKey(uuid)).sorted().limit(MAX_USERS - users.size()).collect(Collectors.toSet());
    if (uuids.isEmpty()) {
        return;
    }
    // load users in bulk from storage
    Map<UUID, User> loadedUsers = plugin.getStorage().loadUsers(uuids).join();
    users.putAll(loadedUsers);
    // schedule cleanup
    for (UUID uniqueId : loadedUsers.keySet()) {
        plugin.getUserManager().getHouseKeeper().cleanup(uniqueId);
    }
}
Also used : ImmutableContextSetImpl(me.lucko.luckperms.common.context.ImmutableContextSetImpl) JsonObject(com.google.gson.JsonObject) CheckOrigin(me.lucko.luckperms.common.verbose.event.CheckOrigin) QueryOptions(net.luckperms.api.query.QueryOptions) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ImmutableCollectors(me.lucko.luckperms.common.util.ImmutableCollectors) Function(java.util.function.Function) JArray(me.lucko.luckperms.common.util.gson.JArray) NodeEntry(me.lucko.luckperms.common.storage.misc.NodeEntry) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Node(net.luckperms.api.node.Node) OutputStreamWriter(java.io.OutputStreamWriter) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) NodeJsonSerializer(me.lucko.luckperms.common.node.utils.NodeJsonSerializer) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) Predicate(java.util.function.Predicate) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Collection(java.util.Collection) Set(java.util.Set) ContextSetJsonSerializer(me.lucko.luckperms.common.context.serializer.ContextSetJsonSerializer) IOException(java.io.IOException) Sender(me.lucko.luckperms.common.sender.Sender) UUID(java.util.UUID) JObject(me.lucko.luckperms.common.util.gson.JObject) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Track(me.lucko.luckperms.common.model.Track) ConstraintNodeMatcher(me.lucko.luckperms.common.node.matcher.ConstraintNodeMatcher) List(java.util.List) PermissionHolderIdentifier(me.lucko.luckperms.common.model.PermissionHolderIdentifier) Stream(java.util.stream.Stream) Writer(java.io.Writer) Group(me.lucko.luckperms.common.model.Group) Preconditions(com.google.common.base.Preconditions) GZIPOutputStream(java.util.zip.GZIPOutputStream) Comparator(java.util.Comparator) GsonProvider(me.lucko.luckperms.common.util.gson.GsonProvider) Collections(java.util.Collections) User(me.lucko.luckperms.common.model.User) User(me.lucko.luckperms.common.model.User) NodeEntry(me.lucko.luckperms.common.storage.misc.NodeEntry) UUID(java.util.UUID)

Aggregations

NodeEntry (me.lucko.luckperms.common.storage.misc.NodeEntry)12 Node (net.luckperms.api.node.Node)11 ArrayList (java.util.ArrayList)10 UUID (java.util.UUID)8 IOException (java.io.IOException)5 Map (java.util.Map)5 List (java.util.List)3 Function (java.util.function.Function)3 Collectors (java.util.stream.Collectors)3 ConstraintNodeMatcher (me.lucko.luckperms.common.node.matcher.ConstraintNodeMatcher)3 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)3 Sender (me.lucko.luckperms.common.sender.Sender)3 ConfigurationNode (ninja.leaping.configurate.ConfigurationNode)3 Maps (com.google.common.collect.Maps)2 Path (java.nio.file.Path)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 HashSet (java.util.HashSet)2 PreparedStatementBuilder (me.lucko.luckperms.common.bulkupdate.PreparedStatementBuilder)2