A few more small API changes

This commit is contained in:
Luck committed 2019-11-23 12:52:26 +00:00
1 parent 213b2fcb44
commit 95d2832884
87 files changed
+352 -360

No files matched your search

@@ -46,7 +46,6 @@ import net.luckperms.api.track.TrackManager;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Collection;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
@@ -207,11 +206,4 @@ public interface LuckPerms {
*/
void registerMessengerProvider(@NonNull MessengerProvider messengerProvider);
/**
* Gets a {@link Collection} of all known permission strings.
*
* @return a collection of the known permissions
*/
@NonNull Collection<String> getKnownPermissions();
}
@@ -27,8 +27,8 @@ package net.luckperms.api.event.node;
import net.luckperms.api.event.LuckPermsEvent;
import net.luckperms.api.event.Param;
import net.luckperms.api.model.DataType;
import net.luckperms.api.model.PermissionHolder;
import net.luckperms.api.model.data.DataType;
import net.luckperms.api.model.group.Group;
import net.luckperms.api.model.user.User;
import net.luckperms.api.node.Node;
@@ -26,26 +26,18 @@
package net.luckperms.api.model;
import net.luckperms.api.cacheddata.CachedDataManager;
import net.luckperms.api.context.ContextSet;
import net.luckperms.api.context.ImmutableContextSet;
import net.luckperms.api.model.data.DataType;
import net.luckperms.api.model.data.NodeMap;
import net.luckperms.api.model.group.Group;
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.Node;
import net.luckperms.api.node.NodeEqualityPredicate;
import net.luckperms.api.node.Tristate;
import net.luckperms.api.query.QueryOptions;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.UUID;
import java.util.function.Predicate;
/**
* Generic superinterface for an object which holds permissions.
@@ -156,108 +148,6 @@ public interface PermissionHolder {
*/
@NonNull NodeMap transientData();
/**
* Encapsulates a store of data ({@link Node}s) within a {@link PermissionHolder}.
*
* <p>The effect of any mutate operation will not persist in storage unless changes are
* explicitly saved. If changes are not saved, the effect will only be observed until the next
* time the holders permission data is (re)loaded. Changes to {@link User}s should be saved
* using {@link UserManager#saveUser(User)}, and changes to {@link Group}s should be saved
* using {@link GroupManager#saveGroup(Group)}.</p>
*
* <p>Before making changes to a user or group, it may be a good idea to load a fresh copy of
* the backing data from the storage if you haven't done so already, to avoid overwriting changes
* made already. This can be done via {@link UserManager#loadUser(UUID)} or
* {@link GroupManager#loadGroup(String)} respectively.</p>
*/
interface NodeMap {
/**
* Gets a map of the {@link Node}s contained within this instance,
* mapped to their defined {@link Node#getContexts() context}.
*
* @return a map of nodes
*/
@NonNull Map<ImmutableContextSet, Collection<Node>> toMap();
/**
* Gets a flattened set of {@link Node}s contained within this instance.
*
* <p>Effectively combines the value collections of the map returned by
* {@link #toMap()}.</p>
*
* @return a flattened set of the holders own nodes
*/
@NonNull Set<Node> toSet();
/**
* Gets if this instance contains a given {@link Node}.
*
* <p>Returns {@link Tristate#UNDEFINED} if the instance does not contain the node,
* and the {@link Node#getValue() assigned value} of the node as a {@link Tristate}
* if it is present.</p>
*
* @param node the node to check for
* @param equalityPredicate how to determine if a node matches
* @return a Tristate relating to the assigned state of the node
* @throws NullPointerException if the node is null
*/
@NonNull Tristate contains(@NonNull Node node, @NonNull NodeEqualityPredicate equalityPredicate);
/**
* Adds a node.
*
* @param node the node to be add
* @return the result of the operation
*/
@NonNull DataMutateResult add(@NonNull Node node);
/**
* Adds a node.
*
* @param node the node to add
* @param temporaryMergeBehaviour the behaviour used to merge temporary permission entries
* @return the result of the operation
*/
@NonNull TemporaryDataMutateResult add(@NonNull Node node, @NonNull TemporaryMergeBehaviour temporaryMergeBehaviour);
/**
* Removes a node.
*
* @param node the node to remove
* @return the result of the operation
*/
@NonNull DataMutateResult remove(@NonNull Node node);
/**
* Clears all nodes.
*/
void clear();
/**
* Clears any nodes which pass the predicate.
*
* @param test the predicate to test for nodes which should be removed
*/
void clear(@NonNull Predicate<? super Node> test);
/**
* Clears all nodes in a specific context.
*
* @param contextSet the contexts to filter by
*/
void clear(@NonNull ContextSet contextSet);
/**
* Clears all nodes in a specific context which pass the predicate.
*
* @param contextSet the contexts to filter by
* @param test the predicate to test for nodes which should be removed
*/
void clear(@NonNull ContextSet contextSet, @NonNull Predicate<? super Node> test);
}
/**
* Gets a flattened/squashed view of the holders permissions.
*
@@ -272,7 +162,7 @@ public interface PermissionHolder {
*
* @return a list of the holders own nodes.
*/
@NonNull List<Node> getNodes();
@NonNull Collection<Node> getNodes();
/**
* Gets a sorted set of all held nodes.
@@ -301,7 +191,7 @@ public interface PermissionHolder {
* @param queryOptions the query options
* @return a list of nodes
*/
@NonNull List<Node> resolveInheritedNodes(@NonNull QueryOptions queryOptions);
@NonNull Collection<Node> resolveInheritedNodes(@NonNull QueryOptions queryOptions);
/**
* Gets a mutable sorted set of the nodes that this object has and inherits, filtered by context
@@ -1,61 +0,0 @@
/*
* 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.model;
import net.luckperms.api.node.Node;
import net.luckperms.api.util.Result;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Extension of {@link DataMutateResult} for temporary set operations.
*/
public interface TemporaryDataMutateResult extends Result {
/**
* Gets the underlying result.
*
* @return the result
*/
@NonNull DataMutateResult getResult();
/**
* Gets the node that resulted from any {@link TemporaryMergeBehaviour}
* processing.
*
* <p>If no processing took place, the same instance will be returned by
* this method.</p>
*
* @return the resultant node
*/
@NonNull Node getMergedNode();
@Override
default boolean wasSuccessful() {
return getResult().wasSuccessful();
}
}
@@ -1,5 +1,5 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
* This file is part of luckperms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
@@ -23,11 +23,15 @@
* SOFTWARE.
*/
package net.luckperms.api.model;
package net.luckperms.api.model.data;
import net.luckperms.api.model.PermissionHolder;
import net.luckperms.api.node.Node;
import net.luckperms.api.track.Track;
import net.luckperms.api.util.Result;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Represents the result of a data mutation call on a LuckPerms object.
*
@@ -40,29 +44,54 @@ public enum DataMutateResult implements Result {
*/
SUCCESS(true),
/**
* Indicates the mutation failed
*/
FAIL(false),
/**
* Indicates the mutation failed because the subject of the action already has something
*/
ALREADY_HAS(false),
FAIL_ALREADY_HAS(false),
/**
* Indicates the mutation failed because the subject of the action lacks something
*/
LACKS(false),
FAIL_LACKS(false);
/**
* Indicates the mutation failed
*/
FAIL(false);
private final boolean successful;
private final boolean success;
DataMutateResult(boolean success) {
this.success = success;
DataMutateResult(boolean successful) {
this.successful = successful;
}
@Override
public boolean wasSuccessful() {
return this.success;
return this.successful;
}
/**
* Extension of {@link DataMutateResult} for temporary set operations.
*/
public interface WithMergedNode {
/**
* Gets the underlying result.
*
* @return the result
*/
@NonNull DataMutateResult getResult();
/**
* Gets the node that resulted from any {@link TemporaryNodeMergeStrategy}
* processing.
*
* <p>If no processing took place, the same instance will be returned by
* this method.</p>
*
* @return the resultant node
*/
@NonNull Node getMergedNode();
}
}
@@ -1,5 +1,5 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
* This file is part of luckperms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
@@ -23,7 +23,7 @@
* SOFTWARE.
*/
package net.luckperms.api.model;
package net.luckperms.api.model.data;
/**
* Represents a type of data.
@@ -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.model.data;
import net.luckperms.api.context.ContextSet;
import net.luckperms.api.context.ImmutableContextSet;
import net.luckperms.api.model.PermissionHolder;
import net.luckperms.api.model.group.Group;
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.Node;
import net.luckperms.api.node.NodeEqualityPredicate;
import net.luckperms.api.node.Tristate;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Collection;
import java.util.Map;
import java.util.UUID;
import java.util.function.Predicate;
/**
* Encapsulates a store of data ({@link Node}s) within a {@link PermissionHolder}.
*
* <p>The effect of any mutate operation will not persist in storage unless changes are
* explicitly saved. If changes are not saved, the effect will only be observed until the next
* time the holders permission data is (re)loaded. Changes to {@link User}s should be saved
* using {@link UserManager#saveUser(User)}, and changes to {@link Group}s should be saved
* using {@link GroupManager#saveGroup(Group)}.</p>
*
* <p>Before making changes to a user or group, it may be a good idea to load a fresh copy of
* the backing data from the storage if you haven't done so already, to avoid overwriting changes
* made already. This can be done via {@link UserManager#loadUser(UUID)} or
* {@link GroupManager#loadGroup(String)} respectively.</p>
*/
public interface NodeMap {
/**
* Gets a map of the {@link Node}s contained within this instance,
* mapped to their defined {@link Node#getContexts() context}.
*
* @return a map of nodes
*/
@NonNull Map<ImmutableContextSet, Collection<Node>> toMap();
/**
* Gets a flattened view of {@link Node}s contained within this instance.
*
* <p>Effectively combines the value collections of the map returned by
* {@link #toMap()}.</p>
*
* @return a flattened collection of nodes
*/
@NonNull Collection<Node> toCollection();
/**
* Gets if this instance contains a given {@link Node}.
*
* <p>Returns {@link Tristate#UNDEFINED} if the instance does not contain the node,
* and the {@link Node#getValue() assigned value} of the node as a {@link Tristate}
* if it is present.</p>
*
* @param node the node to check for
* @param equalityPredicate how to determine if a node matches
* @return a Tristate relating to the assigned state of the node
* @throws NullPointerException if the node is null
*/
@NonNull Tristate contains(@NonNull Node node, @NonNull NodeEqualityPredicate equalityPredicate);
/**
* Adds a node.
*
* @param node the node to be add
* @return the result of the operation
*/
@NonNull DataMutateResult add(@NonNull Node node);
/**
* Adds a node.
*
* @param node the node to add
* @param temporaryNodeMergeStrategy the strategy used to merge temporary permission entries
* @return the result of the operation
*/
DataMutateResult.@NonNull WithMergedNode add(@NonNull Node node, @NonNull TemporaryNodeMergeStrategy temporaryNodeMergeStrategy);
/**
* Removes a node.
*
* @param node the node to remove
* @return the result of the operation
*/
@NonNull DataMutateResult remove(@NonNull Node node);
/**
* Clears all nodes.
*/
void clear();
/**
* Clears any nodes which pass the predicate.
*
* @param test the predicate to test for nodes which should be removed
*/
void clear(@NonNull Predicate<? super Node> test);
/**
* Clears all nodes in a specific context.
*
* @param contextSet the contexts to filter by
*/
void clear(@NonNull ContextSet contextSet);
/**
* Clears all nodes in a specific context which pass the predicate.
*
* @param contextSet the contexts to filter by
* @param test the predicate to test for nodes which should be removed
*/
void clear(@NonNull ContextSet contextSet, @NonNull Predicate<? super Node> test);
}
@@ -1,5 +1,5 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
* This file is part of luckperms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
@@ -23,9 +23,8 @@
* SOFTWARE.
*/
package net.luckperms.api.model;
package net.luckperms.api.model.data;
import net.luckperms.api.model.PermissionHolder.NodeMap;
import net.luckperms.api.node.Node;
/**
@@ -33,13 +32,13 @@ import net.luckperms.api.node.Node;
* that would otherwise conflict with existing entries.
*
* <p>The default behaviour of {@link NodeMap#add(Node)} is
* to return a result of {@link DataMutateResult#ALREADY_HAS} when an equivalent
* node is found. This can be replicated using {@link #FAIL_WITH_ALREADY_HAS}.</p>
* to return a result of {@link DataMutateResult#FAIL_ALREADY_HAS} when an equivalent
* node is found. This can be replicated using {@link #NONE}.</p>
*
* <p>However, the {@link NodeMap#add(Node, TemporaryMergeBehaviour)}
* <p>However, the {@link NodeMap#add(Node, TemporaryNodeMergeStrategy)}
* method allows this behaviour to be customized for temporary permissions.</p>
*/
public enum TemporaryMergeBehaviour {
public enum TemporaryNodeMergeStrategy {
/**
* Expiry durations will be added to the existing expiry time of a permission.
@@ -54,6 +53,6 @@ public enum TemporaryMergeBehaviour {
/**
* The operation will fail if an existing temporary node is present.
*/
FAIL_WITH_ALREADY_HAS
NONE
}
@@ -25,8 +25,8 @@
package net.luckperms.api.model.user;
import net.luckperms.api.model.DataMutateResult;
import net.luckperms.api.model.PermissionHolder;
import net.luckperms.api.model.data.DataMutateResult;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -28,6 +28,7 @@ package net.luckperms.api.platform;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.time.Instant;
import java.util.Collection;
import java.util.Set;
import java.util.UUID;
@@ -50,6 +51,13 @@ public interface Platform {
*/
@NonNull Set<UUID> getUniqueConnections();
/**
* Gets a {@link Collection} of all known permission strings.
*
* @return a collection of the known permissions
*/
@NonNull Collection<String> getKnownPermissions();
/**
* Gets the time when the plugin first started.
*
@@ -25,7 +25,7 @@
package net.luckperms.api.query.dataorder;
import net.luckperms.api.model.DataType;
import net.luckperms.api.model.data.DataType;
import net.luckperms.api.query.QueryOptions;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -25,8 +25,8 @@
package net.luckperms.api.query.dataorder;
import net.luckperms.api.model.DataType;
import net.luckperms.api.model.PermissionHolder;
import net.luckperms.api.model.data.DataType;
import net.luckperms.api.query.OptionKey;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -26,7 +26,7 @@
package net.luckperms.api.track;
import net.luckperms.api.context.ContextSet;
import net.luckperms.api.model.DataMutateResult;
import net.luckperms.api.model.data.DataMutateResult;
import net.luckperms.api.model.group.Group;
import net.luckperms.api.model.user.User;
@@ -58,13 +58,6 @@ public interface Track {
*/
@NonNull List<String> getGroups();
/**
* Gets the number of groups on this track
*
* @return the number of groups on this track
*/
int getSize();
/**
* Gets the next group on the track, after the one provided
*