From aea44fc8bc62f5912aed02f04d35853da914a9be Mon Sep 17 00:00:00 2001 From: Luck Date: Mon, 16 Jan 2017 20:01:41 +0000 Subject: [PATCH] API changes for 2.17 - closes #123 --- api/pom.xml | 2 +- .../java/me/lucko/luckperms/LuckPerms.java | 13 +- .../java/me/lucko/luckperms/api/Contexts.java | 11 +- .../me/lucko/luckperms/api/Datastore.java | 2 +- .../java/me/lucko/luckperms/api/Group.java | 33 ++-- .../lucko/luckperms/api}/HeldPermission.java | 57 +++++- .../lucko/luckperms/api/LPConfiguration.java | 29 +++- .../me/lucko/luckperms/api/LocalizedNode.java | 4 +- .../main/java/me/lucko/luckperms/api/Log.java | 20 ++- .../java/me/lucko/luckperms/api/LogEntry.java | 68 ++++---- .../java/me/lucko/luckperms/api/Logger.java | 2 +- .../me/lucko/luckperms/api/LuckPermsApi.java | 23 ++- .../lucko/luckperms/api/MessagingService.java | 6 +- .../java/me/lucko/luckperms/api/Node.java | 4 +- .../me/lucko/luckperms/api/NodeFactory.java | 101 +++++++++++ .../lucko/luckperms/api/PermissionHolder.java | 164 ++++++++++++++---- .../me/lucko/luckperms/api/PlatformType.java | 2 +- .../java/me/lucko/luckperms/api/Storage.java | 33 +++- .../java/me/lucko/luckperms/api/Track.java | 9 +- .../java/me/lucko/luckperms/api/Tristate.java | 28 ++- .../java/me/lucko/luckperms/api/User.java | 24 ++- .../me/lucko/luckperms/api/UuidCache.java | 5 +- .../luckperms/api/caching/PermissionData.java | 3 +- .../lucko/luckperms/api/caching/UserData.java | 23 ++- bukkit-legacy/pom.xml | 2 +- bukkit-placeholders/pom.xml | 2 +- bukkit/pom.xml | 2 +- bungee/pom.xml | 2 +- common/pom.xml | 2 +- .../luckperms/common/api/ApiProvider.java | 63 ++++--- .../{internal/Utils.java => ApiUtils.java} | 13 +- .../DatastoreDelegate.java} | 59 +++---- .../GroupDelegate.java} | 49 +++--- .../LPConfigurationDelegate.java} | 4 +- .../LogDelegate.java} | 6 +- .../api/delegate/NodeFactoryDelegate.java | 67 +++++++ .../PermissionHolderDelegate.java} | 91 ++++++++-- .../StorageDelegate.java} | 43 +++-- .../TrackDelegate.java} | 20 +-- .../UserDelegate.java} | 47 ++--- .../UuidCacheDelegate.java} | 4 +- .../common/commands/misc/SearchCommand.java | 2 +- .../common/commands/user/UserDemote.java | 8 +- .../common/commands/user/UserPromote.java | 8 +- .../luckperms/common/commands/utils/Util.java | 2 +- .../common/core/model/PermissionHolder.java | 32 ++-- .../luckperms/common/core/model/User.java | 4 +- .../common/storage/AbstractStorage.java | 2 +- .../common/storage/SplitBacking.java | 2 +- .../luckperms/common/storage/Storage.java | 2 +- .../storage/backing/AbstractBacking.java | 2 +- .../common/storage/backing/JSONBacking.java | 2 +- .../storage/backing/MongoDBBacking.java | 2 +- .../common/storage/backing/SQLBacking.java | 2 +- .../common/storage/backing/YAMLBacking.java | 2 +- .../storage/holder/NodeHeldPermission.java | 1 + .../storage/wrappings/TolerantStorage.java | 2 +- pom.xml | 4 +- sponge/pom.xml | 2 +- 59 files changed, 898 insertions(+), 325 deletions(-) rename {common/src/main/java/me/lucko/luckperms/common/storage/holder => api/src/main/java/me/lucko/luckperms/api}/HeldPermission.java (61%) create mode 100644 api/src/main/java/me/lucko/luckperms/api/NodeFactory.java rename common/src/main/java/me/lucko/luckperms/common/api/{internal/Utils.java => ApiUtils.java} (82%) rename common/src/main/java/me/lucko/luckperms/common/api/{internal/DatastoreLink.java => delegate/DatastoreDelegate.java} (85%) rename common/src/main/java/me/lucko/luckperms/common/api/{internal/GroupLink.java => delegate/GroupDelegate.java} (71%) rename common/src/main/java/me/lucko/luckperms/common/api/{internal/LPConfigurationLink.java => delegate/LPConfigurationDelegate.java} (97%) rename common/src/main/java/me/lucko/luckperms/common/api/{internal/LogLink.java => delegate/LogDelegate.java} (96%) create mode 100644 common/src/main/java/me/lucko/luckperms/common/api/delegate/NodeFactoryDelegate.java rename common/src/main/java/me/lucko/luckperms/common/api/{internal/PermissionHolderLink.java => delegate/PermissionHolderDelegate.java} (83%) rename common/src/main/java/me/lucko/luckperms/common/api/{internal/StorageLink.java => delegate/StorageDelegate.java} (77%) rename common/src/main/java/me/lucko/luckperms/common/api/{internal/TrackLink.java => delegate/TrackDelegate.java} (82%) rename common/src/main/java/me/lucko/luckperms/common/api/{internal/UserLink.java => delegate/UserDelegate.java} (75%) rename common/src/main/java/me/lucko/luckperms/common/api/{internal/UuidCacheLink.java => delegate/UuidCacheDelegate.java} (94%) diff --git a/api/pom.xml b/api/pom.xml index 12f6c336a..9d076b2dc 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 2.16-SNAPSHOT + 2.17-SNAPSHOT 4.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 75080202c..2a835116e 100644 --- a/api/src/main/java/me/lucko/luckperms/LuckPerms.java +++ b/api/src/main/java/me/lucko/luckperms/LuckPerms.java @@ -27,13 +27,16 @@ import me.lucko.luckperms.api.LuckPermsApi; import java.util.Optional; /** - * Static access to LuckPerms + * Singleton for the {@link LuckPermsApi}. + * + *

Ideally, the ServiceManager for the platform should be used to obtain and cache an instance, however, this can be + * used if you need static access. */ public final class LuckPerms { private static LuckPermsApi api = null; /** - * Gets an instance of {@link LuckPermsApi} + * Gets an instance of {@link LuckPermsApi}, throwing {@link IllegalStateException} if the API is not loaded. * * @return an api instance * @throws IllegalStateException if the api is not loaded @@ -46,8 +49,10 @@ public final class LuckPerms { } /** - * Gets an instance of {@link LuckPermsApi} safely. Unlike {@link LuckPerms#getApi}, this method will not throw an - * {@link IllegalStateException} if the api is not loaded, rather return an empty {@link Optional}. + * Gets an instance of {@link LuckPermsApi} safely. + * + *

Unlike {@link LuckPerms#getApi}, this method will not throw an {@link IllegalStateException} if the API is + * not loaded, rather return an empty {@link Optional}. * * @return an optional api instance */ 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 5638ec840..5fffa0a03 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Contexts.java +++ b/api/src/main/java/me/lucko/luckperms/api/Contexts.java @@ -27,8 +27,9 @@ import me.lucko.luckperms.api.context.ContextSet; import java.util.Map; /** - * Represents the context and options for a permission lookup. - * All values are immutable. + * Context and options for a permission lookup. + * + *

All values are immutable. * * @since 2.11 */ @@ -67,28 +68,34 @@ public class Contexts { * The keys for servers and worlds are defined as static values. */ private final ContextSet context; + /** * The mode to parse defaults on Bukkit * * @since 2.12 */ private final boolean op; + /** * If global or non server specific nodes should be applied */ private final boolean includeGlobal; + /** * If global or non world specific nodes should be applied */ private final boolean includeGlobalWorld; + /** * If parent groups should be applied */ private final boolean applyGroups; + /** * If global or non server specific group memberships should be applied */ private final boolean applyGlobalGroups; + /** * If global or non world specific group memberships should be applied */ diff --git a/api/src/main/java/me/lucko/luckperms/api/Datastore.java b/api/src/main/java/me/lucko/luckperms/api/Datastore.java index 2d10880c6..621dfd052 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Datastore.java +++ b/api/src/main/java/me/lucko/luckperms/api/Datastore.java @@ -28,7 +28,7 @@ import java.util.Set; import java.util.UUID; /** - * Interface for the internal Datastore instance + * Deprecated Storage interface. Use {@link Storage} instead. * * @deprecated as of version 2.14 in favour of {@link Storage}. */ 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 f1d27a70f..bad6ed0da 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Group.java +++ b/api/src/main/java/me/lucko/luckperms/api/Group.java @@ -26,14 +26,16 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; import java.util.List; +import java.util.OptionalInt; /** - * Interface for internal Group instances + * A group which holds permission data. */ -@SuppressWarnings("unused") public interface Group extends PermissionHolder { /** + * Get the name of the group + * * @return the name of the group */ String getName(); @@ -220,11 +222,6 @@ public interface Group extends PermissionHolder { */ void unsetInheritGroup(Group group, String server, String world, boolean temporary) throws ObjectLacksException; - /** - * Clear all of the groups permission nodes - */ - void clearNodes(); - /** * Get a {@link List} of all of the groups the group inherits, on all servers * @@ -236,6 +233,17 @@ public interface Group extends PermissionHolder { * Get a {@link List} of the groups the group inherits on a specific server * * @param server the server to check + * @return a {@link List} of group names + * @throws NullPointerException if the server is null + * @throws IllegalArgumentException if the server is invalid + */ + List getLocalGroups(String server); + + + /** + * Get a {@link List} of the groups the group inherits on a specific server and world + * + * @param server the server to check * @param world the world to check * @return a {@link List} of group names * @throws NullPointerException if the server or world is null @@ -244,12 +252,11 @@ public interface Group extends PermissionHolder { List getLocalGroups(String server, String world); /** - * Get a {@link List} of the groups the group inherits on a specific server + * Gets the weight of this group, is present. * - * @param server the server to check - * @return a {@link List} of group names - * @throws NullPointerException if the server is null - * @throws IllegalArgumentException if the server is invalid + * @return the group weight + * @since 2.17 */ - List getLocalGroups(String server); + OptionalInt getWeight(); + } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/holder/HeldPermission.java b/api/src/main/java/me/lucko/luckperms/api/HeldPermission.java similarity index 61% rename from common/src/main/java/me/lucko/luckperms/common/storage/holder/HeldPermission.java rename to api/src/main/java/me/lucko/luckperms/api/HeldPermission.java index afc0108cf..c6322edd1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/holder/HeldPermission.java +++ b/api/src/main/java/me/lucko/luckperms/api/HeldPermission.java @@ -20,24 +20,75 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.storage.holder; +package me.lucko.luckperms.api; import com.google.common.collect.Multimap; -import me.lucko.luckperms.api.Node; - import java.util.Optional; import java.util.OptionalLong; +/** + * A relationship between a Holder and a permission + * + * @param the identifier type of the holder + * @since 2.17 + */ public interface HeldPermission { + /** + * Gets the holder of the permission + * + * @return the holder + */ T getHolder(); + + /** + * Gets the permission being held + * + * @return the permission + */ String getPermission(); + + /** + * Gets the value of the permission + * + * @return the value + */ boolean getValue(); + + /** + * Gets the server where the permission is held + * + * @return the server + */ Optional getServer(); + + /** + * Gets the world where the permission is held + * + * @return the world + */ Optional getWorld(); + + /** + * Gets the time in unix time when the permission will expire + * + * @return the expiry time + */ OptionalLong getExpiry(); + + /** + * Gets the context for the permission. + * + * @return the context + */ Multimap getContext(); + + /** + * Converts this permission into a Node + * + * @return a Node copy of this permission + */ Node asNode(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/LPConfiguration.java b/api/src/main/java/me/lucko/luckperms/api/LPConfiguration.java index 84f5d5f80..9bd4a4718 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LPConfiguration.java +++ b/api/src/main/java/me/lucko/luckperms/api/LPConfiguration.java @@ -28,22 +28,24 @@ import me.lucko.luckperms.api.data.MySQLConfiguration; import java.util.Map; /** - * A wrapper interface for the internal LuckPerms configuration, providing read only access. + * Read-only access to the LuckPerms configuration settings */ -@SuppressWarnings("unused") public interface LPConfiguration { /** + * Returns the name of this server * @return the name of this server */ String getServer(); /** + * Returns how often a sync task will run in minutes * @return how often a sync task will run in minutes */ int getSyncTime(); /** + * Returns the default group, in a node representation * @return the default group, in a node representation * @deprecated as of 2.6, the default group is always "default" */ @@ -51,6 +53,7 @@ public interface LPConfiguration { String getDefaultGroupNode(); /** + * Returns the name of the default group * @return the name of the default group * @deprecated as of 2.6, the default group is always "default" */ @@ -58,55 +61,65 @@ public interface LPConfiguration { String getDefaultGroupName(); /** + * Returns if the users on this server will have their global permissions applied * @return if the users on this server will have their global permissions applied */ boolean getIncludeGlobalPerms(); /** + * Returns if the users on this server will have their global world permissions applied * @return if the users on this server will have their global world permissions applied * @since 2.9 */ boolean getIncludeGlobalWorldPerms(); /** + * Returns true if the platform is applying global groups * @return true if the platform is applying global groups * @since 2.9 */ boolean getApplyGlobalGroups(); /** + * Returns true if the platform is applying global world groups * @return true if the platform is applying global world groups * @since 2.9 */ boolean getApplyGlobalWorldGroups(); /** - * @return the online mode setting in the config + * Returns the online mode setting + * @return the online mode setting */ boolean getOnlineMode(); /** + * Returns if LuckPerms is applying wildcard permissions * @return if LuckPerms is applying wildcard permissions */ boolean getApplyWildcards(); /** + * Returns if LuckPerms is resolving and applying regex permissions * @return if LuckPerms is resolving and applying regex permissions */ boolean getApplyRegex(); /** + * Returns if LuckPerms is expanding shorthand permissions * @return if LuckPerms is expanding shorthand permissions */ boolean getApplyShorthand(); /** + * Returns if LuckPerms will send notifications to users when permissions are modified * @return if LuckPerms will send notifications to users when permissions are modified * @since 2.7 */ boolean getLogNotify(); /** + * Returns true if permission checks are being recorded / debugged * @return true if permission checks are being recorded / debugged * @since 2.9 * @deprecated as this value is now always false. Functionality was replaced by the verbose command. @@ -115,36 +128,42 @@ public interface LPConfiguration { boolean getDebugPermissionChecks(); /** + * Returns true if the vanilla op system is enabled * @return true if the vanilla op system is enabled * @since 2.8 */ boolean getEnableOps(); /** + * Returns true if opped players are allowed to use LuckPerms commands * @return true if opped players are allowed to use LuckPerms commands * @since 2.8 */ boolean getCommandsAllowOp(); /** + * Returns true if auto op is enabled * @return true if auto op is enabled * @since 2.9 */ boolean getAutoOp(); /** + * Returns the name of the server used within Vault operations * @return the name of the server used within Vault operations * @since 2.7 */ String getVaultServer(); /** + * Returns true if global permissions should be considered when retrieving meta or player groups * @return true if global permissions should be considered when retrieving meta or player groups * @since 2.7 */ boolean getVaultIncludeGlobal(); /** + * Returns the database values set in the configuration * @return the database values set in the configuration * @deprecated use {@link #getDatastoreConfig()} */ @@ -153,22 +172,26 @@ public interface LPConfiguration { MySQLConfiguration getDatabaseValues(); /** + * Returns the values set for data storage in the configuration * @return the values set for data storage in the configuration */ DatastoreConfiguration getDatastoreConfig(); /** + * Returns the storage method string from the configuration * @return the storage method string from the configuration */ String getStorageMethod(); /** + * Returns true if split storage is enabled * @return true if split storage is enabled * @since 2.7 */ boolean getSplitStorage(); /** + * Returns a map of split storage options * @return a map of split storage options, where the key is the storage section, and the value is the storage * method. For example: key = user, value = json * @since 2.7 diff --git a/api/src/main/java/me/lucko/luckperms/api/LocalizedNode.java b/api/src/main/java/me/lucko/luckperms/api/LocalizedNode.java index ada9fbdfa..a27cf00e9 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LocalizedNode.java +++ b/api/src/main/java/me/lucko/luckperms/api/LocalizedNode.java @@ -23,14 +23,14 @@ package me.lucko.luckperms.api; /** - * Represents a Node and where it was inherited from. + * A node with a traceable origin * * @since 2.11 */ public interface LocalizedNode extends Node { /** - * Gets the node + * Gets the delegate node * * @return the node this instance is representing */ diff --git a/api/src/main/java/me/lucko/luckperms/api/Log.java b/api/src/main/java/me/lucko/luckperms/api/Log.java index fd8086cf3..b66964d0a 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Log.java +++ b/api/src/main/java/me/lucko/luckperms/api/Log.java @@ -27,10 +27,11 @@ import java.util.SortedSet; import java.util.UUID; /** - * Represents the internal LuckPerms log. All content internally is immutable. You can add to the log using the {@link - * Datastore}, and then request an updated copy. + * Represents the internal LuckPerms log. + * + *

The returned instance provides a copy of the data at the time of retrieval. Any changes made to log entries will + * only apply to this instance of the log. You can add to the log using the {@link Storage}, and then request an updated copy. */ -@SuppressWarnings("unused") public interface Log { /** @@ -48,6 +49,8 @@ public interface Log { * * @param pageNo the page number * @return the page content + * @throws IllegalArgumentException if the pageNo is less than 1 + * @throws IllegalStateException if the log doesn't contain enough entries to populate the page. See {@link #getRecentMaxPages()}} */ SortedMap getRecent(int pageNo); @@ -69,6 +72,8 @@ public interface Log { * @param pageNo the page number * @param actor the uuid of the actor to filter by * @return the page content + * @throws IllegalArgumentException if the pageNo is less than 1 + * @throws IllegalStateException if the log doesn't contain enough entries to populate the page. See {@link #getRecentMaxPages(UUID)}} */ SortedMap getRecent(int pageNo, UUID actor); @@ -91,6 +96,8 @@ public interface Log { * @param pageNo the page number * @param uuid the uuid of the acted user to filter by * @return the page content + * @throws IllegalArgumentException if the pageNo is less than 1 + * @throws IllegalStateException if the log doesn't contain enough entries to populate the page. See {@link #getUserHistoryMaxPages(UUID)}} */ SortedMap getUserHistory(int pageNo, UUID uuid); @@ -113,6 +120,8 @@ public interface Log { * @param pageNo the page number * @param name the name of the acted group to filter by * @return the page content + * @throws IllegalArgumentException if the pageNo is less than 1 + * @throws IllegalStateException if the log doesn't contain enough entries to populate the page. See {@link #getGroupHistoryMaxPages(String)}} */ SortedMap getGroupHistory(int pageNo, String name); @@ -141,9 +150,12 @@ public interface Log { /** * @param name the name to filter by * @return the max page number allowed in the {@link #getTrackHistory(int, String)} method + * @throws IllegalArgumentException if the pageNo is less than 1 + * @throws IllegalStateException if the log doesn't contain enough entries to populate the page. See {@link #getTrackHistoryMaxPages(String)}} */ int getTrackHistoryMaxPages(String name); + /** * @param query the query to filter by * @return all content in this log where the content matches query @@ -156,6 +168,8 @@ public interface Log { * @param pageNo the page number * @param query the query to filter by * @return the page content + * @throws IllegalArgumentException if the pageNo is less than 1 + * @throws IllegalStateException if the log doesn't contain enough entries to populate the page. See {@link #getSearchMaxPages(String)}} */ SortedMap getSearch(int pageNo, String query); diff --git a/api/src/main/java/me/lucko/luckperms/api/LogEntry.java b/api/src/main/java/me/lucko/luckperms/api/LogEntry.java index 2e35e1aaf..97145d537 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LogEntry.java +++ b/api/src/main/java/me/lucko/luckperms/api/LogEntry.java @@ -25,9 +25,10 @@ package me.lucko.luckperms.api; import java.util.UUID; /** - * Represents a single entry in a log + * A single entry in the log + * + *

Implements {@link Comparable} ordering based upon the timestamp of the entry. */ -@SuppressWarnings({"unused", "WeakerAccess"}) public class LogEntry implements Comparable { private static final String FORMAT = "&8(&e%s&8) [&a%s&8] (&b%s&8) &7--> &f%s"; @@ -154,9 +155,15 @@ public class LogEntry implements Comparable { @Override public String toString() { - return "LogEntry(timestamp=" + this.getTimestamp() + ", actor=" + this.getActor() + ", actorName=" + - this.getActorName() + ", type=" + this.getType() + ", acted=" + this.getActed() + ", actedName=" + - this.getActedName() + ", action=" + this.getAction() + ")"; + return "LogEntry(" + + "timestamp=" + this.getTimestamp() + ", " + + "actor=" + this.getActor() + ", " + + "actorName=" + this.getActorName() + ", " + + "type=" + this.getType() + ", " + + "acted=" + this.getActed() + ", " + + "actedName=" + this.getActedName() + ", " + + "action=" + this.getAction() + + ")"; } @Override @@ -165,41 +172,25 @@ public class LogEntry implements Comparable { if (!(o instanceof LogEntry)) return false; final LogEntry other = (LogEntry) o; if (this.getTimestamp() != other.getTimestamp()) return false; - final Object this$actor = this.getActor(); - final Object other$actor = other.getActor(); - if (this$actor == null ? other$actor != null : !this$actor.equals(other$actor)) return false; - final Object this$actorName = this.getActorName(); - final Object other$actorName = other.getActorName(); - if (this$actorName == null ? other$actorName != null : !this$actorName.equals(other$actorName)) return false; + if (this.getActor() == null ? other.getActor() != null : !this.getActor().equals(other.getActor())) return false; + if (this.getActorName() == null ? other.getActorName() != null : !this.getActorName().equals(other.getActorName())) return false; if (this.getType() != other.getType()) return false; - final Object this$acted = this.getActed(); - final Object other$acted = other.getActed(); - if (this$acted == null ? other$acted != null : !this$acted.equals(other$acted)) return false; - final Object this$actedName = this.getActedName(); - final Object other$actedName = other.getActedName(); - if (this$actedName == null ? other$actedName != null : !this$actedName.equals(other$actedName)) return false; - final Object this$action = this.getAction(); - final Object other$action = other.getAction(); - return this$action == null ? other$action == null : this$action.equals(other$action); + if (this.getActed() == null ? other.getActed() != null : !this.getActed().equals(other.getActed())) return false; + if (this.getActedName() == null ? other.getActedName() != null : !this.getActedName().equals(other.getActedName())) return false; + return this.getAction() == null ? other.getAction() == null : this.getAction().equals(other.getAction()); } @Override public int hashCode() { final int PRIME = 59; int result = 1; - final long $timestamp = this.getTimestamp(); - result = result * PRIME + (int) ($timestamp >>> 32 ^ $timestamp); - final Object $actor = this.getActor(); - result = result * PRIME + ($actor == null ? 43 : $actor.hashCode()); - final Object $actorName = this.getActorName(); - result = result * PRIME + ($actorName == null ? 43 : $actorName.hashCode()); + result = result * PRIME + (int) (this.getTimestamp() >>> 32 ^ this.getTimestamp()); + result = result * PRIME + (this.getActor() == null ? 43 : this.getActor().hashCode()); + result = result * PRIME + (this.getActorName() == null ? 43 : this.getActorName().hashCode()); result = result * PRIME + this.getType(); - final Object $acted = this.getActed(); - result = result * PRIME + ($acted == null ? 43 : $acted.hashCode()); - final Object $actedName = this.getActedName(); - result = result * PRIME + ($actedName == null ? 43 : $actedName.hashCode()); - final Object $action = this.getAction(); - result = result * PRIME + ($action == null ? 43 : $action.hashCode()); + result = result * PRIME + (this.getActed() == null ? 43 : this.getActed().hashCode()); + result = result * PRIME + (this.getActedName() == null ? 43 : this.getActedName().hashCode()); + result = result * PRIME + (this.getAction() == null ? 43 : this.getAction().hashCode()); return result; } @@ -214,6 +205,7 @@ public class LogEntry implements Comparable { protected LogEntryBuilder getThis() { return this; } + } public static abstract class AbstractLogEntryBuilder> { @@ -311,9 +303,15 @@ public class LogEntry implements Comparable { @Override public String toString() { - return "LogEntry.LogEntryBuilder(timestamp=" + getTimestamp() + ", actor=" + getActor() + ", actorName=" + - getActorName() + ", type=" + getType() + ", acted=" + getActed() + ", actedName=" + getActedName() + - ", action=" + getAction() + ")"; + return "LogEntry.LogEntryBuilder(" + + "timestamp=" + this.getTimestamp() + ", " + + "actor=" + this.getActor() + ", " + + "actorName=" + this.getActorName() + ", " + + "type=" + this.getType() + ", " + + "acted=" + this.getActed() + ", " + + "actedName=" + this.getActedName() + ", " + + "action=" + this.getAction() + + ")"; } } 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 16289269d..a4d7bd9c6 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Logger.java +++ b/api/src/main/java/me/lucko/luckperms/api/Logger.java @@ -23,7 +23,7 @@ package me.lucko.luckperms.api; /** - * A wrapper interface for platform logger instances. + * A wrapper interface for platform logger instances * *

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. 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 75b435d03..8aa14ed02 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java +++ b/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.api; import me.lucko.luckperms.api.context.ContextListener; +import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.context.IContextCalculator; import me.lucko.luckperms.api.event.LPListener; @@ -31,9 +32,8 @@ import java.util.Set; import java.util.UUID; /** - * The root API interface in LuckPerms + * The root API interface for LuckPerms */ -@SuppressWarnings("unused") public interface LuckPermsApi { /** @@ -250,6 +250,13 @@ public interface LuckPermsApi { */ boolean isTrackLoaded(String name); + /** + * Gets the node factory instance for the platform + * + * @return the node factory + */ + NodeFactory getNodeFactory(); + /** * Returns a permission builder instance * @@ -279,11 +286,21 @@ public interface LuckPermsApi { /** * Gets a calculated context instance for the user using the rules of the platform. - * These values are calculated using the options in the configuration, and the provided calculators. + * + *

These values are calculated using the options in the configuration, and the provided calculators. * * @param user the user to get contexts for * @return an optional containing contexts. Will return empty if the user is not online. */ Optional getContextForUser(User user); + /** + * Gets set of contexts applicable to a player using the platforms {@link IContextCalculator}s. + * + * @param player the player to calculate for. Must be the player instance for the platform. + * @return a set of contexts. + * @since 2.17 + */ + ContextSet getContextForPlayer(Object player); + } diff --git a/api/src/main/java/me/lucko/luckperms/api/MessagingService.java b/api/src/main/java/me/lucko/luckperms/api/MessagingService.java index 7cf51aacb..99e5c4e67 100644 --- a/api/src/main/java/me/lucko/luckperms/api/MessagingService.java +++ b/api/src/main/java/me/lucko/luckperms/api/MessagingService.java @@ -23,7 +23,7 @@ package me.lucko.luckperms.api; /** - * Exposes any networking provider being used on the platform. e.g. Redis + * A means to push changes to other servers using the platforms networking * * @since 2.14 */ @@ -31,7 +31,9 @@ public interface MessagingService { /** * Uses the messaging service to inform other servers about changes. - * This will push the update asynchronously, and this method will return almost immediately. + * + *

This will push the update asynchronously, and this method will return immediately. Calling this method is + * equivalent to running "/lp networksync", except will not sync this server. */ void pushUpdate(); 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 3023dea07..4e202e595 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Node.java +++ b/api/src/main/java/me/lucko/luckperms/api/Node.java @@ -31,12 +31,12 @@ import java.util.Optional; import java.util.Set; /** - * Represents an immutable node object + * An immutable permission node + * *

Use {@link LuckPermsApi#buildNode(String)} to get an instance. * * @since 2.6 */ -@SuppressWarnings("unused") public interface Node extends Map.Entry { /** diff --git a/api/src/main/java/me/lucko/luckperms/api/NodeFactory.java b/api/src/main/java/me/lucko/luckperms/api/NodeFactory.java new file mode 100644 index 000000000..11bf81fd6 --- /dev/null +++ b/api/src/main/java/me/lucko/luckperms/api/NodeFactory.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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; + +/** + * Builds {@link Node} instances + * + * @since 2.17 + */ +public interface NodeFactory { + + /** + * Creates a node from a serialised node string + * + * @param serialisedPermission the serialised permission string + * @param value the value of the node + * @return a node instance + * @throws NullPointerException if the permission is null + */ + Node fromSerialisedNode(String serialisedPermission, boolean value); + + + /** + * Creates a new node builder from a given base permission string + * + * @param permission the permission + * @return a node builder instance + * @throws NullPointerException if the permission is null + */ + Node.Builder newBuilder(String permission); + + /** + * Creates a node builder instance from an existing node + * + * @param other the other node + * @return a node builder instance + * @throws NullPointerException if the other node is null + */ + Node.Builder newBuilderFromExisting(Node other); + + /** + * Creates a node builder from a serialised node string + * @param serialisedPermission the serialised permission string + * @param value the value of the node + * @return a node builder instance + * @throws NullPointerException if the permission is null + */ + Node.Builder newBuilderFromSerialisedNode(String serialisedPermission, boolean value); + + + /** + * Creates a node builder from a key value pair + * + * @param key the key + * @param value the value + * @return a node builder instance + * @throws NullPointerException if the key or value is null + */ + Node.Builder makeMetaNode(String key, String value); + + /** + * Creates a node builder from a prefix string and priority + * + * @param priority the priority + * @param prefix the prefix string + * @return a node builder instance + * @throws NullPointerException if the prefix is null + */ + Node.Builder makePrefixNode(int priority, String prefix); + + /** + * Creates a node builder from a prefix string and priority + * + * @param priority the priority + * @param suffix the suffix string + * @return a node builder instance + * @throws NullPointerException if the suffix is null + */ + Node.Builder makeSuffixNode(int priority, String suffix); + +} 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 0f38d19d2..ef907d78f 100644 --- a/api/src/main/java/me/lucko/luckperms/api/PermissionHolder.java +++ b/api/src/main/java/me/lucko/luckperms/api/PermissionHolder.java @@ -31,19 +31,24 @@ import java.util.Set; import java.util.SortedSet; /** - * Interface for internal PermissionHolder (user/group) instances + * An object capable of holding permissions + * + *

Any changes made will be lost unless the instance is saved back to the {@link Storage}. */ -@SuppressWarnings("unused") public interface PermissionHolder { /** - * @return the identifier for this object. either a uuid string or name However, you should really just use {@link - * User#getUuid()}, {@link User#getName()} or {@link Group#getName()} + * Gets the objects name + * + *

{@link User#getUuid()}, {@link User#getName()} or {@link Group#getName()} should normally be used instead of + * this method. + * + * @return the identifier for this object. Either a uuid string or name. */ String getObjectName(); /** - * Gets an immutable Set of the objects permission nodes + * Gets a sorted set of all held permissions. * * @return an immutable set of permissions in priority order * @since 2.6 @@ -51,20 +56,22 @@ public interface PermissionHolder { SortedSet getPermissions(); /** - * Similar to {@link #getPermissions()}, except excluding transient permissions + * Similar to {@link #getPermissions()}, except without transient permissions * * @return a set of nodes * @since 2.6 */ - Set getEnduringPermissions(); + Set getEnduringPermissions(); /** - * Similar to {@link #getPermissions()}, except excluding non-transient permissions + * Gets an immutable set of all transiently held permissions. + * + *

Transient permissions only exist for the duration of the session. * * @return a set of nodes * @since 2.6 */ - Set getTransientPermissions(); + Set getTransientPermissions(); /** @@ -91,7 +98,7 @@ public interface PermissionHolder { SortedSet getAllNodes(Contexts contexts); /** - * Gets a mutable set of the nodes that is objects has and inherits, filtered by context. + * Gets a mutable set of the nodes that this object has and inherits, filtered by context. * Unlike {@link #getAllNodes(Contexts)}, this method WILL filter individual nodes, and only return ones that fully * meet the context provided. * @@ -102,6 +109,14 @@ public interface PermissionHolder { */ Set getAllNodesFiltered(Contexts contexts); + /** + * Converts the output of {@link #getAllNodesFiltered(Contexts)}, and expands shorthand permissions. + * @param contexts the context for the lookup + * @param lowerCase if the keys should be made lowercase whilst being exported + * @return a mutable map of permissions + */ + Map exportNodes(Contexts contexts, boolean lowerCase); + /** * Gets an immutable Map of the objects permission nodes * @@ -111,6 +126,11 @@ public interface PermissionHolder { @Deprecated Map getNodes(); + /** + * Removes temporary permissions that have expired + */ + void auditTemporaryPermissions(); + /** * Checks to see if the object has a certain permission * @@ -508,6 +528,109 @@ 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 + */ + void clearNodes(String server); + + /** + * Clears all nodes held by the object on a specific server and world + * + * @param server the server to filter by, can be null + * @param world the world to filter by, can be null + * @since 2.17 + */ + 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 + */ + void clearParents(String server); + + /** + * Clears all parents on a specific server and world + * + * @param server the server to filter by, can be null + * @param world the world to filter by, can be null + * @since 2.17 + */ + 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 + */ + void clearMeta(String server); + + /** + * Clears all meta held by the object on a specific server and world + * + * @param server the server to filter by, can be null + * @param world the world to filter by, can be null + * @since 2.17 + */ + void clearMeta(String server, String world); + + /** + * Clears all meta for a given key. + * + * @param key the meta key + * @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. + */ + 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(); + /** * Gets the permissions and inherited permissions that apply to a specific server and world * @@ -581,14 +704,6 @@ public interface PermissionHolder { @Deprecated Map, Long> getTemporaryNodes(); - /** - * Processes the nodes and returns the temporary ones. - * - * @return a set of temporary nodes - * @since 2.6 - */ - Set getTemporaryPermissionNodes(); - /** * Processes the nodes and returns the non-temporary ones. * @@ -598,17 +713,4 @@ public interface PermissionHolder { @Deprecated Map getPermanentNodes(); - /** - * Processes the nodes and returns the non-temporary ones. - * - * @return a set of permanent nodes - * @since 2.6 - */ - Set getPermanentPermissionNodes(); - - /** - * Removes temporary permissions that have expired - */ - void auditTemporaryPermissions(); - } diff --git a/api/src/main/java/me/lucko/luckperms/api/PlatformType.java b/api/src/main/java/me/lucko/luckperms/api/PlatformType.java index 18ace418c..e99644076 100644 --- a/api/src/main/java/me/lucko/luckperms/api/PlatformType.java +++ b/api/src/main/java/me/lucko/luckperms/api/PlatformType.java @@ -23,7 +23,7 @@ package me.lucko.luckperms.api; /** - * Represents the platform type that LuckPerms is running on + * The platforms which LuckPerms can run on * * @since 2.7 */ diff --git a/api/src/main/java/me/lucko/luckperms/api/Storage.java b/api/src/main/java/me/lucko/luckperms/api/Storage.java index fd2e66e9d..e7341ae87 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Storage.java +++ b/api/src/main/java/me/lucko/luckperms/api/Storage.java @@ -22,6 +22,7 @@ package me.lucko.luckperms.api; +import java.util.List; import java.util.Set; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -29,7 +30,7 @@ import java.util.concurrent.Executor; import java.util.function.Consumer; /** - * Interface for the internal Storage instance + * A means of loading and saving data to/from the Storage provider. * *

All methods return {@link CompletableFuture}s, which will be populated with the result once the data has been * loaded asynchronously. Care should be taken when using the methods to ensure that the main server thread is not @@ -124,6 +125,16 @@ public interface Storage { */ CompletableFuture> getUniqueUsers(); + /** + * Searches for a list of users 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 + * @since 2.17 + */ + CompletableFuture>> getUsersWithPermission(String permission); + /** * Creates and loads a group into the plugins local storage * @@ -171,6 +182,16 @@ public interface Storage { */ CompletableFuture deleteGroup(Group group); + /** + * 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 + * @since 2.17 + */ + CompletableFuture>> getGroupsWithPermission(String permission); + /** * Creates and loads a track into the plugins local storage * @@ -239,4 +260,14 @@ public interface Storage { */ CompletableFuture getUUID(String username); + /** + * Gets a username from a UUID + * + * @param uuid the corresponding uuid + * @return a name string, could be null + * @throws NullPointerException if either parameters are null + * @since 2.17 + */ + CompletableFuture getName(UUID uuid); + } diff --git a/api/src/main/java/me/lucko/luckperms/api/Track.java b/api/src/main/java/me/lucko/luckperms/api/Track.java index 4318af803..1a1918788 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Track.java +++ b/api/src/main/java/me/lucko/luckperms/api/Track.java @@ -28,19 +28,20 @@ import me.lucko.luckperms.exceptions.ObjectLacksException; import java.util.List; /** - * Interface for internal Track instances + * An ordered collection of groups for easy promotions and demotions */ -@SuppressWarnings("unused") public interface Track { /** + * Gets the name of this track * @return the name of this track */ String getName(); /** * Gets an ordered list of the groups on this track - * Index 0 is the first/lowest group in (or start of) the track + * + *

Index 0 is the first/lowest group in (or start of) the track * * @return an ordered {@link List} of the groups on this track */ @@ -136,7 +137,7 @@ public interface Track { boolean containsGroup(String group); /** - * Clear all of the groups within this track + * Clear all of the groups from this track */ void clearGroups(); 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 3a0bf33db..bcc17e082 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Tristate.java +++ b/api/src/main/java/me/lucko/luckperms/api/Tristate.java @@ -23,14 +23,34 @@ package me.lucko.luckperms.api; /** - * Represents a permission value + * 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. */ public enum Tristate { + /** + * A value indicating a holder has a permission set. + */ TRUE(true), + + /** + * A value indicating a holder has a negated value for a permission. + */ FALSE(false), + + /** + * A value indicating a holder doesn't have a value for a permission set. + */ UNDEFINED(false); + /** + * Converts from {@link Boolean} a boolean + * + * @param b the boolean + * @return {@link #TRUE} or {@link #FALSE}, depending on the value of the boolean. + */ public static Tristate fromBoolean(boolean b) { return b ? TRUE : FALSE; } @@ -41,6 +61,12 @@ public enum Tristate { this.booleanValue = booleanValue; } + /** + * Returns the value of the Tristate as a boolean. + *

A value of {@link #UNDEFINED} converts to false. + * + * @return a boolean representation of the Tristate. + */ public boolean asBoolean() { return booleanValue; } 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 84c93f7fa..c6d0a2af4 100644 --- a/api/src/main/java/me/lucko/luckperms/api/User.java +++ b/api/src/main/java/me/lucko/luckperms/api/User.java @@ -31,17 +31,20 @@ import java.util.Optional; import java.util.UUID; /** - * Interface for internal User instances + * A player holding permission data */ -@SuppressWarnings("unused") public interface User extends PermissionHolder { /** + * Gets the users unique ID + * * @return the users Mojang assigned unique id */ UUID getUuid(); /** + * Gets the users username + * * @return the Users Username */ String getName(); @@ -64,7 +67,10 @@ public interface User extends PermissionHolder { void setPrimaryGroup(String group) throws ObjectAlreadyHasException; /** - * Refresh and re-assign the users permissions + * 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. */ void refreshPermissions(); @@ -76,6 +82,13 @@ public interface User extends PermissionHolder { */ Optional getUserDataCache(); + /** + * Sets up the users data cache, if the don't have one setup already. + * + * @since 2.17 + */ + void setupDataCache(); + /** * Check to see if the user is a member of a group * @@ -255,11 +268,6 @@ public interface User extends PermissionHolder { */ void removeGroup(Group group, String server, String world, boolean temporary) throws ObjectLacksException; - /** - * Clear all of the users permission nodes - */ - void clearNodes(); - /** * Get a {@link List} of all of the groups the user is a member of, on all servers * 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 cc75f0ec4..545051069 100644 --- a/api/src/main/java/me/lucko/luckperms/api/UuidCache.java +++ b/api/src/main/java/me/lucko/luckperms/api/UuidCache.java @@ -28,16 +28,15 @@ import java.util.UUID; * A UUID cache for online users, between external Mojang UUIDs, and internal LuckPerms UUIDs. * *

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 random UUID for a + * 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. * *

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. * - *

WARNING: THIS IS ONLY EFFECTIVE FOR ONLINE PLAYERS. USE THE DATASTORE METHODS FOR OFFLINE PLAYERS. + *

THIS IS ONLY EFFECTIVE FOR ONLINE PLAYERS. USE THE DATASTORE METHODS FOR OFFLINE PLAYERS. */ -@SuppressWarnings("unused") public interface UuidCache { /** diff --git a/api/src/main/java/me/lucko/luckperms/api/caching/PermissionData.java b/api/src/main/java/me/lucko/luckperms/api/caching/PermissionData.java index ce10e57d3..082686534 100644 --- a/api/src/main/java/me/lucko/luckperms/api/caching/PermissionData.java +++ b/api/src/main/java/me/lucko/luckperms/api/caching/PermissionData.java @@ -44,7 +44,8 @@ public interface PermissionData { /** * Invalidates the underlying permission calculator cache. - * Can be called to allow for an update in defaults. + * + *

Can be called to allow for an update in defaults. */ void invalidateCache(); 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 4a4e84d8d..e752f71d1 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 @@ -38,7 +38,8 @@ public interface UserData { /** * Gets PermissionData from the cache, given a specified context. - * If the data is not cached, it is calculated. Therefore, this call could be costly. + * + *

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 permission data instance @@ -48,7 +49,8 @@ public interface UserData { /** * Gets MetaData from the cache, given a specified context. - * If the data is not cached, it is calculated. Therefore, this call could be costly. + * + *

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 @@ -75,8 +77,10 @@ public interface UserData { MetaData calculateMeta(Contexts contexts); /** - * Calculates permission 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. + * Calculates permission 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 @@ -84,8 +88,10 @@ 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. + * 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 @@ -111,8 +117,9 @@ public interface UserData { void preCalculate(Set contexts); /** - * Ensures that PermissionData and MetaData is cached for a context. If the cache does not contain any data for the - * context, it will be calculated and saved. + * Ensures that PermissionData and MetaData is cached for a context. + * + *

If the cache does not contain any data for the context, it will be calculated and saved. * * @param contexts the contexts to pre-calculate for * @throws NullPointerException if contexts is null diff --git a/bukkit-legacy/pom.xml b/bukkit-legacy/pom.xml index dca315330..c3373e2a3 100644 --- a/bukkit-legacy/pom.xml +++ b/bukkit-legacy/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 2.16-SNAPSHOT + 2.17-SNAPSHOT 4.0.0 diff --git a/bukkit-placeholders/pom.xml b/bukkit-placeholders/pom.xml index cd0dd1f8f..e81e432ae 100644 --- a/bukkit-placeholders/pom.xml +++ b/bukkit-placeholders/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 2.16-SNAPSHOT + 2.17-SNAPSHOT 4.0.0 diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 9507eab11..0941283c9 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 2.16-SNAPSHOT + 2.17-SNAPSHOT 4.0.0 diff --git a/bungee/pom.xml b/bungee/pom.xml index 51e901ec9..eba3bd358 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 2.16-SNAPSHOT + 2.17-SNAPSHOT 4.0.0 diff --git a/common/pom.xml b/common/pom.xml index 564e1b755..a02790028 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 2.16-SNAPSHOT + 2.17-SNAPSHOT 4.0.0 diff --git a/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java b/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java index 821fa1d6f..201a893a1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java @@ -35,24 +35,26 @@ import me.lucko.luckperms.api.Logger; import me.lucko.luckperms.api.LuckPermsApi; import me.lucko.luckperms.api.MessagingService; import me.lucko.luckperms.api.Node; +import me.lucko.luckperms.api.NodeFactory; import me.lucko.luckperms.api.PlatformType; import me.lucko.luckperms.api.Storage; import me.lucko.luckperms.api.Track; import me.lucko.luckperms.api.User; import me.lucko.luckperms.api.UuidCache; import me.lucko.luckperms.api.context.ContextListener; +import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.context.IContextCalculator; import me.lucko.luckperms.api.event.LPEvent; import me.lucko.luckperms.api.event.LPListener; import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.api.internal.DatastoreLink; -import me.lucko.luckperms.common.api.internal.GroupLink; -import me.lucko.luckperms.common.api.internal.LPConfigurationLink; -import me.lucko.luckperms.common.api.internal.StorageLink; -import me.lucko.luckperms.common.api.internal.TrackLink; -import me.lucko.luckperms.common.api.internal.UserLink; -import me.lucko.luckperms.common.api.internal.Utils; -import me.lucko.luckperms.common.api.internal.UuidCacheLink; +import me.lucko.luckperms.common.api.delegate.DatastoreDelegate; +import me.lucko.luckperms.common.api.delegate.GroupDelegate; +import me.lucko.luckperms.common.api.delegate.LPConfigurationDelegate; +import me.lucko.luckperms.common.api.delegate.NodeFactoryDelegate; +import me.lucko.luckperms.common.api.delegate.StorageDelegate; +import me.lucko.luckperms.common.api.delegate.TrackDelegate; +import me.lucko.luckperms.common.api.delegate.UserDelegate; +import me.lucko.luckperms.common.api.delegate.UuidCacheDelegate; import me.lucko.luckperms.common.core.NodeBuilder; import me.lucko.luckperms.common.core.UserIdentifier; @@ -61,7 +63,7 @@ import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; -import static me.lucko.luckperms.common.api.internal.Utils.checkNode; +import static me.lucko.luckperms.common.api.ApiUtils.checkNode; /** * Implements the LuckPerms API using the plugin instance @@ -92,7 +94,7 @@ public class ApiProvider implements LuckPermsApi { @Override public double getApiVersion() { - return 2.16; + return 2.17; } @Override @@ -117,18 +119,18 @@ public class ApiProvider implements LuckPermsApi { @Override public LPConfiguration getConfiguration() { - return new LPConfigurationLink(plugin.getConfiguration()); + return new LPConfigurationDelegate(plugin.getConfiguration()); } @Override public Storage getStorage() { - return new StorageLink(plugin, plugin.getStorage()); + return new StorageDelegate(plugin, plugin.getStorage()); } @SuppressWarnings("deprecation") @Override public Datastore getDatastore() { - return new DatastoreLink(plugin, plugin.getStorage()); + return new DatastoreDelegate(plugin, plugin.getStorage()); } @Override @@ -138,7 +140,7 @@ public class ApiProvider implements LuckPermsApi { @Override public UuidCache getUuidCache() { - return new UuidCacheLink(plugin.getUuidCache()); + return new UuidCacheDelegate(plugin.getUuidCache()); } @Override @@ -149,7 +151,7 @@ public class ApiProvider implements LuckPermsApi { @Override public User getUser(@NonNull UUID uuid) { final me.lucko.luckperms.common.core.model.User user = plugin.getUserManager().get(uuid); - return user == null ? null : new UserLink(user); + return user == null ? null : new UserDelegate(user); } @Override @@ -160,7 +162,7 @@ public class ApiProvider implements LuckPermsApi { @Override public User getUser(@NonNull String name) { final me.lucko.luckperms.common.core.model.User user = plugin.getUserManager().getByUsername(name); - return user == null ? null : new UserLink(user); + return user == null ? null : new UserDelegate(user); } @Override @@ -170,7 +172,7 @@ public class ApiProvider implements LuckPermsApi { @Override public Set getUsers() { - return plugin.getUserManager().getAll().values().stream().map(UserLink::new).collect(Collectors.toSet()); + return plugin.getUserManager().getAll().values().stream().map(UserDelegate::new).collect(Collectors.toSet()); } @Override @@ -180,14 +182,14 @@ public class ApiProvider implements LuckPermsApi { @Override public void cleanupUser(@NonNull User user) { - Utils.checkUser(user); - plugin.getUserManager().cleanup(((UserLink) user).getMaster()); + ApiUtils.checkUser(user); + plugin.getUserManager().cleanup(((UserDelegate) user).getMaster()); } @Override public Group getGroup(@NonNull String name) { final me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(name); - return group == null ? null : new GroupLink(group); + return group == null ? null : new GroupDelegate(group); } @Override @@ -197,7 +199,7 @@ public class ApiProvider implements LuckPermsApi { @Override public Set getGroups() { - return plugin.getGroupManager().getAll().values().stream().map(GroupLink::new).collect(Collectors.toSet()); + return plugin.getGroupManager().getAll().values().stream().map(GroupDelegate::new).collect(Collectors.toSet()); } @Override @@ -208,7 +210,7 @@ public class ApiProvider implements LuckPermsApi { @Override public Track getTrack(@NonNull String name) { final me.lucko.luckperms.common.core.model.Track track = plugin.getTrackManager().getIfLoaded(name); - return track == null ? null : new TrackLink(track); + return track == null ? null : new TrackDelegate(track); } @Override @@ -218,7 +220,7 @@ public class ApiProvider implements LuckPermsApi { @Override public Set getTracks() { - return plugin.getTrackManager().getAll().values().stream().map(TrackLink::new).collect(Collectors.toSet()); + return plugin.getTrackManager().getAll().values().stream().map(TrackDelegate::new).collect(Collectors.toSet()); } @Override @@ -226,6 +228,11 @@ public class ApiProvider implements LuckPermsApi { return plugin.getTrackManager().isLoaded(name); } + @Override + public NodeFactory getNodeFactory() { + return NodeFactoryDelegate.INSTANCE; + } + @Override public Node.Builder buildNode(@NonNull String permission) throws IllegalArgumentException { return new NodeBuilder(checkNode(permission)); @@ -245,7 +252,13 @@ public class ApiProvider implements LuckPermsApi { @Override public Optional getContextForUser(User user) { - Utils.checkUser(user); - return Optional.ofNullable(plugin.getContextForUser(((UserLink) user).getMaster())); + ApiUtils.checkUser(user); + return Optional.ofNullable(plugin.getContextForUser(((UserDelegate) user).getMaster())); + } + + @SuppressWarnings("unchecked") + @Override + public ContextSet getContextForPlayer(Object player) { + return plugin.getContextManager().getApplicableContext(player); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/Utils.java b/common/src/main/java/me/lucko/luckperms/common/api/ApiUtils.java similarity index 82% rename from common/src/main/java/me/lucko/luckperms/common/api/internal/Utils.java rename to common/src/main/java/me/lucko/luckperms/common/api/ApiUtils.java index cfa1a870e..39d962bdf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/Utils.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/ApiUtils.java @@ -20,7 +20,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.api.internal; +package me.lucko.luckperms.common.api; import lombok.experimental.UtilityClass; @@ -29,21 +29,24 @@ import com.google.common.base.Preconditions; import me.lucko.luckperms.api.Group; import me.lucko.luckperms.api.Track; import me.lucko.luckperms.api.User; +import me.lucko.luckperms.common.api.delegate.GroupDelegate; +import me.lucko.luckperms.common.api.delegate.TrackDelegate; +import me.lucko.luckperms.common.api.delegate.UserDelegate; import me.lucko.luckperms.common.utils.ArgumentChecker; @UtilityClass -public class Utils { +public class ApiUtils { public static void checkUser(User user) { - Preconditions.checkState(user instanceof UserLink, "User instance cannot be handled by this implementation."); + Preconditions.checkState(user instanceof UserDelegate, "User instance cannot be handled by this implementation."); } public static void checkGroup(Group group) { - Preconditions.checkState(group instanceof GroupLink, "Group instance cannot be handled by this implementation."); + Preconditions.checkState(group instanceof GroupDelegate, "Group instance cannot be handled by this implementation."); } public static void checkTrack(Track track) { - Preconditions.checkState(track instanceof TrackLink, "Track instance cannot be handled by this implementation."); + Preconditions.checkState(track instanceof TrackDelegate, "Track instance cannot be handled by this implementation."); } public static String checkUsername(String s) { diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/DatastoreLink.java b/common/src/main/java/me/lucko/luckperms/common/api/delegate/DatastoreDelegate.java similarity index 85% rename from common/src/main/java/me/lucko/luckperms/common/api/internal/DatastoreLink.java rename to common/src/main/java/me/lucko/luckperms/common/api/delegate/DatastoreDelegate.java index 9d2919d49..2431c09a3 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/DatastoreLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegate/DatastoreDelegate.java @@ -20,7 +20,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.api.internal; +package me.lucko.luckperms.common.api.delegate; import lombok.AllArgsConstructor; import lombok.NonNull; @@ -39,19 +39,14 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.CompletableFuture; -import static me.lucko.luckperms.common.api.internal.Utils.checkGroup; -import static me.lucko.luckperms.common.api.internal.Utils.checkName; -import static me.lucko.luckperms.common.api.internal.Utils.checkTrack; -import static me.lucko.luckperms.common.api.internal.Utils.checkUser; -import static me.lucko.luckperms.common.api.internal.Utils.checkUsername; +import static me.lucko.luckperms.common.api.ApiUtils.checkGroup; +import static me.lucko.luckperms.common.api.ApiUtils.checkName; +import static me.lucko.luckperms.common.api.ApiUtils.checkTrack; +import static me.lucko.luckperms.common.api.ApiUtils.checkUser; +import static me.lucko.luckperms.common.api.ApiUtils.checkUsername; -/** - * Provides a link between {@link Datastore} and {@link Storage} - * - * Note that this class only provides for the old deprecated interface, see {@link StorageLink} for the new one. - */ -@SuppressWarnings({"unused", "WeakerAccess", "deprecation"}) -public class DatastoreLink implements Datastore { +@SuppressWarnings("deprecation") +public class DatastoreDelegate implements Datastore { private final LuckPermsPlugin plugin; private final Storage master; @@ -59,7 +54,7 @@ public class DatastoreLink implements Datastore { private final Sync sync; private final Future future; - public DatastoreLink(@NonNull LuckPermsPlugin plugin, @NonNull Storage master) { + public DatastoreDelegate(@NonNull LuckPermsPlugin plugin, @NonNull Storage master) { this.plugin = plugin; this.master = master; this.async = new Async(master); @@ -109,7 +104,7 @@ public class DatastoreLink implements Datastore { @Override public void getLog(@NonNull Callback callback) { - master.force().getLog().thenAcceptAsync(log -> callback.onComplete(new LogLink(log)), plugin.getSyncExecutor()); + master.force().getLog().thenAcceptAsync(log -> callback.onComplete(new LogDelegate(log)), plugin.getSyncExecutor()); } @Override @@ -130,7 +125,7 @@ public class DatastoreLink implements Datastore { @Override public void saveUser(@NonNull User user, Callback callback) { checkUser(user); - registerCallback(master.force().saveUser(((UserLink) user).getMaster()), callback); + registerCallback(master.force().saveUser(((UserDelegate) user).getMaster()), callback); } @Override @@ -161,7 +156,7 @@ public class DatastoreLink implements Datastore { @Override public void saveGroup(@NonNull Group group, Callback callback) { checkGroup(group); - registerCallback(master.force().saveGroup(((GroupLink) group).getMaster()), callback); + registerCallback(master.force().saveGroup(((GroupDelegate) group).getMaster()), callback); } @Override @@ -170,7 +165,7 @@ public class DatastoreLink implements Datastore { if (group.getName().equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) { throw new IllegalArgumentException("Cannot delete the default group."); } - registerCallback(master.force().deleteGroup(((GroupLink) group).getMaster()), callback); + registerCallback(master.force().deleteGroup(((GroupDelegate) group).getMaster()), callback); } @Override @@ -191,13 +186,13 @@ public class DatastoreLink implements Datastore { @Override public void saveTrack(@NonNull Track track, Callback callback) { checkTrack(track); - registerCallback(master.force().saveTrack(((TrackLink) track).getMaster()), callback); + registerCallback(master.force().saveTrack(((TrackDelegate) track).getMaster()), callback); } @Override public void deleteTrack(@NonNull Track track, Callback callback) { checkTrack(track); - registerCallback(master.force().deleteTrack(((TrackLink) track).getMaster()), callback); + registerCallback(master.force().deleteTrack(((TrackDelegate) track).getMaster()), callback); } @Override @@ -226,7 +221,7 @@ public class DatastoreLink implements Datastore { if (log == null) { return null; } - return new LogLink(log); + return new LogDelegate(log); } @Override @@ -247,7 +242,7 @@ public class DatastoreLink implements Datastore { @Override public boolean saveUser(@NonNull User user) { checkUser(user); - return master.force().saveUser(((UserLink) user).getMaster()).join(); + return master.force().saveUser(((UserDelegate) user).getMaster()).join(); } @Override @@ -278,7 +273,7 @@ public class DatastoreLink implements Datastore { @Override public boolean saveGroup(@NonNull Group group) { checkGroup(group); - return master.force().saveGroup(((GroupLink) group).getMaster()).join(); + return master.force().saveGroup(((GroupDelegate) group).getMaster()).join(); } @Override @@ -287,7 +282,7 @@ public class DatastoreLink implements Datastore { if (group.getName().equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) { throw new IllegalArgumentException("Cannot delete the default group."); } - return master.force().deleteGroup(((GroupLink) group).getMaster()).join(); + return master.force().deleteGroup(((GroupDelegate) group).getMaster()).join(); } @Override @@ -308,13 +303,13 @@ public class DatastoreLink implements Datastore { @Override public boolean saveTrack(@NonNull Track track) { checkTrack(track); - return master.force().saveTrack(((TrackLink) track).getMaster()).join(); + return master.force().saveTrack(((TrackDelegate) track).getMaster()).join(); } @Override public boolean deleteTrack(@NonNull Track track) { checkTrack(track); - return master.force().deleteTrack(((TrackLink) track).getMaster()).join(); + return master.force().deleteTrack(((TrackDelegate) track).getMaster()).join(); } @Override @@ -339,7 +334,7 @@ public class DatastoreLink implements Datastore { @Override public java.util.concurrent.Future getLog() { - return master.force().getLog().thenApply(log -> log == null ? null : new LogLink(log)); + return master.force().getLog().thenApply(log -> log == null ? null : new LogDelegate(log)); } @Override @@ -360,7 +355,7 @@ public class DatastoreLink implements Datastore { @Override public java.util.concurrent.Future saveUser(@NonNull User user) { checkUser(user); - return master.force().saveUser(((UserLink) user).getMaster()); + return master.force().saveUser(((UserDelegate) user).getMaster()); } @Override @@ -391,7 +386,7 @@ public class DatastoreLink implements Datastore { @Override public java.util.concurrent.Future saveGroup(@NonNull Group group) { checkGroup(group); - return master.force().saveGroup(((GroupLink) group).getMaster()); + return master.force().saveGroup(((GroupDelegate) group).getMaster()); } @Override @@ -400,7 +395,7 @@ public class DatastoreLink implements Datastore { if (group.getName().equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) { throw new IllegalArgumentException("Cannot delete the default group."); } - return master.force().deleteGroup(((GroupLink) group).getMaster()); + return master.force().deleteGroup(((GroupDelegate) group).getMaster()); } @Override @@ -421,13 +416,13 @@ public class DatastoreLink implements Datastore { @Override public java.util.concurrent.Future saveTrack(@NonNull Track track) { checkTrack(track); - return master.force().saveTrack(((TrackLink) track).getMaster()); + return master.force().saveTrack(((TrackDelegate) track).getMaster()); } @Override public java.util.concurrent.Future deleteTrack(@NonNull Track track) { checkTrack(track); - return master.force().deleteTrack(((TrackLink) track).getMaster()); + return master.force().deleteTrack(((TrackDelegate) track).getMaster()); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/GroupLink.java b/common/src/main/java/me/lucko/luckperms/common/api/delegate/GroupDelegate.java similarity index 71% rename from common/src/main/java/me/lucko/luckperms/common/api/internal/GroupLink.java rename to common/src/main/java/me/lucko/luckperms/common/api/delegate/GroupDelegate.java index 77f878202..e4f943bb1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/GroupLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegate/GroupDelegate.java @@ -20,7 +20,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.api.internal; +package me.lucko.luckperms.common.api.delegate; import lombok.AccessLevel; import lombok.EqualsAndHashCode; @@ -32,17 +32,17 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; import java.util.List; +import java.util.OptionalInt; -import static me.lucko.luckperms.common.api.internal.Utils.checkGroup; -import static me.lucko.luckperms.common.api.internal.Utils.checkServer; -import static me.lucko.luckperms.common.api.internal.Utils.checkTime; +import static me.lucko.luckperms.common.api.ApiUtils.checkGroup; +import static me.lucko.luckperms.common.api.ApiUtils.checkServer; +import static me.lucko.luckperms.common.api.ApiUtils.checkTime; /** * Provides a link between {@link Group} and {@link me.lucko.luckperms.common.core.model.Group} */ @EqualsAndHashCode(of = {"name"}, callSuper = false) -@SuppressWarnings("unused") -public class GroupLink extends PermissionHolderLink implements Group { +public class GroupDelegate extends PermissionHolderDelegate implements Group { @Getter(AccessLevel.PACKAGE) private final me.lucko.luckperms.common.core.model.Group master; @@ -50,7 +50,7 @@ public class GroupLink extends PermissionHolderLink implements Group { @Getter private final String name; - public GroupLink(@NonNull me.lucko.luckperms.common.core.model.Group master) { + public GroupDelegate(@NonNull me.lucko.luckperms.common.core.model.Group master) { super(master); this.master = master; this.name = master.getName(); @@ -59,91 +59,91 @@ public class GroupLink extends PermissionHolderLink implements Group { @Override public boolean inheritsGroup(@NonNull Group group) { checkGroup(group); - return master.inheritsGroup(((GroupLink) group).getMaster()); + return master.inheritsGroup(((GroupDelegate) group).getMaster()); } @Override public boolean inheritsGroup(@NonNull Group group, @NonNull String server) { checkGroup(group); - return master.inheritsGroup(((GroupLink) group).getMaster(), server); + return master.inheritsGroup(((GroupDelegate) group).getMaster(), server); } @Override public boolean inheritsGroup(@NonNull Group group, @NonNull String server, @NonNull String world) { checkGroup(group); - return master.inheritsGroup(((GroupLink) group).getMaster(), server, world); + return master.inheritsGroup(((GroupDelegate) group).getMaster(), server, world); } @Override public void setInheritGroup(@NonNull Group group) throws ObjectAlreadyHasException { checkGroup(group); - master.setInheritGroup(((GroupLink) group).getMaster()); + master.setInheritGroup(((GroupDelegate) group).getMaster()); } @Override public void setInheritGroup(@NonNull Group group, @NonNull String server) throws ObjectAlreadyHasException { checkGroup(group); - master.setInheritGroup(((GroupLink) group).getMaster(), checkServer(server)); + master.setInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server)); } @Override public void setInheritGroup(@NonNull Group group, @NonNull String server, @NonNull String world) throws ObjectAlreadyHasException { checkGroup(group); - master.setInheritGroup(((GroupLink) group).getMaster(), checkServer(server), world); + master.setInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), world); } @Override public void setInheritGroup(@NonNull Group group, @NonNull long expireAt) throws ObjectAlreadyHasException { checkGroup(group); - master.setInheritGroup(((GroupLink) group).getMaster(), checkTime(expireAt)); + master.setInheritGroup(((GroupDelegate) group).getMaster(), checkTime(expireAt)); } @Override public void setInheritGroup(@NonNull Group group, @NonNull String server, @NonNull long expireAt) throws ObjectAlreadyHasException { checkGroup(group); - master.setInheritGroup(((GroupLink) group).getMaster(), checkServer(server), checkTime(expireAt)); + master.setInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), checkTime(expireAt)); } @Override public void setInheritGroup(@NonNull Group group, @NonNull String server, @NonNull String world, @NonNull long expireAt) throws ObjectAlreadyHasException { checkGroup(group); - master.setInheritGroup(((GroupLink) group).getMaster(), checkServer(server), world, checkTime(expireAt)); + master.setInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), world, checkTime(expireAt)); } @Override public void unsetInheritGroup(@NonNull Group group) throws ObjectLacksException { checkGroup(group); - master.unsetInheritGroup(((GroupLink) group).getMaster()); + master.unsetInheritGroup(((GroupDelegate) group).getMaster()); } @Override public void unsetInheritGroup(@NonNull Group group, @NonNull boolean temporary) throws ObjectLacksException { checkGroup(group); - master.unsetInheritGroup(((GroupLink) group).getMaster(), temporary); + master.unsetInheritGroup(((GroupDelegate) group).getMaster(), temporary); } @Override public void unsetInheritGroup(@NonNull Group group, @NonNull String server) throws ObjectLacksException { checkGroup(group); - master.unsetInheritGroup(((GroupLink) group).getMaster(), checkServer(server)); + master.unsetInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server)); } @Override public void unsetInheritGroup(@NonNull Group group, @NonNull String server, @NonNull String world) throws ObjectLacksException { checkGroup(group); - master.unsetInheritGroup(((GroupLink) group).getMaster(), checkServer(server), world); + master.unsetInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), world); } @Override public void unsetInheritGroup(@NonNull Group group, @NonNull String server, @NonNull boolean temporary) throws ObjectLacksException { checkGroup(group); - master.unsetInheritGroup(((GroupLink) group).getMaster(), checkServer(server), temporary); + master.unsetInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), temporary); } @Override public void unsetInheritGroup(@NonNull Group group, @NonNull String server, @NonNull String world, @NonNull boolean temporary) throws ObjectLacksException { checkGroup(group); - master.unsetInheritGroup(((GroupLink) group).getMaster(), checkServer(server), world, temporary); + master.unsetInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), world, temporary); } @Override @@ -161,6 +161,11 @@ public class GroupLink extends PermissionHolderLink implements Group { return master.getLocalGroups(checkServer(server), world); } + @Override + public OptionalInt getWeight() { + return master.getWeight(); + } + @Override public List getLocalGroups(@NonNull String server) { return master.getLocalGroups(checkServer(server)); diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/LPConfigurationLink.java b/common/src/main/java/me/lucko/luckperms/common/api/delegate/LPConfigurationDelegate.java similarity index 97% rename from common/src/main/java/me/lucko/luckperms/common/api/internal/LPConfigurationLink.java rename to common/src/main/java/me/lucko/luckperms/common/api/delegate/LPConfigurationDelegate.java index 2003ffa85..e3fcfdd53 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/LPConfigurationLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegate/LPConfigurationDelegate.java @@ -20,7 +20,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.api.internal; +package me.lucko.luckperms.common.api.delegate; import lombok.AllArgsConstructor; @@ -34,7 +34,7 @@ import java.util.Map; * Provides a link between {@link LPConfiguration} and {@link me.lucko.luckperms.common.config.LPConfiguration} */ @AllArgsConstructor -public class LPConfigurationLink implements LPConfiguration { +public class LPConfigurationDelegate implements LPConfiguration { private final me.lucko.luckperms.common.config.LPConfiguration master; @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/LogLink.java b/common/src/main/java/me/lucko/luckperms/common/api/delegate/LogDelegate.java similarity index 96% rename from common/src/main/java/me/lucko/luckperms/common/api/internal/LogLink.java rename to common/src/main/java/me/lucko/luckperms/common/api/delegate/LogDelegate.java index 725cf08b9..d6c88ba09 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/LogLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegate/LogDelegate.java @@ -20,7 +20,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.api.internal; +package me.lucko.luckperms.common.api.delegate; import lombok.AllArgsConstructor; import lombok.NonNull; @@ -32,13 +32,13 @@ import java.util.SortedMap; import java.util.SortedSet; import java.util.UUID; -import static me.lucko.luckperms.common.api.internal.Utils.checkName; +import static me.lucko.luckperms.common.api.ApiUtils.checkName; /** * Provides a link between {@link Log} and {@link me.lucko.luckperms.common.data.Log} */ @AllArgsConstructor -public class LogLink implements Log { +public class LogDelegate implements Log { private final me.lucko.luckperms.common.data.Log master; @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/api/delegate/NodeFactoryDelegate.java b/common/src/main/java/me/lucko/luckperms/common/api/delegate/NodeFactoryDelegate.java new file mode 100644 index 000000000..0ad36f638 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegate/NodeFactoryDelegate.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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.common.api.delegate; + +import lombok.NonNull; + +import me.lucko.luckperms.api.Node; +import me.lucko.luckperms.common.core.NodeFactory; + +public class NodeFactoryDelegate implements me.lucko.luckperms.api.NodeFactory { + public static final NodeFactoryDelegate INSTANCE = new NodeFactoryDelegate(); + + @Override + public Node fromSerialisedNode(@NonNull String serialisedPermission, boolean value) { + return NodeFactory.fromSerialisedNode(serialisedPermission, value); + } + + @Override + public Node.Builder newBuilder(@NonNull String permission) { + return NodeFactory.newBuilder(permission); + } + + @Override + public Node.Builder newBuilderFromExisting(@NonNull Node other) { + return NodeFactory.builderFromExisting(other); + } + + @Override + public Node.Builder newBuilderFromSerialisedNode(@NonNull String serialisedPermission, boolean value) { + return NodeFactory.builderFromSerialisedNode(serialisedPermission, value); + } + + @Override + public Node.Builder makeMetaNode(@NonNull String key, @NonNull String value) { + return NodeFactory.makeMetaNode(key, value); + } + + @Override + public Node.Builder makePrefixNode(int priority, @NonNull String prefix) { + return NodeFactory.makePrefixNode(priority, prefix); + } + + @Override + public Node.Builder makeSuffixNode(int priority, @NonNull String suffix) { + return NodeFactory.makeSuffixNode(priority, suffix); + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/PermissionHolderLink.java b/common/src/main/java/me/lucko/luckperms/common/api/delegate/PermissionHolderDelegate.java similarity index 83% rename from common/src/main/java/me/lucko/luckperms/common/api/internal/PermissionHolderLink.java rename to common/src/main/java/me/lucko/luckperms/common/api/delegate/PermissionHolderDelegate.java index e83f18dda..9b99da4be 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/PermissionHolderLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegate/PermissionHolderDelegate.java @@ -20,11 +20,15 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.api.internal; +package me.lucko.luckperms.common.api.delegate; import lombok.AllArgsConstructor; import lombok.NonNull; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSortedSet; + import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.LocalizedNode; import me.lucko.luckperms.api.Node; @@ -36,16 +40,17 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; import java.util.AbstractMap; -import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedSet; +import java.util.TreeSet; -import static me.lucko.luckperms.common.api.internal.Utils.checkNode; -import static me.lucko.luckperms.common.api.internal.Utils.checkServer; -import static me.lucko.luckperms.common.api.internal.Utils.checkTime; +import static me.lucko.luckperms.common.api.ApiUtils.checkNode; +import static me.lucko.luckperms.common.api.ApiUtils.checkServer; +import static me.lucko.luckperms.common.api.ApiUtils.checkTime; import static me.lucko.luckperms.common.core.model.PermissionHolder.exportToLegacy; /** @@ -53,7 +58,7 @@ import static me.lucko.luckperms.common.core.model.PermissionHolder.exportToLega */ @SuppressWarnings("unused") @AllArgsConstructor -public class PermissionHolderLink implements PermissionHolder { +public class PermissionHolderDelegate implements PermissionHolder { private final me.lucko.luckperms.common.core.model.PermissionHolder master; @Override @@ -63,37 +68,42 @@ public class PermissionHolderLink implements PermissionHolder { @Override public SortedSet getPermissions() { - return master.getPermissions(false); + return ImmutableSortedSet.copyOf(master.getPermissions(false)); } @Override public Set getEnduringPermissions() { - return master.getNodes(); + return ImmutableSet.copyOf(master.getNodes()); } @Override public Set getTransientPermissions() { - return master.getTransientNodes(); + return ImmutableSet.copyOf(master.getTransientNodes()); } @Override public Set getAllNodes() { - return Collections.unmodifiableSet(master.getAllNodes(null, ExtractedContexts.generate(Contexts.allowAll()))); + return ImmutableSet.copyOf(master.getAllNodes(null, ExtractedContexts.generate(Contexts.allowAll()))); } @Override public SortedSet getAllNodes(@NonNull Contexts contexts) { - return master.getAllNodes(null, ExtractedContexts.generate(contexts)); + return new TreeSet<>(master.getAllNodes(null, ExtractedContexts.generate(contexts))); } @Override public Set getAllNodesFiltered(@NonNull Contexts contexts) { - return master.getAllNodesFiltered(ExtractedContexts.generate(contexts)); + return new HashSet<>(master.getAllNodesFiltered(ExtractedContexts.generate(contexts))); + } + + @Override + public Map exportNodes(Contexts contexts, boolean lowerCase) { + return new HashMap<>(master.exportNodes(contexts, lowerCase)); } @Override public Map getNodes() { - return exportToLegacy(master.getNodes()); + return ImmutableMap.copyOf(exportToLegacy(master.getNodes())); } @Override @@ -251,6 +261,61 @@ public class PermissionHolderLink implements PermissionHolder { master.unsetPermission(checkNode(node), checkServer(server), world, temporary); } + @Override + public void clearNodes() { + master.clearNodes(); + } + + @Override + public void clearNodes(String server) { + master.clearNodes(server); + } + + @Override + public void clearNodes(String server, String world) { + master.clearNodes(server, world); + } + + @Override + public void clearParents() { + master.clearParents(); + } + + @Override + public void clearParents(String server) { + master.clearParents(server); + } + + @Override + public void clearParents(String server, String world) { + master.clearParents(server, world); + } + + @Override + public void clearMeta() { + master.clearMeta(); + } + + @Override + public void clearMeta(String server) { + master.clearMeta(server); + } + + @Override + public void clearMeta(String server, String world) { + master.clearMeta(server, world); + } + + @Override + public void clearMetaKeys(String key, String server, String world, boolean temporary) { + master.clearMetaKeys(key, server, world, temporary); + } + + @Override + public void clearTransientNodes() { + master.clearTransientNodes(); + } + @Override public Map getLocalPermissions(String server, String world, List excludedGroups, List possibleNodes) { Map context = new HashMap<>(); diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/StorageLink.java b/common/src/main/java/me/lucko/luckperms/common/api/delegate/StorageDelegate.java similarity index 77% rename from common/src/main/java/me/lucko/luckperms/common/api/internal/StorageLink.java rename to common/src/main/java/me/lucko/luckperms/common/api/delegate/StorageDelegate.java index 96f5d241d..7c603180e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/StorageLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegate/StorageDelegate.java @@ -20,12 +20,13 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.api.internal; +package me.lucko.luckperms.common.api.delegate; import lombok.AllArgsConstructor; import lombok.NonNull; import me.lucko.luckperms.api.Group; +import me.lucko.luckperms.api.HeldPermission; import me.lucko.luckperms.api.Log; import me.lucko.luckperms.api.LogEntry; import me.lucko.luckperms.api.Storage; @@ -33,22 +34,23 @@ import me.lucko.luckperms.api.Track; import me.lucko.luckperms.api.User; import me.lucko.luckperms.common.LuckPermsPlugin; +import java.util.List; import java.util.Set; import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; -import static me.lucko.luckperms.common.api.internal.Utils.checkGroup; -import static me.lucko.luckperms.common.api.internal.Utils.checkName; -import static me.lucko.luckperms.common.api.internal.Utils.checkTrack; -import static me.lucko.luckperms.common.api.internal.Utils.checkUser; -import static me.lucko.luckperms.common.api.internal.Utils.checkUsername; +import static me.lucko.luckperms.common.api.ApiUtils.checkGroup; +import static me.lucko.luckperms.common.api.ApiUtils.checkName; +import static me.lucko.luckperms.common.api.ApiUtils.checkTrack; +import static me.lucko.luckperms.common.api.ApiUtils.checkUser; +import static me.lucko.luckperms.common.api.ApiUtils.checkUsername; /** * Provides a link between {@link Storage} and {@link me.lucko.luckperms.common.storage.Storage} */ @AllArgsConstructor -public class StorageLink implements Storage { +public class StorageDelegate implements Storage { private final LuckPermsPlugin plugin; private final me.lucko.luckperms.common.storage.Storage master; @@ -79,7 +81,7 @@ public class StorageLink implements Storage { @Override public CompletableFuture getLog() { - return master.force().getLog().thenApply(log -> log == null ? null : new LogLink(log)); + return master.force().getLog().thenApply(log -> log == null ? null : new LogDelegate(log)); } @Override @@ -90,7 +92,7 @@ public class StorageLink implements Storage { @Override public CompletableFuture saveUser(User user) { checkUser(user); - return master.force().saveUser(((UserLink) user).getMaster()); + return master.force().saveUser(((UserDelegate) user).getMaster()); } @Override @@ -103,6 +105,11 @@ public class StorageLink implements Storage { return master.force().getUniqueUsers(); } + @Override + public CompletableFuture>> getUsersWithPermission(@NonNull String permission) { + return master.force().getUsersWithPermission(permission); + } + @Override public CompletableFuture createAndLoadGroup(String name) { return master.force().createAndLoadGroup(checkName(name)); @@ -121,7 +128,7 @@ public class StorageLink implements Storage { @Override public CompletableFuture saveGroup(Group group) { checkGroup(group); - return master.force().saveGroup(((GroupLink) group).getMaster()); + return master.force().saveGroup(((GroupDelegate) group).getMaster()); } @Override @@ -130,7 +137,12 @@ public class StorageLink implements Storage { if (group.getName().equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) { throw new IllegalArgumentException("Cannot delete the default group."); } - return master.force().deleteGroup(((GroupLink) group).getMaster()); + return master.force().deleteGroup(((GroupDelegate) group).getMaster()); + } + + @Override + public CompletableFuture>> getGroupsWithPermission(@NonNull String permission) { + return master.force().getGroupsWithPermission(permission); } @Override @@ -151,13 +163,13 @@ public class StorageLink implements Storage { @Override public CompletableFuture saveTrack(Track track) { checkTrack(track); - return master.force().saveTrack(((TrackLink) track).getMaster()); + return master.force().saveTrack(((TrackDelegate) track).getMaster()); } @Override public CompletableFuture deleteTrack(Track track) { checkTrack(track); - return master.force().deleteTrack(((TrackLink) track).getMaster()); + return master.force().deleteTrack(((TrackDelegate) track).getMaster()); } @Override @@ -169,4 +181,9 @@ public class StorageLink implements Storage { public CompletableFuture getUUID(String username) { return master.force().getUUID(checkUsername(username)); } + + @Override + public CompletableFuture getName(@NonNull UUID uuid) { + return master.force().getName(uuid); + } } diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/TrackLink.java b/common/src/main/java/me/lucko/luckperms/common/api/delegate/TrackDelegate.java similarity index 82% rename from common/src/main/java/me/lucko/luckperms/common/api/internal/TrackLink.java rename to common/src/main/java/me/lucko/luckperms/common/api/delegate/TrackDelegate.java index 5ab4589ab..94a032866 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/TrackLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegate/TrackDelegate.java @@ -20,7 +20,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.api.internal; +package me.lucko.luckperms.common.api.delegate; import lombok.AccessLevel; import lombok.EqualsAndHashCode; @@ -34,14 +34,14 @@ import me.lucko.luckperms.exceptions.ObjectLacksException; import java.util.List; -import static me.lucko.luckperms.common.api.internal.Utils.checkGroup; +import static me.lucko.luckperms.common.api.ApiUtils.checkGroup; /** * Provides a link between {@link Track} and {@link me.lucko.luckperms.common.core.model.Track} */ @EqualsAndHashCode(of = {"name"}) @SuppressWarnings("unused") -public class TrackLink implements Track { +public class TrackDelegate implements Track { @Getter(AccessLevel.PACKAGE) private final me.lucko.luckperms.common.core.model.Track master; @@ -49,7 +49,7 @@ public class TrackLink implements Track { @Getter private final String name; - public TrackLink(@NonNull me.lucko.luckperms.common.core.model.Track master) { + public TrackDelegate(@NonNull me.lucko.luckperms.common.core.model.Track master) { this.master = master; this.name = master.getName(); } @@ -67,31 +67,31 @@ public class TrackLink implements Track { @Override public String getNext(@NonNull Group current) throws ObjectLacksException { checkGroup(current); - return master.getNext(((GroupLink) current).getMaster()); + return master.getNext(((GroupDelegate) current).getMaster()); } @Override public String getPrevious(@NonNull Group current) throws ObjectLacksException { checkGroup(current); - return master.getPrevious(((GroupLink) current).getMaster()); + return master.getPrevious(((GroupDelegate) current).getMaster()); } @Override public void appendGroup(@NonNull Group group) throws ObjectAlreadyHasException { checkGroup(group); - master.appendGroup(((GroupLink) group).getMaster()); + master.appendGroup(((GroupDelegate) group).getMaster()); } @Override public void insertGroup(@NonNull Group group, @NonNull int position) throws ObjectAlreadyHasException, IndexOutOfBoundsException { checkGroup(group); - master.insertGroup(((GroupLink) group).getMaster(), position); + master.insertGroup(((GroupDelegate) group).getMaster(), position); } @Override public void removeGroup(@NonNull Group group) throws ObjectLacksException { checkGroup(group); - master.removeGroup(((GroupLink) group).getMaster()); + master.removeGroup(((GroupDelegate) group).getMaster()); } @Override @@ -102,7 +102,7 @@ public class TrackLink implements Track { @Override public boolean containsGroup(@NonNull Group group) { checkGroup(group); - return master.containsGroup(((GroupLink) group).getMaster()); + return master.containsGroup(((GroupDelegate) group).getMaster()); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/UserLink.java b/common/src/main/java/me/lucko/luckperms/common/api/delegate/UserDelegate.java similarity index 75% rename from common/src/main/java/me/lucko/luckperms/common/api/internal/UserLink.java rename to common/src/main/java/me/lucko/luckperms/common/api/delegate/UserDelegate.java index 1327fafa5..8884e8bc0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/UserLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegate/UserDelegate.java @@ -20,7 +20,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.api.internal; +package me.lucko.luckperms.common.api.delegate; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -36,16 +36,16 @@ import java.util.List; import java.util.Optional; import java.util.UUID; -import static me.lucko.luckperms.common.api.internal.Utils.checkGroup; -import static me.lucko.luckperms.common.api.internal.Utils.checkServer; -import static me.lucko.luckperms.common.api.internal.Utils.checkTime; +import static me.lucko.luckperms.common.api.ApiUtils.checkGroup; +import static me.lucko.luckperms.common.api.ApiUtils.checkServer; +import static me.lucko.luckperms.common.api.ApiUtils.checkTime; /** * Provides a link between {@link User} and {@link me.lucko.luckperms.common.core.model.User} */ @EqualsAndHashCode(of = {"uuid"}, callSuper = false) @SuppressWarnings("unused") -public class UserLink extends PermissionHolderLink implements User { +public class UserDelegate extends PermissionHolderDelegate implements User { @Getter private final me.lucko.luckperms.common.core.model.User master; @@ -53,7 +53,7 @@ public class UserLink extends PermissionHolderLink implements User { @Getter private final UUID uuid; - public UserLink(@NonNull me.lucko.luckperms.common.core.model.User master) { + public UserDelegate(@NonNull me.lucko.luckperms.common.core.model.User master) { super(master); this.master = master; this.uuid = master.getUuid(); @@ -92,94 +92,99 @@ public class UserLink extends PermissionHolderLink implements User { return Optional.ofNullable(master.getUserData()); } + @Override + public void setupDataCache() { + master.setupData(false); + } + @Override public boolean isInGroup(@NonNull Group group) { checkGroup(group); - return master.inheritsGroup(((GroupLink) group).getMaster()); + return master.inheritsGroup(((GroupDelegate) group).getMaster()); } @Override public boolean isInGroup(@NonNull Group group, @NonNull String server) { checkGroup(group); - return master.inheritsGroup(((GroupLink) group).getMaster(), server); + return master.inheritsGroup(((GroupDelegate) group).getMaster(), server); } @Override public boolean isInGroup(@NonNull Group group, @NonNull String server, @NonNull String world) { checkGroup(group); - return master.inheritsGroup(((GroupLink) group).getMaster(), server, world); + return master.inheritsGroup(((GroupDelegate) group).getMaster(), server, world); } @Override public void addGroup(@NonNull Group group) throws ObjectAlreadyHasException { checkGroup(group); - master.setInheritGroup(((GroupLink) group).getMaster()); + master.setInheritGroup(((GroupDelegate) group).getMaster()); } @Override public void addGroup(@NonNull Group group, @NonNull String server) throws ObjectAlreadyHasException { checkGroup(group); - master.setInheritGroup(((GroupLink) group).getMaster(), checkServer(server)); + master.setInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server)); } @Override public void addGroup(@NonNull Group group, @NonNull String server, @NonNull String world) throws ObjectAlreadyHasException { checkGroup(group); - master.setInheritGroup(((GroupLink) group).getMaster(), checkServer(server), world); + master.setInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), world); } @Override public void addGroup(@NonNull Group group, @NonNull long expireAt) throws ObjectAlreadyHasException { checkGroup(group); - master.setInheritGroup(((GroupLink) group).getMaster(), checkTime(expireAt)); + master.setInheritGroup(((GroupDelegate) group).getMaster(), checkTime(expireAt)); } @Override public void addGroup(@NonNull Group group, @NonNull String server, @NonNull long expireAt) throws ObjectAlreadyHasException { checkGroup(group); - master.setInheritGroup(((GroupLink) group).getMaster(), checkServer(server), checkTime(expireAt)); + master.setInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), checkTime(expireAt)); } @Override public void addGroup(@NonNull Group group, @NonNull String server, @NonNull String world, @NonNull long expireAt) throws ObjectAlreadyHasException { checkGroup(group); - master.setInheritGroup(((GroupLink) group).getMaster(), checkServer(server), world, checkTime(expireAt)); + master.setInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), world, checkTime(expireAt)); } @Override public void removeGroup(@NonNull Group group) throws ObjectLacksException { checkGroup(group); - master.unsetInheritGroup(((GroupLink) group).getMaster()); + master.unsetInheritGroup(((GroupDelegate) group).getMaster()); } @Override public void removeGroup(@NonNull Group group, @NonNull boolean temporary) throws ObjectLacksException { checkGroup(group); - master.unsetInheritGroup(((GroupLink) group).getMaster(), temporary); + master.unsetInheritGroup(((GroupDelegate) group).getMaster(), temporary); } @Override public void removeGroup(@NonNull Group group, @NonNull String server) throws ObjectLacksException { checkGroup(group); - master.unsetInheritGroup(((GroupLink) group).getMaster(), checkServer(server)); + master.unsetInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server)); } @Override public void removeGroup(@NonNull Group group, @NonNull String server, @NonNull String world) throws ObjectLacksException { checkGroup(group); - master.unsetInheritGroup(((GroupLink) group).getMaster(), checkServer(server), world); + master.unsetInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), world); } @Override public void removeGroup(@NonNull Group group, @NonNull String server, @NonNull boolean temporary) throws ObjectLacksException { checkGroup(group); - master.unsetInheritGroup(((GroupLink) group).getMaster(), checkServer(server), temporary); + master.unsetInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), temporary); } @Override public void removeGroup(@NonNull Group group, @NonNull String server, @NonNull String world, @NonNull boolean temporary) throws ObjectLacksException { checkGroup(group); - master.unsetInheritGroup(((GroupLink) group).getMaster(), checkServer(server), world, temporary); + master.unsetInheritGroup(((GroupDelegate) group).getMaster(), checkServer(server), world, temporary); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/UuidCacheLink.java b/common/src/main/java/me/lucko/luckperms/common/api/delegate/UuidCacheDelegate.java similarity index 94% rename from common/src/main/java/me/lucko/luckperms/common/api/internal/UuidCacheLink.java rename to common/src/main/java/me/lucko/luckperms/common/api/delegate/UuidCacheDelegate.java index 8a38080f5..211465c20 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/UuidCacheLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegate/UuidCacheDelegate.java @@ -20,7 +20,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.common.api.internal; +package me.lucko.luckperms.common.api.delegate; import lombok.AllArgsConstructor; import lombok.NonNull; @@ -33,7 +33,7 @@ import java.util.UUID; * Provides a link between {@link UuidCache} and {@link me.lucko.luckperms.common.core.UuidCache} */ @AllArgsConstructor -public class UuidCacheLink implements UuidCache { +public class UuidCacheDelegate implements UuidCache { private final me.lucko.luckperms.common.core.UuidCache master; @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/SearchCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/SearchCommand.java index 669f70e72..f1fac9165 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/SearchCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/SearchCommand.java @@ -22,6 +22,7 @@ package me.lucko.luckperms.common.commands.misc; +import me.lucko.luckperms.api.HeldPermission; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandException; @@ -31,7 +32,6 @@ import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; -import me.lucko.luckperms.common.storage.holder.HeldPermission; import me.lucko.luckperms.common.utils.Predicates; import io.github.mkremins.fanciful.FancyMessage; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java index b0f54fb14..e90420635 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java @@ -27,8 +27,8 @@ import com.google.common.base.Objects; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.event.events.UserDemoteEvent; import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.api.internal.TrackLink; -import me.lucko.luckperms.common.api.internal.UserLink; +import me.lucko.luckperms.common.api.delegate.TrackDelegate; +import me.lucko.luckperms.common.api.delegate.UserDelegate; import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; @@ -150,7 +150,7 @@ public class UserDemote extends SubCommand { .action("demote " + args.stream().collect(Collectors.joining(" "))) .build().submit(plugin, sender); save(user, sender, plugin); - plugin.getApiProvider().fireEventAsync(new UserDemoteEvent(new TrackLink(track), new UserLink(user), old, null)); + plugin.getApiProvider().fireEventAsync(new UserDemoteEvent(new TrackDelegate(track), new UserDelegate(user), old, null)); return CommandResult.SUCCESS; } @@ -194,7 +194,7 @@ public class UserDemote extends SubCommand { .action("demote " + args.stream().collect(Collectors.joining(" "))) .build().submit(plugin, sender); save(user, sender, plugin); - plugin.getApiProvider().fireEventAsync(new UserDemoteEvent(new TrackLink(track), new UserLink(user), old, previousGroup.getName())); + plugin.getApiProvider().fireEventAsync(new UserDemoteEvent(new TrackDelegate(track), new UserDelegate(user), old, previousGroup.getName())); return CommandResult.SUCCESS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java index cc9a8ea1d..9bb16bc6e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java @@ -27,8 +27,8 @@ import com.google.common.base.Objects; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.event.events.UserPromoteEvent; import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.api.internal.TrackLink; -import me.lucko.luckperms.common.api.internal.UserLink; +import me.lucko.luckperms.common.api.delegate.TrackDelegate; +import me.lucko.luckperms.common.api.delegate.UserDelegate; import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandResult; @@ -147,7 +147,7 @@ public class UserPromote extends SubCommand { .action("promote " + args.stream().collect(Collectors.joining(" "))) .build().submit(plugin, sender); save(user, sender, plugin); - plugin.getApiProvider().fireEventAsync(new UserPromoteEvent(new TrackLink(track), new UserLink(user), null, first)); + plugin.getApiProvider().fireEventAsync(new UserPromoteEvent(new TrackDelegate(track), new UserDelegate(user), null, first)); return CommandResult.SUCCESS; } @@ -211,7 +211,7 @@ public class UserPromote extends SubCommand { .action("promote " + args.stream().collect(Collectors.joining(" "))) .build().submit(plugin, sender); save(user, sender, plugin); - plugin.getApiProvider().fireEventAsync(new UserPromoteEvent(new TrackLink(track), new UserLink(user), old, nextGroup.getName())); + plugin.getApiProvider().fireEventAsync(new UserPromoteEvent(new TrackDelegate(track), new UserDelegate(user), old, nextGroup.getName())); return CommandResult.SUCCESS; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/utils/Util.java b/common/src/main/java/me/lucko/luckperms/common/commands/utils/Util.java index 59199b7ae..1b86c1a83 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/utils/Util.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/utils/Util.java @@ -26,6 +26,7 @@ import lombok.experimental.UtilityClass; import com.google.common.collect.Maps; +import me.lucko.luckperms.api.HeldPermission; import me.lucko.luckperms.api.LocalizedNode; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.Tristate; @@ -35,7 +36,6 @@ import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Patterns; import me.lucko.luckperms.common.core.model.PermissionHolder; import me.lucko.luckperms.common.core.model.User; -import me.lucko.luckperms.common.storage.holder.HeldPermission; import me.lucko.luckperms.common.utils.DateUtil; import io.github.mkremins.fanciful.ChatColor; diff --git a/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java index 3f8a93706..e9631475c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java @@ -45,8 +45,8 @@ import me.lucko.luckperms.api.event.events.PermissionNodeExpireEvent; import me.lucko.luckperms.api.event.events.PermissionNodeSetEvent; import me.lucko.luckperms.api.event.events.PermissionNodeUnsetEvent; import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.api.internal.GroupLink; -import me.lucko.luckperms.common.api.internal.PermissionHolderLink; +import me.lucko.luckperms.common.api.delegate.GroupDelegate; +import me.lucko.luckperms.common.api.delegate.PermissionHolderDelegate; import me.lucko.luckperms.common.caching.MetaHolder; import me.lucko.luckperms.common.caching.handlers.CachedStateManager; import me.lucko.luckperms.common.caching.handlers.GroupReference; @@ -581,7 +581,7 @@ public abstract class PermissionHolder { return false; } - PermissionHolderLink link = new PermissionHolderLink(this); + PermissionHolderDelegate link = new PermissionHolderDelegate(this); for (Node r : removed) { plugin.getApiProvider().fireEventAsync(new PermissionNodeExpireEvent(link, r)); } @@ -700,7 +700,7 @@ public abstract class PermissionHolder { } invalidateCache(true); - plugin.getApiProvider().fireEventAsync(new PermissionNodeSetEvent(new PermissionHolderLink(this), node)); + plugin.getApiProvider().fireEventAsync(new PermissionNodeSetEvent(new PermissionHolderDelegate(this), node)); } /** @@ -719,7 +719,7 @@ public abstract class PermissionHolder { } invalidateCache(false); - plugin.getApiProvider().fireEventAsync(new PermissionNodeSetEvent(new PermissionHolderLink(this), node)); + plugin.getApiProvider().fireEventAsync(new PermissionNodeSetEvent(new PermissionHolderDelegate(this), node)); } public void setPermission(String node, boolean value) throws ObjectAlreadyHasException { @@ -763,10 +763,10 @@ public abstract class PermissionHolder { invalidateCache(true); if (node.isGroupNode()) { - plugin.getApiProvider().fireEventAsync(new GroupRemoveEvent(new PermissionHolderLink(this), + plugin.getApiProvider().fireEventAsync(new GroupRemoveEvent(new PermissionHolderDelegate(this), node.getGroupName(), node.getServer().orElse(null), node.getWorld().orElse(null), node.isTemporary())); } else { - plugin.getApiProvider().fireEventAsync(new PermissionNodeUnsetEvent(new PermissionHolderLink(this), node)); + plugin.getApiProvider().fireEventAsync(new PermissionNodeUnsetEvent(new PermissionHolderDelegate(this), node)); } } @@ -787,10 +787,10 @@ public abstract class PermissionHolder { invalidateCache(false); if (node.isGroupNode()) { - plugin.getApiProvider().fireEventAsync(new GroupRemoveEvent(new PermissionHolderLink(this), + plugin.getApiProvider().fireEventAsync(new GroupRemoveEvent(new PermissionHolderDelegate(this), node.getGroupName(), node.getServer().orElse(null), node.getWorld().orElse(null), node.isTemporary())); } else { - plugin.getApiProvider().fireEventAsync(new PermissionNodeUnsetEvent(new PermissionHolderLink(this), node)); + plugin.getApiProvider().fireEventAsync(new PermissionNodeUnsetEvent(new PermissionHolderDelegate(this), node)); } } @@ -836,7 +836,7 @@ public abstract class PermissionHolder { } setPermission("group." + group.getName(), true); - getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderLink(this), new GroupLink(group), null, null, 0L)); + getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderDelegate(this), new GroupDelegate(group), null, null, 0L)); } public void setInheritGroup(Group group, String server) throws ObjectAlreadyHasException { @@ -845,7 +845,7 @@ public abstract class PermissionHolder { } setPermission("group." + group.getName(), true, server); - getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderLink(this), new GroupLink(group), server, null, 0L)); + getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderDelegate(this), new GroupDelegate(group), server, null, 0L)); } public void setInheritGroup(Group group, String server, String world) throws ObjectAlreadyHasException { @@ -854,7 +854,7 @@ public abstract class PermissionHolder { } setPermission("group." + group.getName(), true, server, world); - getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderLink(this), new GroupLink(group), server, world, 0L)); + getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderDelegate(this), new GroupDelegate(group), server, world, 0L)); } public void setInheritGroup(Group group, long expireAt) throws ObjectAlreadyHasException { @@ -863,7 +863,7 @@ public abstract class PermissionHolder { } setPermission("group." + group.getName(), true, expireAt); - getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderLink(this), new GroupLink(group), null, null, expireAt)); + getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderDelegate(this), new GroupDelegate(group), null, null, expireAt)); } public void setInheritGroup(Group group, String server, long expireAt) throws ObjectAlreadyHasException { @@ -872,7 +872,7 @@ public abstract class PermissionHolder { } setPermission("group." + group.getName(), true, server, expireAt); - getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderLink(this), new GroupLink(group), server, null, expireAt)); + getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderDelegate(this), new GroupDelegate(group), server, null, expireAt)); } public void setInheritGroup(Group group, String server, String world, long expireAt) throws ObjectAlreadyHasException { @@ -881,7 +881,7 @@ public abstract class PermissionHolder { } setPermission("group." + group.getName(), true, server, world, expireAt); - getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderLink(this), new GroupLink(group), server, world, expireAt)); + getPlugin().getApiProvider().fireEventAsync(new GroupAddEvent(new PermissionHolderDelegate(this), new GroupDelegate(group), server, world, expireAt)); } public void unsetInheritGroup(Group group) throws ObjectLacksException { @@ -1087,6 +1087,8 @@ public abstract class PermissionHolder { } public OptionalInt getWeight() { + if (this instanceof User) return OptionalInt.empty(); + OptionalInt weight = OptionalInt.empty(); try { weight = getNodes().stream() diff --git a/common/src/main/java/me/lucko/luckperms/common/core/model/User.java b/common/src/main/java/me/lucko/luckperms/common/core/model/User.java index 6c036d196..6fe1f0221 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/model/User.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/model/User.java @@ -30,7 +30,7 @@ import lombok.ToString; import me.lucko.luckperms.api.caching.UserData; import me.lucko.luckperms.api.event.events.UserPermissionRefreshEvent; import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.api.internal.UserLink; +import me.lucko.luckperms.common.api.delegate.UserDelegate; import me.lucko.luckperms.common.caching.UserCache; import me.lucko.luckperms.common.caching.handlers.HolderReference; import me.lucko.luckperms.common.caching.handlers.UserReference; @@ -139,7 +139,7 @@ public class User extends PermissionHolder implements Identifiableme.lucko.luckperms luckperms - 2.16-SNAPSHOT + 2.17-SNAPSHOT common api @@ -38,7 +38,7 @@ UTF-8 - 2.16 + 2.17 diff --git a/sponge/pom.xml b/sponge/pom.xml index f04d63f69..3dde52118 100644 --- a/sponge/pom.xml +++ b/sponge/pom.xml @@ -5,7 +5,7 @@ luckperms me.lucko.luckperms - 2.16-SNAPSHOT + 2.17-SNAPSHOT 4.0.0