diff --git a/api/pom.xml b/api/pom.xml
index ad2cd2fee..c6e609290 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -5,7 +5,7 @@
luckpermsme.lucko.luckperms
- 3.1-SNAPSHOT
+ 3.2-SNAPSHOT4.0.0
diff --git a/api/src/main/java/me/lucko/luckperms/LuckPerms.java b/api/src/main/java/me/lucko/luckperms/LuckPerms.java
index ec2e1c80f..a47a7d35a 100644
--- a/api/src/main/java/me/lucko/luckperms/LuckPerms.java
+++ b/api/src/main/java/me/lucko/luckperms/LuckPerms.java
@@ -49,7 +49,7 @@ public final class LuckPerms {
}
/**
- * Gets an instance of {@link LuckPermsApi} safely.
+ * Gets an instance of {@link LuckPermsApi}, if it is loaded.
*
*
Unlike {@link LuckPerms#getApi}, this method will not throw an {@link IllegalStateException} if the API is
* not loaded, rather return an empty {@link Optional}.
@@ -60,10 +60,12 @@ public final class LuckPerms {
return Optional.ofNullable(api);
}
+ /* method used by the implementation to set the singleton instance */
static void registerProvider(LuckPermsApi luckPermsApi) {
api = luckPermsApi;
}
+ /* method used by the implementation to remove any previous instance */
static void unregisterProvider() {
api = null;
}
diff --git a/common/src/main/java/me/lucko/luckperms/common/metastacking/MetaType.java b/api/src/main/java/me/lucko/luckperms/api/ChatMetaType.java
similarity index 73%
rename from common/src/main/java/me/lucko/luckperms/common/metastacking/MetaType.java
rename to api/src/main/java/me/lucko/luckperms/api/ChatMetaType.java
index e53d68161..413fa7969 100644
--- a/common/src/main/java/me/lucko/luckperms/common/metastacking/MetaType.java
+++ b/api/src/main/java/me/lucko/luckperms/api/ChatMetaType.java
@@ -23,14 +23,20 @@
* SOFTWARE.
*/
-package me.lucko.luckperms.common.metastacking;
-
-import me.lucko.luckperms.api.Node;
+package me.lucko.luckperms.api;
import java.util.Map;
-public enum MetaType {
+/**
+ * Represents a type of chat meta
+ *
+ * @since 3.2
+ */
+public enum ChatMetaType {
+ /**
+ * Represents a prefix
+ */
PREFIX {
@Override
public boolean matches(Node node) {
@@ -48,6 +54,9 @@ public enum MetaType {
}
},
+ /**
+ * Represents a suffix
+ */
SUFFIX {
@Override
public boolean matches(Node node) {
@@ -65,10 +74,29 @@ public enum MetaType {
}
};
+ /**
+ * Returns if the passed node matches the type
+ *
+ * @param node the node to test
+ * @return true if the node has the same type
+ */
public abstract boolean matches(Node node);
+ /**
+ * Returns if the passed node should be ignored when searching for meta of this type
+ *
+ * @param node the node to test
+ * @return true if the node does not share the same type
+ */
public abstract boolean shouldIgnore(Node node);
+ /**
+ * Maps the corresponding entry from the given node
+ *
+ * @param node the node to retrieve the entry from
+ * @return the entry
+ * @throws IllegalStateException if the node does not share the same type
+ */
public abstract Map.Entry getEntry(Node node);
}
diff --git a/api/src/main/java/me/lucko/luckperms/api/Contexts.java b/api/src/main/java/me/lucko/luckperms/api/Contexts.java
index 1326909cf..4c11e5194 100644
--- a/api/src/main/java/me/lucko/luckperms/api/Contexts.java
+++ b/api/src/main/java/me/lucko/luckperms/api/Contexts.java
@@ -165,6 +165,7 @@ public class Contexts {
return this.applyGlobalWorldGroups;
}
+ @Override
public String toString() {
return "Contexts(" +
"context=" + this.getContexts() + ", " +
@@ -181,18 +182,12 @@ public class Contexts {
* Ugly auto-generated lombok code
*/
- /**
- * Check for equality
- *
- * @param o the other
- * @return true if equal
- * @since 2.12
- */
+ @Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof Contexts)) return false;
final Contexts other = (Contexts) o;
- return (this.getContexts() == null ? other.getContexts() == null : this.getContexts().equals(other.getContexts())) &&
+ return this.getContexts().equals(other.getContexts()) &&
this.isOp() == other.isOp() &&
this.isIncludeGlobal() == other.isIncludeGlobal() &&
this.isIncludeGlobalWorld() == other.isIncludeGlobalWorld() &&
@@ -201,12 +196,7 @@ public class Contexts {
this.isApplyGlobalWorldGroups() == other.isApplyGlobalWorldGroups();
}
- /**
- * Gets the hashcode
- *
- * @return the hashcode
- * @since 2.12
- */
+ @Override
public int hashCode() {
final int PRIME = 59;
int result = 1;
diff --git a/api/src/main/java/me/lucko/luckperms/api/Group.java b/api/src/main/java/me/lucko/luckperms/api/Group.java
index c9595c2a0..af0f6676b 100644
--- a/api/src/main/java/me/lucko/luckperms/api/Group.java
+++ b/api/src/main/java/me/lucko/luckperms/api/Group.java
@@ -22,6 +22,7 @@
package me.lucko.luckperms.api;
+import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksException;
@@ -41,7 +42,7 @@ public interface Group extends PermissionHolder {
String getName();
/**
- * Check to see if a group inherits a group
+ * Check to see if a group inherits another group directly
*
* @param group The group to check membership of
* @return true if the group inherits the other group
@@ -50,6 +51,26 @@ public interface Group extends PermissionHolder {
*/
boolean inheritsGroup(Group group);
+ /**
+ * Check to see if a group inherits another group directly
+ *
+ * @param group The group to check membership of
+ * @param contextSet the context set to filter by
+ * @return true if the group inherits the other group
+ * @throws NullPointerException if the group is null
+ * @throws IllegalStateException if the group instance was not obtained from LuckPerms.
+ * @since 3.2
+ */
+ boolean inheritsGroup(Group group, ContextSet contextSet);
+
+ /**
+ * Gets the weight of this group, if present.
+ *
+ * @return the group weight
+ * @since 2.17
+ */
+ OptionalInt getWeight();
+
/**
* Check to see if the group inherits a group on a specific server
*
@@ -59,7 +80,9 @@ public interface Group extends PermissionHolder {
* @throws NullPointerException if the group or server is null
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
* @throws IllegalArgumentException if the server is invalid
+ * @deprecated in favour of {@link #inheritsGroup(Group, ContextSet)}
*/
+ @Deprecated
boolean inheritsGroup(Group group, String server);
/**
@@ -72,7 +95,9 @@ public interface Group extends PermissionHolder {
* @throws NullPointerException if the group, server or world is null
* @throws IllegalStateException if the group instance was not obtained from LuckPerms.
* @throws IllegalArgumentException if the server or world is invalid
+ * @deprecated in favour of {@link #inheritsGroup(Group, ContextSet)}
*/
+ @Deprecated
boolean inheritsGroup(Group group, String server, String world);
/**
@@ -250,7 +275,9 @@ public interface Group extends PermissionHolder {
* Get a {@link List} of all of the groups the group inherits, on all servers
*
* @return a {@link List} of group names
+ * @deprecated in favour of just querying a users permissions
*/
+ @Deprecated
List getGroupNames();
/**
@@ -260,7 +287,9 @@ public interface Group extends PermissionHolder {
* @return a {@link List} of group names
* @throws NullPointerException if the server is null
* @throws IllegalArgumentException if the server is invalid
+ * @deprecated in favour of just querying a users permissions
*/
+ @Deprecated
List getLocalGroups(String server);
@@ -272,15 +301,9 @@ public interface Group extends PermissionHolder {
* @return a {@link List} of group names
* @throws NullPointerException if the server or world is null
* @throws IllegalArgumentException if the server or world is invalid
+ * @deprecated in favour of just querying a users permissions
*/
+ @Deprecated
List getLocalGroups(String server, String world);
- /**
- * Gets the weight of this group, is present.
- *
- * @return the group weight
- * @since 2.17
- */
- OptionalInt getWeight();
-
}
diff --git a/api/src/main/java/me/lucko/luckperms/api/Logger.java b/api/src/main/java/me/lucko/luckperms/api/Logger.java
index a0369ed8e..5d1abd4b0 100644
--- a/api/src/main/java/me/lucko/luckperms/api/Logger.java
+++ b/api/src/main/java/me/lucko/luckperms/api/Logger.java
@@ -23,10 +23,10 @@
package me.lucko.luckperms.api;
/**
- * A wrapper interface for platform logger instances
+ * Represents the logger instance being used by LuckPerms on the platform.
*
- *
Bukkit/Bungee both use java.util.logging, and Sponge uses org.slf4j. This class wraps those classes so the
- * commons module can access a logger.
+ *
Messages sent using the logger are sent prefixed with the LuckPerms tag, and on some implementations will be colored
+ * depending on the message type.
*/
public interface Logger {
diff --git a/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java b/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java
index 891b1a1e1..947c5a41b 100644
--- a/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java
+++ b/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java
@@ -25,6 +25,7 @@ package me.lucko.luckperms.api;
import me.lucko.luckperms.api.context.ContextCalculator;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.api.event.EventBus;
+import me.lucko.luckperms.api.metastacking.MetaStackFactory;
import java.util.Optional;
import java.util.Set;
@@ -42,6 +43,7 @@ public interface LuckPermsApi {
/**
* Gets the API version
+ *
* @return the version of the API running on the platform
* @since 2.6
*/
@@ -49,12 +51,14 @@ public interface LuckPermsApi {
/**
* Gets the plugin version
+ *
* @return the version of the plugin running on the platform
*/
String getVersion();
/**
* Gets the platform LuckPerms is running on
+ *
* @return the platform LuckPerms is running on
* @since 2.7
*/
@@ -62,6 +66,7 @@ public interface LuckPermsApi {
/**
* Gets the event bus, used for subscribing to events
+ *
* @return the event bus
* @since 3.0
*/
@@ -247,6 +252,14 @@ public interface LuckPermsApi {
*/
NodeFactory getNodeFactory();
+ /**
+ * Gets the MetaStackFactory, used for creating MetaStacks.
+ *
+ * @return the meta stack factory
+ * @since 3.2
+ */
+ MetaStackFactory getMetaStackFactory();
+
/**
* Returns a permission builder instance
*
diff --git a/api/src/main/java/me/lucko/luckperms/api/Node.java b/api/src/main/java/me/lucko/luckperms/api/Node.java
index 8e86bee2d..4b618d1de 100644
--- a/api/src/main/java/me/lucko/luckperms/api/Node.java
+++ b/api/src/main/java/me/lucko/luckperms/api/Node.java
@@ -40,12 +40,14 @@ import java.util.Set;
public interface Node extends Map.Entry {
/**
+ * Returns the actual permission string
+ *
* @return the actual permission node
*/
String getPermission();
/**
- * Get what value the permission is set to. A negated node would return false.
+ * Gets what value the permission is set to. A negated node would return false.
*
* @return the permission's value
*/
@@ -53,14 +55,22 @@ public interface Node extends Map.Entry {
Boolean getValue();
/**
+ * Returns the value of this node as a tristate
+ *
* @return the value of this node as a Tristate
*/
- Tristate getTristate();
+ default Tristate getTristate() {
+ return Tristate.fromBoolean(getValue());
+ }
/**
+ * Returns if the node is negated
+ *
* @return true if the node is negated
*/
- boolean isNegated();
+ default boolean isNegated() {
+ return !getValue();
+ }
/**
* If this node is set to override explicitly.
@@ -201,28 +211,40 @@ public interface Node extends Map.Entry {
List resolveShorthand();
/**
+ * Returns if this node will expire in the future
+ *
* @return true if this node will expire in the future
*/
boolean isTemporary();
/**
+ * Returns if this node will not expire
+ *
* @return true if this node will not expire
*/
- boolean isPermanent();
+ default boolean isPermanent() {
+ return !isTemporary();
+ }
/**
+ * Returns a unix timestamp in seconds when this node will expire
+ *
* @return the time in Unix time when this node will expire
* @throws IllegalStateException if the node is not temporary
*/
long getExpiryUnixTime();
/**
+ * Returns the date when this node will expire
+ *
* @return the {@link Date} when this node will expire
* @throws IllegalStateException if the node is not temporary
*/
Date getExpiry();
/**
+ * Return the number of seconds until this permission will expire
+ *
* @return the number of seconds until this permission will expire
* @throws IllegalStateException if the node is not temporary
*/
@@ -307,6 +329,8 @@ public interface Node extends Map.Entry {
Map.Entry getMeta();
/**
+ * Returns if this node is a prefix node
+ *
* @return true if this node is a prefix node
*/
boolean isPrefix();
@@ -320,6 +344,8 @@ public interface Node extends Map.Entry {
Map.Entry getPrefix();
/**
+ * Returns if this node is a suffix node
+ *
* @return true if this node is a suffix node
*/
boolean isSuffix();
diff --git a/api/src/main/java/me/lucko/luckperms/api/NodeFactory.java b/api/src/main/java/me/lucko/luckperms/api/NodeFactory.java
index 33800e42e..34b6d67b0 100644
--- a/api/src/main/java/me/lucko/luckperms/api/NodeFactory.java
+++ b/api/src/main/java/me/lucko/luckperms/api/NodeFactory.java
@@ -36,7 +36,10 @@ public interface NodeFactory {
* @param value the value of the node
* @return a node instance
* @throws NullPointerException if the permission is null
+ * @deprecated since this format isn't used internally for permissions anymore
+ * @see Node#toSerializedNode()
*/
+ @Deprecated
Node fromSerialisedNode(String serialisedPermission, boolean value);
@@ -65,7 +68,10 @@ public interface NodeFactory {
* @param value the value of the node
* @return a node builder instance
* @throws NullPointerException if the permission is null
+ * @deprecated since this format isn't used internally for permissions anymore
+ * @see Node#toSerializedNode()
*/
+ @Deprecated
Node.Builder newBuilderFromSerialisedNode(String serialisedPermission, boolean value);
@@ -90,6 +96,17 @@ public interface NodeFactory {
*/
Node.Builder makeMetaNode(String key, String value);
+ /**
+ * Creates a node builder for the given chat meta type
+ *
+ * @param priority the priority
+ * @param value the value for the prefix/suffix
+ * @return a node builder instance
+ * @throws NullPointerException if the type or value is null
+ * @since 3.2
+ */
+ Node.Builder makeChatMetaNode(ChatMetaType type, int priority, String value);
+
/**
* Creates a node builder from a prefix string and priority
*
diff --git a/api/src/main/java/me/lucko/luckperms/api/PermissionHolder.java b/api/src/main/java/me/lucko/luckperms/api/PermissionHolder.java
index 8714f254a..83135db4a 100644
--- a/api/src/main/java/me/lucko/luckperms/api/PermissionHolder.java
+++ b/api/src/main/java/me/lucko/luckperms/api/PermissionHolder.java
@@ -22,12 +22,14 @@
package me.lucko.luckperms.api;
+import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksException;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
+import java.util.function.Predicate;
/**
* An object capable of holding permissions
@@ -46,6 +48,17 @@ public interface PermissionHolder {
*/
String getObjectName();
+ /**
+ * Gets a friendly name for this holder, to be displayed in command output, etc.
+ *
+ *
This will always return a value, eventually falling back to {@link #getObjectName()} if no
+ * other "friendlier" identifiers are present.
+ *
+ * @return a friendly identifier for this holder
+ * @since 3.2
+ */
+ String getFriendlyName();
+
/**
* Gets a sorted set of all held permissions.
*
@@ -57,21 +70,39 @@ public interface PermissionHolder {
/**
* Similar to {@link #getPermissions()}, except without transient permissions
*
+ *
Unlike transient permissions, enduring permissions will be saved to storage, and exist after the session.
+ *
* @return a set of nodes
* @since 2.6
*/
Set extends Node> getEnduringPermissions();
/**
- * Gets an immutable set of all transiently held permissions.
+ * Similar to {@link #getPermissions()}, except without enduring permissions
*
- *
Transient permissions only exist for the duration of the session.
+ *
Transient permissions only exist for the duration of the session.
*
* @return a set of nodes
* @since 2.6
*/
Set extends Node> getTransientPermissions();
+ /**
+ * Processes the nodes and returns the non-temporary ones.
+ *
+ * @return a set of permanent nodes
+ * @since 2.6
+ */
+ Set getPermanentPermissionNodes();
+
+ /**
+ * Processes the nodes and returns the temporary ones.
+ *
+ * @return a set of temporary nodes
+ * @since 2.6
+ */
+ Set getTemporaryPermissionNodes();
+
/**
* Gets a mutable sorted set of the nodes that this object has and inherits, filtered by context
*
@@ -80,7 +111,7 @@ public interface PermissionHolder {
*
*
Nodes are sorted into priority order.
*
- * @param contexts the context for the lookup,
+ * @param contexts the context for the lookup
* @return a mutable sorted set of permissions
* @throws NullPointerException if the context is null
* @since 2.11
@@ -134,81 +165,6 @@ public interface PermissionHolder {
*/
Tristate hasTransientPermission(Node node);
- /**
- * Checks to see if the object has a certain permission
- *
- * @param node The permission node
- * @param b If the node is true/false(negated)
- * @return true if the object has the permission
- * @throws NullPointerException if the node is null
- * @throws IllegalArgumentException if the node is invalid
- */
- boolean hasPermission(String node, boolean b);
-
- /**
- * Checks to see the the object has a permission on a certain server
- *
- * @param node The permission node
- * @param b If the node is true/false(negated)
- * @param server The server
- * @return true if the object has the permission
- * @throws NullPointerException if the node or server is null
- * @throws IllegalArgumentException if the node or server is invalid
- */
- boolean hasPermission(String node, boolean b, String server);
-
- /**
- * Checks to see the the object has a permission on a certain server and world
- *
- * @param node The permission node
- * @param b If the node is true/false(negated)
- * @param server The server
- * @param world The world
- * @return true if the object has the permission
- * @throws NullPointerException if the node, server or world is null
- * @throws IllegalArgumentException if the node, server or world is invalid
- */
- boolean hasPermission(String node, boolean b, String server, String world);
-
- /**
- * Checks to see the the object has a permission
- *
- * @param node The permission node
- * @param b If the node is true/false(negated)
- * @param temporary if the permission is temporary
- * @return true if the object has the permission
- * @throws NullPointerException if the node is null
- * @throws IllegalArgumentException if the node is invalid
- */
- boolean hasPermission(String node, boolean b, boolean temporary);
-
- /**
- * Checks to see the the object has a permission on a certain server
- *
- * @param node The permission node
- * @param b If the node is true/false(negated)
- * @param server The server to check on
- * @param temporary if the permission is temporary
- * @return true if the object has the permission
- * @throws NullPointerException if the node or server is null
- * @throws IllegalArgumentException if the node or server is invalid
- */
- boolean hasPermission(String node, boolean b, String server, boolean temporary);
-
- /**
- * Checks to see the the object has a permission on a certain server and world
- *
- * @param node The permission node
- * @param b If the node is true/false(negated)
- * @param server The server to check on
- * @param world The world to check on
- * @param temporary if the permission is temporary
- * @return true if the object has the permission
- * @throws NullPointerException if the node, server or world is null
- * @throws IllegalArgumentException if the node, server or world is invalid
- */
- boolean hasPermission(String node, boolean b, String server, String world, boolean temporary);
-
/**
* Checks to see if the object inherits a certain permission
*
@@ -219,81 +175,6 @@ public interface PermissionHolder {
*/
Tristate inheritsPermission(Node node);
- /**
- * Checks to see if the object inherits a certain permission
- *
- * @param node The permission node
- * @param b If the node is true/false(negated)
- * @return true if the object inherits the permission
- * @throws NullPointerException if the node is null
- * @throws IllegalArgumentException if the node is invalid
- */
- boolean inheritsPermission(String node, boolean b);
-
- /**
- * Checks to see the the object inherits a permission on a certain server
- *
- * @param node The permission node
- * @param b If the node is true/false(negated)
- * @param server The server
- * @return true if the object inherits the permission
- * @throws NullPointerException if the node or server is null
- * @throws IllegalArgumentException if the node or server is invalid
- */
- boolean inheritsPermission(String node, boolean b, String server);
-
- /**
- * Checks to see the the object inherits a permission on a certain server and world
- *
- * @param node The permission node
- * @param b If the node is true/false(negated)
- * @param server The server
- * @param world The world
- * @return true if the object inherits the permission
- * @throws NullPointerException if the node, server or world is null
- * @throws IllegalArgumentException if the node server or world is invalid
- */
- boolean inheritsPermission(String node, boolean b, String server, String world);
-
- /**
- * Checks to see if the object inherits a permission
- *
- * @param node The permission node
- * @param b If the node is true/false(negated)
- * @param temporary if the permission is temporary
- * @return true if the object inherits the permission
- * @throws NullPointerException if the node is null
- * @throws IllegalArgumentException if the node is invalid
- */
- boolean inheritsPermission(String node, boolean b, boolean temporary);
-
- /**
- * Checks to see if the object inherits a permission on a certain server
- *
- * @param node The permission node
- * @param b If the node is true/false(negated)
- * @param server The server
- * @param temporary if the permission is temporary
- * @return true if the object inherits the permission
- * @throws NullPointerException if the node or server is null
- * @throws IllegalArgumentException if the node or server is invalid
- */
- boolean inheritsPermission(String node, boolean b, String server, boolean temporary);
-
- /**
- * Checks to see if the object inherits a permission on a certain server and world
- *
- * @param node The permission node
- * @param b If the node is true/false(negated)
- * @param server The server
- * @param world The world
- * @param temporary if the permission is temporary
- * @return true if the object inherits the permission
- * @throws NullPointerException if the node, server or world is null
- * @throws IllegalArgumentException if the node, server or world if invalid
- */
- boolean inheritsPermission(String node, boolean b, String server, String world, boolean temporary);
-
/**
* Sets a permission for the object
*
@@ -352,6 +233,286 @@ public interface PermissionHolder {
*/
DataMutateResult setTransientPermissionUnchecked(Node node);
+ /**
+ * Unsets a permission for the object
+ *
+ * @param node The node to be unset
+ * @throws ObjectLacksException if the node wasn't already set
+ * @throws NullPointerException if the node is null
+ * @since 2.6
+ */
+ void unsetPermission(Node node) throws ObjectLacksException;
+
+ /**
+ * Unsets a permission for the object
+ *
+ * @param node The node to be unset
+ * @throws NullPointerException if the node is null
+ * @return the result of the operation
+ * @since 3.1
+ */
+ DataMutateResult unsetPermissionUnchecked(Node node);
+
+ /**
+ * Unsets a transient permission for the object
+ *
+ * @param node The node to be unset
+ * @throws ObjectLacksException if the node wasn't already set
+ * @throws NullPointerException if the node is null
+ * @since 2.6
+ */
+ void unsetTransientPermission(Node node) throws ObjectLacksException;
+
+ /**
+ * Unsets a transient permission for the object
+ *
+ * @param node The node to be unset
+ * @throws NullPointerException if the node is null
+ * @return the result of the operation
+ * @since 3.1
+ */
+ DataMutateResult unsetTransientPermissionUnchecked(Node node);
+
+ /**
+ * Clears any nodes from the holder which pass the predicate
+ *
+ * @param test the predicate to test for nodes which should be removed
+ * @since 3.2
+ */
+ void clearMatching(Predicate test);
+
+ /**
+ * Clears any transient nodes from the holder which pass the predicate
+ *
+ * @param test the predicate to test for nodes which should be removed
+ * @since 3.2
+ */
+ void clearMatchingTransient(Predicate test);
+
+ /**
+ * Clears all nodes held by the object
+ *
+ * @since 2.17
+ */
+ void clearNodes();
+
+ /**
+ * Clears all nodes held by the object in a specific context
+ *
+ * @param contextSet the contexts to filter by
+ * @since 3.2
+ */
+ void clearNodes(ContextSet contextSet);
+
+ /**
+ * Clears all parent groups
+ *
+ * @since 2.17
+ */
+ void clearParents();
+
+ /**
+ * Clears all parent groups in a specific context
+ *
+ * @param contextSet the contexts to filter by
+ * @since 3.2
+ */
+ void clearParents(ContextSet contextSet);
+
+ /**
+ * Clears all meta held by the object
+ *
+ * @since 2.17
+ */
+ void clearMeta();
+
+ /**
+ * Clears all meta held by the object in a specific context
+ *
+ * @param contextSet the contexts to filter by
+ * @since 3.2
+ */
+ void clearMeta(ContextSet contextSet);
+
+ /**
+ * Clears all transient permissions the holder has.
+ */
+ void clearTransientNodes();
+
+ /**
+ * Checks to see if the object has a certain permission
+ *
+ * @param node The permission node
+ * @param b If the node is true/false(negated)
+ * @return true if the object has the permission
+ * @throws NullPointerException if the node is null
+ * @throws IllegalArgumentException if the node is invalid
+ * @deprecated in favour of {@link #hasPermission(Node)}
+ */
+ @Deprecated
+ boolean hasPermission(String node, boolean b);
+
+ /**
+ * Checks to see the the object has a permission on a certain server
+ *
+ * @param node The permission node
+ * @param b If the node is true/false(negated)
+ * @param server The server
+ * @return true if the object has the permission
+ * @throws NullPointerException if the node or server is null
+ * @throws IllegalArgumentException if the node or server is invalid
+ * @deprecated in favour of {@link #hasPermission(Node)}
+ */
+ @Deprecated
+ boolean hasPermission(String node, boolean b, String server);
+
+ /**
+ * Checks to see the the object has a permission on a certain server and world
+ *
+ * @param node The permission node
+ * @param b If the node is true/false(negated)
+ * @param server The server
+ * @param world The world
+ * @return true if the object has the permission
+ * @throws NullPointerException if the node, server or world is null
+ * @throws IllegalArgumentException if the node, server or world is invalid
+ * @deprecated in favour of {@link #hasPermission(Node)}
+ */
+ @Deprecated
+ boolean hasPermission(String node, boolean b, String server, String world);
+
+ /**
+ * Checks to see the the object has a permission
+ *
+ * @param node The permission node
+ * @param b If the node is true/false(negated)
+ * @param temporary if the permission is temporary
+ * @return true if the object has the permission
+ * @throws NullPointerException if the node is null
+ * @throws IllegalArgumentException if the node is invalid
+ * @deprecated in favour of {@link #hasPermission(Node)}
+ */
+ @Deprecated
+ boolean hasPermission(String node, boolean b, boolean temporary);
+
+ /**
+ * Checks to see the the object has a permission on a certain server
+ *
+ * @param node The permission node
+ * @param b If the node is true/false(negated)
+ * @param server The server to check on
+ * @param temporary if the permission is temporary
+ * @return true if the object has the permission
+ * @throws NullPointerException if the node or server is null
+ * @throws IllegalArgumentException if the node or server is invalid
+ * @deprecated in favour of {@link #hasPermission(Node)}
+ */
+ @Deprecated
+ boolean hasPermission(String node, boolean b, String server, boolean temporary);
+
+ /**
+ * Checks to see the the object has a permission on a certain server and world
+ *
+ * @param node The permission node
+ * @param b If the node is true/false(negated)
+ * @param server The server to check on
+ * @param world The world to check on
+ * @param temporary if the permission is temporary
+ * @return true if the object has the permission
+ * @throws NullPointerException if the node, server or world is null
+ * @throws IllegalArgumentException if the node, server or world is invalid
+ * @deprecated in favour of {@link #hasPermission(Node)}
+ */
+ @Deprecated
+ boolean hasPermission(String node, boolean b, String server, String world, boolean temporary);
+
+ /**
+ * Checks to see if the object inherits a certain permission
+ *
+ * @param node The permission node
+ * @param b If the node is true/false(negated)
+ * @return true if the object inherits the permission
+ * @throws NullPointerException if the node is null
+ * @throws IllegalArgumentException if the node is invalid
+ * @deprecated in favour of {@link #hasPermission(Node)}
+ */
+ @Deprecated
+ boolean inheritsPermission(String node, boolean b);
+
+ /**
+ * Checks to see the the object inherits a permission on a certain server
+ *
+ * @param node The permission node
+ * @param b If the node is true/false(negated)
+ * @param server The server
+ * @return true if the object inherits the permission
+ * @throws NullPointerException if the node or server is null
+ * @throws IllegalArgumentException if the node or server is invalid
+ * @deprecated in favour of {@link #hasPermission(Node)}
+ */
+ @Deprecated
+ boolean inheritsPermission(String node, boolean b, String server);
+
+ /**
+ * Checks to see the the object inherits a permission on a certain server and world
+ *
+ * @param node The permission node
+ * @param b If the node is true/false(negated)
+ * @param server The server
+ * @param world The world
+ * @return true if the object inherits the permission
+ * @throws NullPointerException if the node, server or world is null
+ * @throws IllegalArgumentException if the node server or world is invalid
+ * @deprecated in favour of {@link #hasPermission(Node)}
+ */
+ @Deprecated
+ boolean inheritsPermission(String node, boolean b, String server, String world);
+
+ /**
+ * Checks to see if the object inherits a permission
+ *
+ * @param node The permission node
+ * @param b If the node is true/false(negated)
+ * @param temporary if the permission is temporary
+ * @return true if the object inherits the permission
+ * @throws NullPointerException if the node is null
+ * @throws IllegalArgumentException if the node is invalid
+ * @deprecated in favour of {@link #hasPermission(Node)}
+ */
+ @Deprecated
+ boolean inheritsPermission(String node, boolean b, boolean temporary);
+
+ /**
+ * Checks to see if the object inherits a permission on a certain server
+ *
+ * @param node The permission node
+ * @param b If the node is true/false(negated)
+ * @param server The server
+ * @param temporary if the permission is temporary
+ * @return true if the object inherits the permission
+ * @throws NullPointerException if the node or server is null
+ * @throws IllegalArgumentException if the node or server is invalid
+ * @deprecated in favour of {@link #hasPermission(Node)}
+ */
+ @Deprecated
+ boolean inheritsPermission(String node, boolean b, String server, boolean temporary);
+
+ /**
+ * Checks to see if the object inherits a permission on a certain server and world
+ *
+ * @param node The permission node
+ * @param b If the node is true/false(negated)
+ * @param server The server
+ * @param world The world
+ * @param temporary if the permission is temporary
+ * @return true if the object inherits the permission
+ * @throws NullPointerException if the node, server or world is null
+ * @throws IllegalArgumentException if the node, server or world if invalid
+ * @deprecated in favour of {@link #hasPermission(Node)}
+ */
+ @Deprecated
+ boolean inheritsPermission(String node, boolean b, String server, String world, boolean temporary);
+
/**
* Sets a permission for the object
*
@@ -439,46 +600,6 @@ public interface PermissionHolder {
@Deprecated
void setPermission(String node, boolean value, String server, String world, long expireAt) throws ObjectAlreadyHasException;
- /**
- * Unsets a permission for the object
- *
- * @param node The node to be unset
- * @throws ObjectLacksException if the node wasn't already set
- * @throws NullPointerException if the node is null
- * @since 2.6
- */
- void unsetPermission(Node node) throws ObjectLacksException;
-
- /**
- * Unsets a permission for the object
- *
- * @param node The node to be unset
- * @throws NullPointerException if the node is null
- * @return the result of the operation
- * @since 3.1
- */
- DataMutateResult unsetPermissionUnchecked(Node node);
-
- /**
- * Unsets a transient permission for the object
- *
- * @param node The node to be unset
- * @throws ObjectLacksException if the node wasn't already set
- * @throws NullPointerException if the node is null
- * @since 2.6
- */
- void unsetTransientPermission(Node node) throws ObjectLacksException;
-
- /**
- * Unsets a transient permission for the object
- *
- * @param node The node to be unset
- * @throws NullPointerException if the node is null
- * @return the result of the operation
- * @since 3.1
- */
- DataMutateResult unsetTransientPermissionUnchecked(Node node);
-
/**
* Unsets a permission for the object
*
@@ -560,19 +681,14 @@ public interface PermissionHolder {
@Deprecated
void unsetPermission(String node, String server, String world, boolean temporary) throws ObjectLacksException;
- /**
- * Clears all nodes held by the object
- *
- * @since 2.17
- */
- void clearNodes();
-
/**
* Clears all nodes held by the object on a specific server
*
* @param server the server to filter by, can be null
* @since 2.17
+ * @deprecated in favour of {@link #clearNodes(ContextSet)}
*/
+ @Deprecated
void clearNodes(String server);
/**
@@ -581,22 +697,19 @@ public interface PermissionHolder {
* @param server the server to filter by, can be null
* @param world the world to filter by, can be null
* @since 2.17
+ * @deprecated in favour of {@link #clearNodes(ContextSet)}
*/
+ @Deprecated
void clearNodes(String server, String world);
- /**
- * Clears all parent groups
- *
- * @since 2.17
- */
- void clearParents();
-
/**
* Clears all parents on a specific server
*
* @param server the server to filter by, can be null
* @since 2.17
+ * @deprecated in favour of {@link #clearParents(ContextSet)}
*/
+ @Deprecated
void clearParents(String server);
/**
@@ -605,22 +718,19 @@ public interface PermissionHolder {
* @param server the server to filter by, can be null
* @param world the world to filter by, can be null
* @since 2.17
+ * @deprecated in favour of {@link #clearParents(ContextSet)}
*/
+ @Deprecated
void clearParents(String server, String world);
- /**
- * Clears all meta held by the object
- *
- * @since 2.17
- */
- void clearMeta();
-
/**
* Clears all meta held by the object on a specific server
*
* @param server the server to filter by, can be null
* @since 2.17
+ * @deprecated in favour of {@link #clearMeta(ContextSet)}
*/
+ @Deprecated
void clearMeta(String server);
/**
@@ -629,7 +739,9 @@ public interface PermissionHolder {
* @param server the server to filter by, can be null
* @param world the world to filter by, can be null
* @since 2.17
+ * @deprecated in favour of {@link #clearMeta(ContextSet)}
*/
+ @Deprecated
void clearMeta(String server, String world);
/**
@@ -639,28 +751,9 @@ public interface PermissionHolder {
* @param server the server to filter by, can be null
* @param world the world to filter by, can be null
* @param temporary whether the query is for temporary nodes or not.
+ * @deprecated in favour of {@link #removeIf(Predicate)}
*/
+ @Deprecated
void clearMetaKeys(String key, String server, String world, boolean temporary);
- /**
- * Clears all transient permissions the holder has.
- */
- void clearTransientNodes();
-
- /**
- * Processes the nodes and returns the non-temporary ones.
- *
- * @return a set of permanent nodes
- * @since 2.6
- */
- Set getPermanentPermissionNodes();
-
- /**
- * Processes the nodes and returns the temporary ones.
- *
- * @return a set of temporary nodes
- * @since 2.6
- */
- Set getTemporaryPermissionNodes();
-
}
diff --git a/api/src/main/java/me/lucko/luckperms/api/Tristate.java b/api/src/main/java/me/lucko/luckperms/api/Tristate.java
index dbc5ed1ba..a1d2ef2a3 100644
--- a/api/src/main/java/me/lucko/luckperms/api/Tristate.java
+++ b/api/src/main/java/me/lucko/luckperms/api/Tristate.java
@@ -25,8 +25,8 @@ package me.lucko.luckperms.api;
/**
* Represents a permission setting.
*
- *
Consider a value of {@link #FALSE} to be a "negated" setting, and a value of {@link #UNDEFINED} to be a
- * non-existent value.
+ *
Consider a value of {@link #TRUE} to be a positive setting, {@link #FALSE} to be a "negated" setting,
+ * and a value of {@link #UNDEFINED} to be a non-existent value.
*/
public enum Tristate {
diff --git a/api/src/main/java/me/lucko/luckperms/api/User.java b/api/src/main/java/me/lucko/luckperms/api/User.java
index cb4eea2d6..bf8e48027 100644
--- a/api/src/main/java/me/lucko/luckperms/api/User.java
+++ b/api/src/main/java/me/lucko/luckperms/api/User.java
@@ -23,6 +23,7 @@
package me.lucko.luckperms.api;
import me.lucko.luckperms.api.caching.UserData;
+import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.exceptions.ObjectLacksException;
@@ -45,19 +46,22 @@ public interface User extends PermissionHolder {
/**
* Gets the users username, or null if no username is associated with this user
*
- * @return the Users Username
+ * @return the users username
*/
String getName();
/**
- * Gets the users primary group
+ * Gets the users current primary group.
+ *
+ *
The result of this method depends on which method is configured for primary group calculation. It may not
+ * be the same as any value set through {@link #setPrimaryGroup(String)}.
*
* @return the users primary group
*/
String getPrimaryGroup();
/**
- * Sets a users primary group
+ * Sets a users primary group. This will only take effect if platform is using stored primary groups.
*
* @param group the new primary group
* @throws ObjectAlreadyHasException if the user already has this set as their primary group
@@ -69,35 +73,59 @@ public interface User extends PermissionHolder {
/**
* Refresh and re-assign the users permissions.
*
- *
This request is not buffered, and the refresh call will be ran directly. This should ideally be called on
- * an asynchronous thread.
+ *
This request is not buffered, and the refresh call will be ran directly. This should be called on an
+ * asynchronous thread.
*/
void refreshPermissions();
+ /**
+ * Gets the user's {@link UserData} cache.
+ *
+ * @return the users cached data.
+ * @since 3.2
+ */
+ UserData getCachedData();
+
+ /**
+ * Check to see if the user is a direct member of a group
+ *
+ * @param group The group to check membership of
+ * @return true if the user is a member of the group
+ * @throws NullPointerException if the group is null
+ * @throws IllegalStateException if the group instance was not obtained from LuckPerms.
+ */
+ boolean isInGroup(Group group);
+
+ /**
+ * Check to see if the user is a direct member of a group in a specific context
+ *
+ * @param group the group to check membership of
+ * @param contextSet the context set to filter by
+ * @return true if the user is a member of the group
+ * @throws IllegalStateException if the group instance was not obtained from LuckPerms.
+ * @since 3.2
+ */
+ boolean isInGroup(Group group, ContextSet contextSet);
+
/**
* Gets the user's {@link UserData} cache, if they have one setup.
*
* @return an optional, possibly containing the user's cached lookup data.
* @since 2.13
+ * @deprecated in version 3.2, as this cache is now always loaded
*/
+ @Deprecated
Optional getUserDataCache();
/**
* Sets up the users data cache, if the don't have one setup already.
*
* @since 2.17
+ * @deprecated in version 3.2, as this cache is now always loaded.
*/
+ @Deprecated
void setupDataCache();
- /**
- * Check to see if the user is a member of a group
- *
- * @param group The group to check membership of
- * @return true if the user is a member of the group
- * @throws NullPointerException if the group is null
- */
- boolean isInGroup(Group group);
-
/**
* Check to see if a user is a member of a group on a specific server
*
@@ -106,7 +134,9 @@ public interface User extends PermissionHolder {
* @return true if the user is a member of the group
* @throws NullPointerException if the group or server is null
* @throws IllegalArgumentException if the server is invalid
+ * @deprecated in favour of {@link #isInGroup(Group, ContextSet)}
*/
+ @Deprecated
boolean isInGroup(Group group, String server);
/**
@@ -118,7 +148,9 @@ public interface User extends PermissionHolder {
* @return true if the user is a member of the group
* @throws NullPointerException if the group, server or world is null
* @throws IllegalArgumentException if the server or world is invalid
+ * @deprecated in favour of {@link #isInGroup(Group, ContextSet)}
*/
+ @Deprecated
boolean isInGroup(Group group, String server, String world);
/**
@@ -296,7 +328,9 @@ public interface User extends PermissionHolder {
* Get a {@link List} of all of the groups the user is a member of, on all servers
*
* @return a {@link List} of group names
+ * @deprecated in favour of just querying a users permissions
*/
+ @Deprecated
List getGroupNames();
/**
@@ -307,7 +341,9 @@ public interface User extends PermissionHolder {
* @return a {@link List} of group names
* @throws NullPointerException if the server or world is null
* @throws IllegalArgumentException if the server or world is invalid
+ * @deprecated in favour of just querying a users permissions
*/
+ @Deprecated
List getLocalGroups(String server, String world);
/**
@@ -317,7 +353,9 @@ public interface User extends PermissionHolder {
* @return a {@link List} of group names
* @throws NullPointerException if the server is null
* @throws IllegalArgumentException if the server is invalid
+ * @deprecated in favour of just querying a users permissions
*/
+ @Deprecated
List getLocalGroups(String server);
}
diff --git a/api/src/main/java/me/lucko/luckperms/api/UuidCache.java b/api/src/main/java/me/lucko/luckperms/api/UuidCache.java
index 6bea46b38..3c5ec6066 100644
--- a/api/src/main/java/me/lucko/luckperms/api/UuidCache.java
+++ b/api/src/main/java/me/lucko/luckperms/api/UuidCache.java
@@ -30,10 +30,10 @@ import java.util.UUID;
*
This UuidCache is a means of allowing users to have the same internal UUID across a network of offline mode
* servers or mixed offline mode and online mode servers. Platforms running in offline mode generate a UUID for a
* user when they first join the server, but this UUID will then not be consistent across the network. LuckPerms will
- * instead check the datastore cache, to get a UUID for a user that is consistent across an entire network.
+ * instead check the datastore cache, to get a UUID for a user that is consistent across an entire network.
*
*
If you want to get a user object from the Storage using the api on a server in offline mode, you will need to use
- * this cache, OR use Storage#getUUID, for users that are not online.
+ * this cache, OR use Storage#getUUID, for users that are not online.
*
*
This is only effective for online players. Use {@link Storage#getUUID(String)} for offline players.
*/
diff --git a/api/src/main/java/me/lucko/luckperms/api/caching/MetaContexts.java b/api/src/main/java/me/lucko/luckperms/api/caching/MetaContexts.java
new file mode 100644
index 000000000..071fc33ed
--- /dev/null
+++ b/api/src/main/java/me/lucko/luckperms/api/caching/MetaContexts.java
@@ -0,0 +1,110 @@
+/*
+ * This file is part of LuckPerms, licensed under the MIT License.
+ *
+ * Copyright (c) lucko (Luck)
+ * 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 me.lucko.luckperms.api.caching;
+
+import com.google.common.base.Preconditions;
+
+import me.lucko.luckperms.api.Contexts;
+import me.lucko.luckperms.api.metastacking.MetaStackDefinition;
+
+/**
+ * Represents the context for a meta lookup, consisting of a standard {@link Contexts} element, plus options to define how
+ * the meta stack should be constructed.
+ *
+ * @since 3.2
+ */
+public final class MetaContexts {
+
+ /**
+ * Creates a new meta contexts instance
+ *
+ * @param contexts the standard contexts for the query
+ * @param prefixStackDefinition the prefix stack definition to be used
+ * @param suffixStackDefinition the suffix stack definition to be used
+ * @return the new instance
+ */
+ public static MetaContexts of(Contexts contexts, MetaStackDefinition prefixStackDefinition, MetaStackDefinition suffixStackDefinition) {
+ return new MetaContexts(contexts, prefixStackDefinition, suffixStackDefinition);
+ }
+
+ private final Contexts contexts;
+ private final MetaStackDefinition prefixStackDefinition;
+ private final MetaStackDefinition suffixStackDefinition;
+
+ /**
+ * Creates a new meta contexts instance
+ *
+ * @param contexts the standard contexts for the query
+ * @param prefixStackDefinition the prefix stack definition to be used
+ * @param suffixStackDefinition the suffix stack definition to be used
+ */
+ public MetaContexts(Contexts contexts, MetaStackDefinition prefixStackDefinition, MetaStackDefinition suffixStackDefinition) {
+ this.contexts = Preconditions.checkNotNull(contexts, "contexts");
+ this.prefixStackDefinition = Preconditions.checkNotNull(prefixStackDefinition, "prefixStackDefinition");
+ this.suffixStackDefinition = Preconditions.checkNotNull(suffixStackDefinition, "suffixStackDefinition");
+ }
+
+ public Contexts getContexts() {
+ return this.contexts;
+ }
+
+ public MetaStackDefinition getPrefixStackDefinition() {
+ return this.prefixStackDefinition;
+ }
+
+ public MetaStackDefinition getSuffixStackDefinition() {
+ return this.suffixStackDefinition;
+ }
+
+ @Override
+ public String toString() {
+ return "MetaContexts(" +
+ "contexts=" + this.getContexts() + ", " +
+ "prefixStackDefinition=" + this.getPrefixStackDefinition() + ", " +
+ "suffixStackDefinition=" + this.getSuffixStackDefinition() +
+ ")";
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (!(o instanceof MetaContexts)) return false;
+ final MetaContexts other = (MetaContexts) o;
+ return this.getContexts().equals(other.getContexts()) &&
+ this.getPrefixStackDefinition().equals(other.getPrefixStackDefinition()) &&
+ this.getSuffixStackDefinition().equals(other.getSuffixStackDefinition());
+ }
+
+ @Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ result = result * PRIME + this.getContexts().hashCode();
+ result = result * PRIME + this.getPrefixStackDefinition().hashCode();
+ result = result * PRIME + this.getSuffixStackDefinition().hashCode();
+ return result;
+ }
+}
diff --git a/api/src/main/java/me/lucko/luckperms/api/caching/MetaData.java b/api/src/main/java/me/lucko/luckperms/api/caching/MetaData.java
index 87b1b3952..fca29f6bb 100644
--- a/api/src/main/java/me/lucko/luckperms/api/caching/MetaData.java
+++ b/api/src/main/java/me/lucko/luckperms/api/caching/MetaData.java
@@ -22,6 +22,8 @@
package me.lucko.luckperms.api.caching;
+import me.lucko.luckperms.api.metastacking.MetaStackDefinition;
+
import java.util.Map;
import java.util.SortedMap;
@@ -69,4 +71,20 @@ public interface MetaData {
*/
String getSuffix();
+ /**
+ * Gets the definition used for the prefix stack
+ *
+ * @return the definition used for the prefix stack
+ * @since 3.2
+ */
+ MetaStackDefinition getPrefixStackDefinition();
+
+ /**
+ * Gets the definition used for the suffix stack
+ *
+ * @return the definition used for the suffix stack
+ * @since 3.2
+ */
+ MetaStackDefinition getSuffixStackDefinition();
+
}
diff --git a/api/src/main/java/me/lucko/luckperms/api/caching/UserData.java b/api/src/main/java/me/lucko/luckperms/api/caching/UserData.java
index c61885134..2e6f42ccd 100644
--- a/api/src/main/java/me/lucko/luckperms/api/caching/UserData.java
+++ b/api/src/main/java/me/lucko/luckperms/api/caching/UserData.java
@@ -32,6 +32,10 @@ import java.util.Set;
*
Data is only likely to be available for online users. All calls will account for inheritance, as well as any
* default data provided by the platform. This calls are heavily cached and are therefore fast.
*
+ *
For meta, both methods accepting {@link Contexts} and {@link MetaContexts} are provided. The only difference is that
+ * the latter allows you to define how the meta stack should be structured internally. Where {@link Contexts} are passed, the
+ * values from the configuration are used.
+ *
* @since 2.13
*/
public interface UserData {
@@ -47,6 +51,18 @@ public interface UserData {
*/
PermissionData getPermissionData(Contexts contexts);
+ /**
+ * Gets MetaData from the cache, given a specified context.
+ *
+ *
If the data is not cached, it is calculated. Therefore, this call could be costly.
+ *
+ * @param contexts the contexts to get the permission data in
+ * @return a meta data instance
+ * @throws NullPointerException if contexts is null
+ * @since 3.2
+ */
+ MetaData getMetaData(MetaContexts contexts);
+
/**
* Gets MetaData from the cache, given a specified context.
*
@@ -67,6 +83,16 @@ public interface UserData {
*/
PermissionData calculatePermissions(Contexts contexts);
+ /**
+ * Calculates meta data, bypassing the cache.
+ *
+ * @param contexts the contexts to get meta data in
+ * @return a meta data instance
+ * @throws NullPointerException if contexts is null
+ * @since 3.2
+ */
+ MetaData calculateMeta(MetaContexts contexts);
+
/**
* Calculates meta data, bypassing the cache.
*
@@ -87,6 +113,18 @@ public interface UserData {
*/
void recalculatePermissions(Contexts contexts);
+ /**
+ * Calculates meta data and stores it in the cache.
+ *
+ *
If there is already data cached for the given contexts, and if the resultant output is different,
+ * the cached value is updated.
+ *
+ * @param contexts the contexts to recalculate in.
+ * @throws NullPointerException if contexts is null
+ * @since 3.2
+ */
+ void recalculateMeta(MetaContexts contexts);
+
/**
* Calculates meta data and stores it in the cache.
*
diff --git a/common/src/main/java/me/lucko/luckperms/common/metastacking/definition/MetaStackDefinition.java b/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackDefinition.java
similarity index 60%
rename from common/src/main/java/me/lucko/luckperms/common/metastacking/definition/MetaStackDefinition.java
rename to api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackDefinition.java
index 320b389e5..a60b8244d 100644
--- a/common/src/main/java/me/lucko/luckperms/common/metastacking/definition/MetaStackDefinition.java
+++ b/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackDefinition.java
@@ -23,30 +23,49 @@
* SOFTWARE.
*/
-package me.lucko.luckperms.common.metastacking.definition;
-
-import me.lucko.luckperms.common.metastacking.GenericMetaStack;
-import me.lucko.luckperms.common.metastacking.MetaStack;
-import me.lucko.luckperms.common.metastacking.MetaType;
+package me.lucko.luckperms.api.metastacking;
import java.util.List;
+/**
+ * Represents a meta stack model, consisting of a chain of elements, separated by spacers.
+ *
+ *
The resultant string is constructed as:
+ * [start spacer] [element] [middle spacer] [element] [middle spacer] [element] [end spacer]
+ *
+ *
Definitions can be passed to a users UserData instance using MetaContexts, and the result of this stack can be
+ * retrieved from the returned MetaData instance.
+ *
+ * @since 2.3
+ */
public interface MetaStackDefinition {
- static MetaStackDefinition create(List elements, String startSpacer, String middleSpacer, String endSpacer) {
- return new SimpleMetaStackDefinition(elements, startSpacer, middleSpacer, endSpacer);
- }
-
+ /**
+ * Gets an immutable list of the elements in this stack definition
+ *
+ * @return the elements in this stack
+ */
List getElements();
+ /**
+ * Gets the spacer string added before any stack elements
+ *
+ * @return the start spacer
+ */
String getStartSpacer();
+ /**
+ * Gets the spacer added between stack elements
+ *
+ * @return the middle spacer
+ */
String getMiddleSpacer();
+ /**
+ * Gets the spacer added after any stack elements
+ *
+ * @return the end spacer
+ */
String getEndSpacer();
- default MetaStack newStack(MetaType type) {
- return new GenericMetaStack(this, type);
- }
-
}
diff --git a/common/src/main/java/me/lucko/luckperms/common/metastacking/definition/MetaStackElement.java b/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackElement.java
similarity index 61%
rename from common/src/main/java/me/lucko/luckperms/common/metastacking/definition/MetaStackElement.java
rename to api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackElement.java
index a2fa7c3bf..a54e919ed 100644
--- a/common/src/main/java/me/lucko/luckperms/common/metastacking/definition/MetaStackElement.java
+++ b/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackElement.java
@@ -23,15 +23,31 @@
* SOFTWARE.
*/
-package me.lucko.luckperms.common.metastacking.definition;
+package me.lucko.luckperms.api.metastacking;
+import me.lucko.luckperms.api.ChatMetaType;
import me.lucko.luckperms.api.LocalizedNode;
-import me.lucko.luckperms.common.metastacking.MetaType;
+import me.lucko.luckperms.api.Node;
import java.util.Map;
+/**
+ * Represents an element within a {@link MetaStackDefinition}.
+ *
+ * @since 3.2
+ */
public interface MetaStackElement {
- boolean shouldAccumulate(LocalizedNode node, MetaType type, Map.Entry current);
+ /**
+ * Returns if the given node should be accumulated onto the stack.
+ *
+ *
The element being considered can be retrieved using {@link ChatMetaType#getEntry(Node)}.
+ *
+ * @param node the node being considered
+ * @param type the type of entry being accumulated
+ * @param current the current value being used. If this returns true, the current value will be replaced by this entry
+ * @return true if the node should be accumulated into this element, replacing the current value
+ */
+ boolean shouldAccumulate(LocalizedNode node, ChatMetaType type, Map.Entry current);
}
diff --git a/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackFactory.java b/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackFactory.java
new file mode 100644
index 000000000..253689722
--- /dev/null
+++ b/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackFactory.java
@@ -0,0 +1,67 @@
+/*
+ * This file is part of LuckPerms, licensed under the MIT License.
+ *
+ * Copyright (c) lucko (Luck)
+ * 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 me.lucko.luckperms.api.metastacking;
+
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Factory to create meta stack elements and definitions.
+ *
+ * @since 3.2
+ */
+public interface MetaStackFactory {
+
+ /**
+ * Parses a standard {@link MetaStackElement} from string, using the pre-defined elements in the plugin.
+ *
+ * @param definition the definition
+ * @return the parsed element, if present
+ */
+ Optional fromString(String definition);
+
+ /**
+ * Parses a list of {@link MetaStackElement}s from string, using the pre-defined elements in the plugin.
+ *
+ *
If an element cannot be parsed, it will not be included in the resultant list.
+ *
+ * @param definitions the definition strings
+ * @return a list of parsed elements
+ */
+ List fromStrings(List definitions);
+
+ /**
+ * Creates a new {@link MetaStackDefinition} with the given properties.
+ *
+ * @param elements the elements to be included in the stack.
+ * @param startSpacer the spacer to be included at the start of the stacks output
+ * @param middleSpacer the spacer to be included between stack elements
+ * @param endSpacer the spacer to be included at the end of the stacks output
+ * @return the new stack definition instance
+ */
+ MetaStackDefinition createDefinition(List elements, String startSpacer, String middleSpacer, String endSpacer);
+
+}
diff --git a/bukkit-legacy/pom.xml b/bukkit-legacy/pom.xml
index 638249e97..782385df2 100644
--- a/bukkit-legacy/pom.xml
+++ b/bukkit-legacy/pom.xml
@@ -5,7 +5,7 @@
luckpermsme.lucko.luckperms
- 3.1-SNAPSHOT
+ 3.2-SNAPSHOT4.0.0
diff --git a/bukkit/pom.xml b/bukkit/pom.xml
index 58f91beae..b97da1c9d 100644
--- a/bukkit/pom.xml
+++ b/bukkit/pom.xml
@@ -5,7 +5,7 @@
luckpermsme.lucko.luckperms
- 3.1-SNAPSHOT
+ 3.2-SNAPSHOT4.0.0
diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java
index 4a58f1370..6a75d30e0 100644
--- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java
+++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java
@@ -32,6 +32,7 @@ import de.bananaco.bpermissions.api.Permission;
import de.bananaco.bpermissions.api.World;
import de.bananaco.bpermissions.api.WorldManager;
+import me.lucko.luckperms.api.ChatMetaType;
import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult;
@@ -41,7 +42,6 @@ import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.core.NodeFactory;
import me.lucko.luckperms.common.core.model.PermissionHolder;
import me.lucko.luckperms.common.core.model.User;
-import me.lucko.luckperms.common.metastacking.MetaType;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.common.utils.ProgressLogger;
@@ -225,7 +225,7 @@ public class MigrationBPermissions extends SubCommand