Add UserManager/GroupManager searchAll method

This commit is contained in:
Luck committed 2020-05-09 17:27:17 +01:00
1 parent 1af55e3720
commit 7ae532f082
28 files changed
+807 -135

No files matched your search

@@ -39,6 +39,7 @@ import net.luckperms.api.model.group.GroupManager;
import net.luckperms.api.model.user.User;
import net.luckperms.api.model.user.UserManager;
import net.luckperms.api.node.NodeBuilderRegistry;
import net.luckperms.api.node.matcher.NodeMatcherFactory;
import net.luckperms.api.platform.Platform;
import net.luckperms.api.platform.PluginMetadata;
import net.luckperms.api.query.QueryOptionsRegistry;
@@ -192,6 +193,14 @@ public interface LuckPerms {
*/
@NonNull MetaStackFactory getMetaStackFactory();
/**
* Gets the {@link NodeMatcherFactory}.
*
* @return the node matcher factory
* @since 5.1
*/
@NonNull NodeMatcherFactory getNodeMatcherFactory();
/**
* Schedules the execution of an update task, and returns an encapsulation
* of the task as a {@link CompletableFuture}.
@@ -26,11 +26,15 @@
package net.luckperms.api.model.group;
import net.luckperms.api.node.HeldNode;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.matcher.NodeMatcher;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
@@ -105,13 +109,25 @@ public interface GroupManager {
*/
@NonNull CompletableFuture<Void> loadAllGroups();
/**
* Searches the {@link Group#data() normal node maps} of all known {@link Group}s for {@link Node}
* entries matching the given {@link NodeMatcher matcher}.
*
* @param matcher the matcher
* @return the entries which matched
* @since 5.1
*/
@NonNull <T extends Node> CompletableFuture<Map<String, Collection<T>>> searchAll(@NonNull NodeMatcher<? extends T> matcher);
/**
* Searches for a list of groups with a given permission.
*
* @param permission the permission to search for
* @return a list of held permissions, or null if the operation failed
* @throws NullPointerException if the permission is null
* @deprecated use {@link #searchAll(NodeMatcher)}
*/
@Deprecated
@NonNull CompletableFuture<List<HeldNode<String>>> getWithPermission(@NonNull String permission);
/**
@@ -27,11 +27,15 @@ package net.luckperms.api.model.user;
import net.luckperms.api.model.PlayerSaveResult;
import net.luckperms.api.node.HeldNode;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.matcher.NodeMatcher;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@@ -131,13 +135,25 @@ public interface UserManager {
*/
@NonNull CompletableFuture<Set<UUID>> getUniqueUsers();
/**
* Searches the {@link User#data() normal node maps} of all known {@link User}s for {@link Node}
* entries matching the given {@link NodeMatcher matcher}.
*
* @param matcher the matcher
* @return the entries which matched
* @since 5.1
*/
@NonNull <T extends Node> CompletableFuture<Map<UUID, Collection<T>>> searchAll(@NonNull NodeMatcher<? extends T> matcher);
/**
* Searches for a list of users with a given permission.
*
* @param permission the permission to search for
* @return a list of held permissions
* @throws NullPointerException if the permission is null
* @deprecated use {@link #searchAll(NodeMatcher)}
*/
@Deprecated
@NonNull CompletableFuture<List<HeldNode<UUID>>> getWithPermission(@NonNull String permission);
/**
@@ -34,6 +34,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
*
* @param <T> the identifier type of the holder
*/
@Deprecated
public interface HeldNode<T> {
/**
@@ -0,0 +1,146 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.luckperms.api.node.matcher;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.NodeEqualityPredicate;
import net.luckperms.api.node.NodeType;
import net.luckperms.api.node.types.MetaNode;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.function.Predicate;
/**
* A predicate which matches certain {@link Node}s.
*
* @param <T> the node type matched
* @since 5.1
*/
public interface NodeMatcher<T extends Node> extends Predicate<Node> {
/**
* Gets a {@link NodeMatcher} which matches nodes with the same {@link Node#getKey() key}.
*
* <p>The {@link String#equalsIgnoreCase(String)} method is used to test key equality.</p>
*
* @param key the key
* @return the matcher
*/
static @NonNull NodeMatcher<Node> key(@NonNull String key) {
return LuckPermsProvider.get().getNodeMatcherFactory().key(key);
}
/**
* Gets a {@link NodeMatcher} which matches nodes with the same {@link Node#getKey() key}.
*
* <p>The {@link String#equalsIgnoreCase(String)} method is used to test key equality.</p>
*
* @param node the node to use for the key
* @param <T> the node type
* @return the matcher
*/
static <T extends Node> @NonNull NodeMatcher<T> key(@NonNull T node) {
return LuckPermsProvider.get().getNodeMatcherFactory().key(node);
}
/**
* Gets a {@link NodeMatcher} which matches nodes with a {@link Node#getKey() key} starting
* with the given string.
*
* @param startingWith the string to match
* @return the matcher
*/
static @NonNull NodeMatcher<Node> keyStartsWith(@NonNull String startingWith) {
return LuckPermsProvider.get().getNodeMatcherFactory().keyStartsWith(startingWith);
}
/**
* Gets a {@link NodeMatcher} which matches nodes which are
* {@link Node#equals(Node, NodeEqualityPredicate) equal to} the given {@code other} node
* according to the {@link NodeEqualityPredicate}.
*
* @param other the other node to test against
* @param equalityPredicate the equality predicate
* @param <T> the node type
* @return the matcher
*/
static <T extends Node> @NonNull NodeMatcher<T> equals(@NonNull T other, @NonNull NodeEqualityPredicate equalityPredicate) {
return LuckPermsProvider.get().getNodeMatcherFactory().equals(other, equalityPredicate);
}
/**
* Gets a {@link NodeMatcher} which matches {@link MetaNode}s with the same
* {@link MetaNode#getMetaKey() meta key}.
*
* <p>The {@link String#equalsIgnoreCase(String)} method is used to test key equality.</p>
*
* @param metaKey the meta key
* @return the matcher
*/
static @NonNull NodeMatcher<MetaNode> metaKey(@NonNull String metaKey) {
return LuckPermsProvider.get().getNodeMatcherFactory().metaKey(metaKey);
}
/**
* Gets a {@link NodeMatcher} which matches {@link MetaNode}s with the same
* {@link MetaNode#getMetaKey() meta key}.
*
* <p>The {@link String#equalsIgnoreCase(String)} method is used to test key equality.</p>
*
* @param metaNode the meta node to use for the meta key
* @return the matcher
*/
static @NonNull NodeMatcher<MetaNode> metaKey(@NonNull MetaNode metaNode) {
return metaKey(metaNode.getMetaKey());
}
/**
* Gets a {@link NodeMatcher} which matches {@link Node}s with the same
* type as the given {@link NodeType}.
*
* <p>{@link NodeType#PERMISSION}, {@link NodeType#CHAT_META} and
* {@link NodeType#META_OR_CHAT_META} are not supported by this method.</p>
*
* @param type the node type
* @param <T> the node type
* @return the matcher
*/
static <T extends Node> @NonNull NodeMatcher<T> type(NodeType<? extends T> type) {
return LuckPermsProvider.get().getNodeMatcherFactory().type(type);
}
/**
* Tests to see if the given {@link Node} matches.
*
* @param node the node to test
* @return true if the node matched
*/
@Override
boolean test(@NonNull Node node);
}
@@ -0,0 +1,120 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.luckperms.api.node.matcher;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.NodeEqualityPredicate;
import net.luckperms.api.node.NodeType;
import net.luckperms.api.node.types.MetaNode;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* A factory which creates {@link NodeMatcher}s.
*
* @since 5.1
*/
public interface NodeMatcherFactory {
/**
* Gets a {@link NodeMatcher} which matches nodes with the same {@link Node#getKey() key}.
*
* <p>The {@link String#equalsIgnoreCase(String)} method is used to test key equality.</p>
*
* <p>Prefer using the {@link NodeMatcher#key(String)} accessor.</p>
*
* @param key the key
* @return the matcher
*/
@NonNull NodeMatcher<Node> key(@NonNull String key);
/**
* Gets a {@link NodeMatcher} which matches nodes with the same {@link Node#getKey() key}.
*
* <p>The {@link String#equalsIgnoreCase(String)} method is used to test key equality.</p>
*
* <p>Prefer using the {@link NodeMatcher#key(Node)} accessor.</p>
*
* @param node the node to use for the key
* @param <T> the node type
* @return the matcher
*/
<T extends Node> @NonNull NodeMatcher<T> key(@NonNull T node);
/**
* Gets a {@link NodeMatcher} which matches nodes with a {@link Node#getKey() key} starting
* with the given string.
*
* <p>Prefer using the {@link NodeMatcher#keyStartsWith(String)} accessor.</p>
*
* @param startingWith the string to match
* @return the matcher
*/
@NonNull NodeMatcher<Node> keyStartsWith(@NonNull String startingWith);
/**
* Gets a {@link NodeMatcher} which matches nodes which are
* {@link Node#equals(Node, NodeEqualityPredicate) equal to} the given {@code other} node
* according to the {@link NodeEqualityPredicate}.
*
* <p>Prefer using the {@link NodeMatcher#equals(Node, NodeEqualityPredicate)} accessor.</p>
*
* @param other the other node to test against
* @param equalityPredicate the equality predicate
* @param <T> the node type
* @return the matcher
*/
@NonNull <T extends Node> NodeMatcher<T> equals(@NonNull T other, @NonNull NodeEqualityPredicate equalityPredicate);
/**
* Gets a {@link NodeMatcher} which matches {@link MetaNode}s with the same
* {@link MetaNode#getMetaKey() meta key}.
*
* <p>The {@link String#equalsIgnoreCase(String)} method is used to test key equality.</p>
*
* <p>Prefer using the {@link NodeMatcher#metaKey(String)} accessor.</p>
*
* @param metaKey the meta key
* @return the matcher
*/
@NonNull NodeMatcher<MetaNode> metaKey(@NonNull String metaKey);
/**
* Gets a {@link NodeMatcher} which matches {@link Node}s with the same
* type as the given {@link NodeType}.
*
* <p>{@link NodeType#PERMISSION}, {@link NodeType#CHAT_META} and
* {@link NodeType#META_OR_CHAT_META} are not supported by this method.</p>
*
* <p>Prefer using the {@link NodeMatcher#type(NodeType)} accessor.</p>
*
* @param type the node type
* @param <T> the node type
* @return the matcher
*/
<T extends Node> @NonNull NodeMatcher<T> type(NodeType<? extends T> type);
}