From 2ffbeeef8e8314e312da9d42b767b24fa5a7d5e4 Mon Sep 17 00:00:00 2001 From: Luck Date: Sat, 24 Jun 2017 17:25:13 +0100 Subject: [PATCH] Add jsr305 annotations to the API --- api/pom.xml | 6 + .../java/me/lucko/luckperms/LuckPerms.java | 4 + .../me/lucko/luckperms/api/ChatMetaType.java | 23 ++-- .../java/me/lucko/luckperms/api/Contexts.java | 9 +- .../java/me/lucko/luckperms/api/Group.java | 43 ++++--- .../lucko/luckperms/api/HeldPermission.java | 8 ++ .../lucko/luckperms/api/LPConfiguration.java | 7 + .../me/lucko/luckperms/api/LocalizedNode.java | 4 + .../main/java/me/lucko/luckperms/api/Log.java | 45 ++++--- .../java/me/lucko/luckperms/api/LogEntry.java | 24 +++- .../java/me/lucko/luckperms/api/Logger.java | 8 +- .../me/lucko/luckperms/api/LuckPermsApi.java | 59 ++++++--- .../java/me/lucko/luckperms/api/Node.java | 84 ++++++++---- .../me/lucko/luckperms/api/NodeFactory.java | 29 +++-- .../lucko/luckperms/api/PermissionHolder.java | 120 ++++++++++-------- .../me/lucko/luckperms/api/PlatformType.java | 3 + .../java/me/lucko/luckperms/api/Storage.java | 62 ++++++--- .../java/me/lucko/luckperms/api/Track.java | 23 ++-- .../java/me/lucko/luckperms/api/Tristate.java | 3 + .../java/me/lucko/luckperms/api/User.java | 51 +++++--- .../me/lucko/luckperms/api/UuidCache.java | 8 +- .../luckperms/api/caching/MetaContexts.java | 10 +- .../lucko/luckperms/api/caching/MetaData.java | 11 ++ .../luckperms/api/caching/PermissionData.java | 6 +- .../lucko/luckperms/api/caching/UserData.java | 30 +++-- .../api/context/ContextCalculator.java | 5 +- .../luckperms/api/context/ContextSet.java | 42 ++++-- .../api/context/ImmutableContextSet.java | 106 ++++++---------- .../api/context/MutableContextSet.java | 68 ++++------ .../api/data/DatastoreConfiguration.java | 6 + .../luckperms/api/event/Cancellable.java | 3 + .../lucko/luckperms/api/event/EventBus.java | 8 +- .../luckperms/api/event/EventHandler.java | 4 + .../luckperms/api/event/LuckPermsEvent.java | 3 + .../api/event/group/GroupCreateEvent.java | 4 + .../api/event/group/GroupDeleteEvent.java | 5 + .../api/event/group/GroupLoadEvent.java | 3 + .../api/event/log/LogBroadcastEvent.java | 3 + .../api/event/log/LogPublishEvent.java | 3 + .../api/event/node/NodeAddEvent.java | 3 + .../api/event/node/NodeMutateEvent.java | 5 + .../api/event/node/NodeRemoveEvent.java | 3 + .../api/event/sync/PreNetworkSyncEvent.java | 3 + .../api/event/track/TrackCreateEvent.java | 4 + .../api/event/track/TrackDeleteEvent.java | 5 + .../api/event/track/TrackLoadEvent.java | 3 + .../track/mutate/TrackAddGroupEvent.java | 3 + .../event/track/mutate/TrackMutateEvent.java | 5 + .../track/mutate/TrackRemoveGroupEvent.java | 3 + .../api/event/user/UserCacheLoadEvent.java | 4 + .../event/user/UserDataRecalculateEvent.java | 4 + .../api/event/user/UserFirstLoginEvent.java | 4 + .../api/event/user/UserLoadEvent.java | 3 + .../api/event/user/track/UserTrackEvent.java | 7 + .../api/metastacking/MetaStackDefinition.java | 6 + .../api/metastacking/MetaStackElement.java | 5 +- .../api/metastacking/MetaStackFactory.java | 11 +- .../luckperms/common/api/ApiProvider.java | 6 +- .../luckperms/common/utils/SenderLogger.java | 7 +- 59 files changed, 690 insertions(+), 347 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 8b996d751..4794bc58a 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -100,6 +100,12 @@ 19.0 provided + + com.google.code.findbugs + jsr305 + 3.0.2 + compile + diff --git a/api/src/main/java/me/lucko/luckperms/LuckPerms.java b/api/src/main/java/me/lucko/luckperms/LuckPerms.java index db4525cd7..71de6dc64 100644 --- a/api/src/main/java/me/lucko/luckperms/LuckPerms.java +++ b/api/src/main/java/me/lucko/luckperms/LuckPerms.java @@ -29,6 +29,8 @@ import me.lucko.luckperms.api.LuckPermsApi; import java.util.Optional; +import javax.annotation.Nonnull; + /** * Singleton for the {@link LuckPermsApi}. * @@ -44,6 +46,7 @@ public final class LuckPerms { * @return an api instance * @throws IllegalStateException if the api is not loaded */ + @Nonnull public static LuckPermsApi getApi() { if (api == null) { throw new IllegalStateException("API is not loaded."); @@ -59,6 +62,7 @@ public final class LuckPerms { * * @return an optional api instance */ + @Nonnull public static Optional getApiSafe() { return Optional.ofNullable(api); } diff --git a/api/src/main/java/me/lucko/luckperms/api/ChatMetaType.java b/api/src/main/java/me/lucko/luckperms/api/ChatMetaType.java index 413fa7969..6aca7ab99 100644 --- a/api/src/main/java/me/lucko/luckperms/api/ChatMetaType.java +++ b/api/src/main/java/me/lucko/luckperms/api/ChatMetaType.java @@ -25,8 +25,12 @@ package me.lucko.luckperms.api; +import com.google.common.base.Preconditions; + import java.util.Map; +import javax.annotation.Nonnull; + /** * Represents a type of chat meta * @@ -40,17 +44,17 @@ public enum ChatMetaType { PREFIX { @Override public boolean matches(Node node) { - return node.isPrefix(); + return Preconditions.checkNotNull(node, "node").isPrefix(); } @Override public boolean shouldIgnore(Node node) { - return !node.isPrefix(); + return !Preconditions.checkNotNull(node, "node").isPrefix(); } @Override public Map.Entry getEntry(Node node) { - return node.getPrefix(); + return Preconditions.checkNotNull(node, "node").getPrefix(); } }, @@ -60,17 +64,17 @@ public enum ChatMetaType { SUFFIX { @Override public boolean matches(Node node) { - return node.isSuffix(); + return Preconditions.checkNotNull(node, "node").isSuffix(); } @Override public boolean shouldIgnore(Node node) { - return !node.isSuffix(); + return !Preconditions.checkNotNull(node, "node").isSuffix(); } @Override public Map.Entry getEntry(Node node) { - return node.getSuffix(); + return Preconditions.checkNotNull(node, "node").getSuffix(); } }; @@ -80,7 +84,7 @@ public enum ChatMetaType { * @param node the node to test * @return true if the node has the same type */ - public abstract boolean matches(Node node); + public abstract boolean matches(@Nonnull Node node); /** * Returns if the passed node should be ignored when searching for meta of this type @@ -88,7 +92,7 @@ public enum ChatMetaType { * @param node the node to test * @return true if the node does not share the same type */ - public abstract boolean shouldIgnore(Node node); + public abstract boolean shouldIgnore(@Nonnull Node node); /** * Maps the corresponding entry from the given node @@ -97,6 +101,7 @@ public enum ChatMetaType { * @return the entry * @throws IllegalStateException if the node does not share the same type */ - public abstract Map.Entry getEntry(Node node); + @Nonnull + public abstract Map.Entry getEntry(@Nonnull Node node); } diff --git a/api/src/main/java/me/lucko/luckperms/api/Contexts.java b/api/src/main/java/me/lucko/luckperms/api/Contexts.java index 101b4fc0c..2ea47dbbc 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Contexts.java +++ b/api/src/main/java/me/lucko/luckperms/api/Contexts.java @@ -27,6 +27,8 @@ package me.lucko.luckperms.api; import me.lucko.luckperms.api.context.ContextSet; +import javax.annotation.Nonnull; + /** * Context and options for a permission lookup. * @@ -44,11 +46,12 @@ public class Contexts { * * @return a context that will not apply any filters */ + @Nonnull public static Contexts allowAll() { return ALLOW_ALL; } - public static Contexts of(ContextSet context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) { + public static Contexts of(@Nonnull ContextSet context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) { return new Contexts(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups, op); } @@ -90,7 +93,7 @@ public class Contexts { */ private final boolean applyGlobalWorldGroups; - public Contexts(ContextSet context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) { + public Contexts(@Nonnull ContextSet context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) { if (context == null) { throw new NullPointerException("context"); } @@ -110,6 +113,7 @@ public class Contexts { * @return an immutable set of context key value pairs * @since 2.13 */ + @Nonnull public ContextSet getContexts() { return this.context; } @@ -169,6 +173,7 @@ public class Contexts { } @Override + @Nonnull public String toString() { return "Contexts(" + "context=" + this.getContexts() + ", " + 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 581b4c090..90847c3d3 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Group.java +++ b/api/src/main/java/me/lucko/luckperms/api/Group.java @@ -32,6 +32,8 @@ import me.lucko.luckperms.exceptions.ObjectLacksException; import java.util.List; import java.util.OptionalInt; +import javax.annotation.Nonnull; + /** * A group which holds permission data. */ @@ -42,6 +44,7 @@ public interface Group extends PermissionHolder { * * @return the name of the group */ + @Nonnull String getName(); /** @@ -52,7 +55,7 @@ public interface Group extends PermissionHolder { * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ - boolean inheritsGroup(Group group); + boolean inheritsGroup(@Nonnull Group group); /** * Check to see if a group inherits another group directly @@ -64,7 +67,7 @@ public interface Group extends PermissionHolder { * @throws IllegalStateException if the group instance was not obtained from LuckPerms. * @since 3.2 */ - boolean inheritsGroup(Group group, ContextSet contextSet); + boolean inheritsGroup(@Nonnull Group group, @Nonnull ContextSet contextSet); /** * Gets the weight of this group, if present. @@ -72,6 +75,7 @@ public interface Group extends PermissionHolder { * @return the group weight * @since 2.17 */ + @Nonnull OptionalInt getWeight(); /** @@ -86,7 +90,7 @@ public interface Group extends PermissionHolder { * @deprecated in favour of {@link #inheritsGroup(Group, ContextSet)} */ @Deprecated - boolean inheritsGroup(Group group, String server); + boolean inheritsGroup(@Nonnull Group group, @Nonnull String server); /** * Check to see if the group inherits a group on a specific server and world @@ -101,7 +105,7 @@ public interface Group extends PermissionHolder { * @deprecated in favour of {@link #inheritsGroup(Group, ContextSet)} */ @Deprecated - boolean inheritsGroup(Group group, String server, String world); + boolean inheritsGroup(@Nonnull Group group, @Nonnull String server, @Nonnull String world); /** * Make this group inherit another group @@ -113,7 +117,7 @@ public interface Group extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void setInheritGroup(Group group) throws ObjectAlreadyHasException; + void setInheritGroup(@Nonnull Group group) throws ObjectAlreadyHasException; /** * Make this group inherit another group on a specific server @@ -127,7 +131,7 @@ public interface Group extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void setInheritGroup(Group group, String server) throws ObjectAlreadyHasException; + void setInheritGroup(@Nonnull Group group, @Nonnull String server) throws ObjectAlreadyHasException; /** * Make this group inherit another group on a specific server and world @@ -142,7 +146,7 @@ public interface Group extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void setInheritGroup(Group group, String server, String world) throws ObjectAlreadyHasException; + void setInheritGroup(@Nonnull Group group, @Nonnull String server, @Nonnull String world) throws ObjectAlreadyHasException; /** * Make this group inherit another group temporarily @@ -156,7 +160,7 @@ public interface Group extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void setInheritGroup(Group group, long expireAt) throws ObjectAlreadyHasException; + void setInheritGroup(@Nonnull Group group, long expireAt) throws ObjectAlreadyHasException; /** * Make this group inherit another group on a specific server temporarily @@ -171,7 +175,7 @@ public interface Group extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void setInheritGroup(Group group, String server, long expireAt) throws ObjectAlreadyHasException; + void setInheritGroup(@Nonnull Group group, @Nonnull String server, long expireAt) throws ObjectAlreadyHasException; /** * Make this group inherit another group on a specific server and world temporarily @@ -187,7 +191,7 @@ public interface Group extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void setInheritGroup(Group group, String server, String world, long expireAt) throws ObjectAlreadyHasException; + void setInheritGroup(@Nonnull Group group, @Nonnull String server, @Nonnull String world, long expireAt) throws ObjectAlreadyHasException; /** * Remove a previously set inheritance rule @@ -199,7 +203,7 @@ public interface Group extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void unsetInheritGroup(Group group) throws ObjectLacksException; + void unsetInheritGroup(@Nonnull Group group) throws ObjectLacksException; /** * Remove a previously set inheritance rule @@ -212,7 +216,7 @@ public interface Group extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void unsetInheritGroup(Group group, boolean temporary) throws ObjectLacksException; + void unsetInheritGroup(@Nonnull Group group, boolean temporary) throws ObjectLacksException; /** * Remove a previously set inheritance rule on a specific server @@ -226,7 +230,7 @@ public interface Group extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void unsetInheritGroup(Group group, String server) throws ObjectLacksException; + void unsetInheritGroup(@Nonnull Group group, @Nonnull String server) throws ObjectLacksException; /** * Remove a previously set inheritance rule on a specific server and world @@ -241,7 +245,7 @@ public interface Group extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void unsetInheritGroup(Group group, String server, String world) throws ObjectLacksException; + void unsetInheritGroup(@Nonnull Group group, @Nonnull String server, @Nonnull String world) throws ObjectLacksException; /** * Remove a previously set inheritance rule on a specific server @@ -256,7 +260,7 @@ public interface Group extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void unsetInheritGroup(Group group, String server, boolean temporary) throws ObjectLacksException; + void unsetInheritGroup(@Nonnull Group group, @Nonnull String server, boolean temporary) throws ObjectLacksException; /** * Remove a previously set inheritance rule on a specific server and world @@ -272,7 +276,7 @@ public interface Group extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void unsetInheritGroup(Group group, String server, String world, boolean temporary) throws ObjectLacksException; + void unsetInheritGroup(@Nonnull Group group, @Nonnull String server, @Nonnull String world, boolean temporary) throws ObjectLacksException; /** * Get a {@link List} of all of the groups the group inherits, on all servers @@ -281,6 +285,7 @@ public interface Group extends PermissionHolder { * @deprecated in favour of just querying a users permissions */ @Deprecated + @Nonnull List getGroupNames(); /** @@ -293,7 +298,8 @@ public interface Group extends PermissionHolder { * @deprecated in favour of just querying a users permissions */ @Deprecated - List getLocalGroups(String server); + @Nonnull + List getLocalGroups(@Nonnull String server); /** @@ -307,6 +313,7 @@ public interface Group extends PermissionHolder { * @deprecated in favour of just querying a users permissions */ @Deprecated - List getLocalGroups(String server, String world); + @Nonnull + List getLocalGroups(@Nonnull String server, @Nonnull String world); } diff --git a/api/src/main/java/me/lucko/luckperms/api/HeldPermission.java b/api/src/main/java/me/lucko/luckperms/api/HeldPermission.java index 86a85a90b..13d8f446d 100644 --- a/api/src/main/java/me/lucko/luckperms/api/HeldPermission.java +++ b/api/src/main/java/me/lucko/luckperms/api/HeldPermission.java @@ -30,6 +30,8 @@ import com.google.common.collect.Multimap; import java.util.Optional; import java.util.OptionalLong; +import javax.annotation.Nonnull; + /** * A relationship between a Holder and a permission * @@ -43,6 +45,7 @@ public interface HeldPermission { * * @return the holder */ + @Nonnull T getHolder(); /** @@ -50,6 +53,7 @@ public interface HeldPermission { * * @return the permission */ + @Nonnull String getPermission(); /** @@ -64,6 +68,7 @@ public interface HeldPermission { * * @return the server */ + @Nonnull Optional getServer(); /** @@ -71,6 +76,7 @@ public interface HeldPermission { * * @return the world */ + @Nonnull Optional getWorld(); /** @@ -85,6 +91,7 @@ public interface HeldPermission { * * @return the context */ + @Nonnull Multimap getContext(); /** @@ -92,6 +99,7 @@ public interface HeldPermission { * * @return a Node copy of this permission */ + @Nonnull 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 ef6978b8f..a35abe1c8 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LPConfiguration.java +++ b/api/src/main/java/me/lucko/luckperms/api/LPConfiguration.java @@ -29,6 +29,8 @@ import me.lucko.luckperms.api.data.DatastoreConfiguration; import java.util.Map; +import javax.annotation.Nonnull; + /** * Read-only access to the LuckPerms configuration settings */ @@ -38,6 +40,7 @@ public interface LPConfiguration { * Returns the name of this server * @return the name of this server */ + @Nonnull String getServer(); /** @@ -130,6 +133,7 @@ public interface LPConfiguration { * @return the name of the server used within Vault operations * @since 2.7 */ + @Nonnull String getVaultServer(); /** @@ -143,12 +147,14 @@ public interface LPConfiguration { * Returns the values set for data storage in the configuration * @return the values set for data storage in the configuration */ + @Nonnull DatastoreConfiguration getDatastoreConfig(); /** * Returns the storage method string from the configuration * @return the storage method string from the configuration */ + @Nonnull String getStorageMethod(); /** @@ -164,6 +170,7 @@ public interface LPConfiguration { * method. For example: key = user, value = json * @since 2.7 */ + @Nonnull Map getSplitStorageOptions(); } 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 45154b641..8ec58956b 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LocalizedNode.java +++ b/api/src/main/java/me/lucko/luckperms/api/LocalizedNode.java @@ -25,6 +25,8 @@ package me.lucko.luckperms.api; +import javax.annotation.Nonnull; + /** * A node with a traceable origin * @@ -37,6 +39,7 @@ public interface LocalizedNode extends Node { * * @return the node this instance is representing */ + @Nonnull Node getNode(); /** @@ -45,6 +48,7 @@ public interface LocalizedNode extends Node { * @return where the node was inherited from. Will not return null. * @see PermissionHolder#getObjectName() */ + @Nonnull String getLocation(); } 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 f5b2f1f55..27a626eef 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Log.java +++ b/api/src/main/java/me/lucko/luckperms/api/Log.java @@ -29,6 +29,8 @@ import java.util.SortedMap; import java.util.SortedSet; import java.util.UUID; +import javax.annotation.Nonnull; + /** * Represents the internal LuckPerms log. * @@ -40,11 +42,13 @@ public interface Log { /** * @return a {@link SortedSet} of all of the {@link LogEntry} objects in this {@link Log} */ + @Nonnull SortedSet getContent(); /** * @return all content in this log */ + @Nonnull SortedSet getRecent(); /** @@ -55,6 +59,7 @@ public interface Log { * @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()}} */ + @Nonnull SortedMap getRecent(int pageNo); /** @@ -67,7 +72,8 @@ public interface Log { * @param actor the uuid of the actor to filter by * @return all content in this log where is actor = uuid */ - SortedSet getRecent(UUID actor); + @Nonnull + SortedSet getRecent(@Nonnull UUID actor); /** * Gets the recent content for the uuid, separated into pages @@ -78,20 +84,22 @@ public interface Log { * @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); + @Nonnull + SortedMap getRecent(int pageNo, @Nonnull UUID actor); /** * @param actor the actor to filter by * @return the max page number allowed in the {@link #getRecent(int, UUID)} method */ - int getRecentMaxPages(UUID actor); + int getRecentMaxPages(@Nonnull UUID actor); /** * @param uuid the uuid to filter by * @return all content in this log where the user = uuid */ - SortedSet getUserHistory(UUID uuid); + @Nonnull + SortedSet getUserHistory(@Nonnull UUID uuid); /** * Gets the user history content, separated by pages @@ -102,20 +110,22 @@ public interface Log { * @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); + @Nonnull + SortedMap getUserHistory(int pageNo, @Nonnull UUID uuid); /** * @param uuid the uuid to filter by * @return the max page number allowed in the {@link #getUserHistory(int, UUID)} method */ - int getUserHistoryMaxPages(UUID uuid); + int getUserHistoryMaxPages(@Nonnull UUID uuid); /** * @param name the name to filter by * @return all content in this log where the group = name */ - SortedSet getGroupHistory(String name); + @Nonnull + SortedSet getGroupHistory(@Nonnull String name); /** * Gets the group history content, separated by pages @@ -126,20 +136,22 @@ public interface Log { * @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); + @Nonnull + SortedMap getGroupHistory(int pageNo, @Nonnull String name); /** * @param name the name to filter by * @return the max page number allowed in the {@link #getGroupHistory(int, String)} method */ - int getGroupHistoryMaxPages(String name); + int getGroupHistoryMaxPages(@Nonnull String name); /** * @param name the name to filter by * @return all content in this log where the track = name */ - SortedSet getTrackHistory(String name); + @Nonnull + SortedSet getTrackHistory(@Nonnull String name); /** * Gets the track history content, separated by pages @@ -148,7 +160,8 @@ public interface Log { * @param name the name of the acted track to filter by * @return the page content */ - SortedMap getTrackHistory(int pageNo, String name); + @Nonnull + SortedMap getTrackHistory(int pageNo, @Nonnull String name); /** * @param name the name to filter by @@ -156,14 +169,15 @@ public interface Log { * @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); + int getTrackHistoryMaxPages(@Nonnull String name); /** * @param query the query to filter by * @return all content in this log where the content matches query */ - SortedSet getSearch(String query); + @Nonnull + SortedSet getSearch(@Nonnull String query); /** * Gets the search content, separated by pages @@ -174,11 +188,12 @@ public interface Log { * @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); + @Nonnull + SortedMap getSearch(int pageNo, @Nonnull String query); /** * @param query the query to filter by * @return the max page number allowed in the {@link #getSearch(int, String)} method */ - int getSearchMaxPages(String query); + int getSearchMaxPages(@Nonnull 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 da8bd0b4b..d6431203d 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LogEntry.java +++ b/api/src/main/java/me/lucko/luckperms/api/LogEntry.java @@ -27,6 +27,9 @@ package me.lucko.luckperms.api; import java.util.UUID; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * A single entry in the log * @@ -35,6 +38,7 @@ import java.util.UUID; public class LogEntry implements Comparable { private static final String FORMAT = "&8(&e%s&8) [&a%s&8] (&b%s&8) &7--> &f%s"; + @Nonnull public static LogEntryBuilder builder() { return new LogEntryBuilder(); } @@ -47,7 +51,7 @@ public class LogEntry implements Comparable { private String actedName; private String action; - public LogEntry(long timestamp, UUID actor, String actorName, char type, UUID acted, String actedName, String action) { + public LogEntry(long timestamp, @Nonnull UUID actor, @Nonnull String actorName, char type, @Nullable UUID acted, @Nonnull String actedName, @Nonnull String action) { if (actor == null) { throw new NullPointerException("actor"); } @@ -85,12 +89,13 @@ public class LogEntry implements Comparable { return equals(o) ? 0 : (Long.compare(timestamp, o.getTimestamp()) == 0 ? 1 : Long.compare(timestamp, o.getTimestamp())); } - public boolean matchesSearch(String query) { + public boolean matchesSearch(@Nonnull String query) { query = query.toLowerCase(); return actorName.toLowerCase().contains(query) || actedName.toLowerCase().contains(query) || action.toLowerCase().contains(query); } + @Nonnull public String getFormatted() { return String.format(FORMAT, String.valueOf(actorName).equals("null") ? actor.toString() : actorName, @@ -108,19 +113,21 @@ public class LogEntry implements Comparable { this.timestamp = timestamp; } + @Nonnull public UUID getActor() { return actor; } - void setActor(UUID actor) { + void setActor(@Nonnull UUID actor) { this.actor = actor; } + @Nonnull public String getActorName() { return actorName; } - void setActorName(String actorName) { + void setActorName(@Nonnull String actorName) { this.actorName = actorName; } @@ -132,27 +139,30 @@ public class LogEntry implements Comparable { this.type = type; } + @Nullable public UUID getActed() { return acted; } - void setActed(UUID acted) { + void setActed(@Nullable UUID acted) { this.acted = acted; } + @Nonnull public String getActedName() { return actedName; } - void setActedName(String actedName) { + void setActedName(@Nonnull String actedName) { this.actedName = actedName; } + @Nonnull public String getAction() { return action; } - void setAction(String action) { + void setAction(@Nonnull String action) { this.action = action; } 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 e563f5709..057a10a42 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Logger.java +++ b/api/src/main/java/me/lucko/luckperms/api/Logger.java @@ -25,6 +25,8 @@ package me.lucko.luckperms.api; +import javax.annotation.Nonnull; + /** * Represents the logger instance being used by LuckPerms on the platform. * @@ -33,10 +35,10 @@ package me.lucko.luckperms.api; */ public interface Logger { - void info(String s); + void info(@Nonnull String s); - void warn(String s); + void warn(@Nonnull String s); - void severe(String s); + void severe(@Nonnull String s); } 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 4fe679d6a..643209fd9 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java +++ b/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java @@ -34,6 +34,9 @@ import java.util.Optional; import java.util.Set; import java.util.UUID; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * The root API interface for LuckPerms */ @@ -57,6 +60,7 @@ public interface LuckPermsApi { * * @return the version of the plugin running on the platform */ + @Nonnull String getVersion(); /** @@ -65,6 +69,7 @@ public interface LuckPermsApi { * @return the platform LuckPerms is running on * @since 2.7 */ + @Nonnull PlatformType getPlatformType(); /** @@ -73,6 +78,7 @@ public interface LuckPermsApi { * @return the event bus * @since 3.0 */ + @Nonnull EventBus getEventBus(); /** @@ -80,6 +86,7 @@ public interface LuckPermsApi { * * @return a configuration instance */ + @Nonnull LPConfiguration getConfiguration(); /** @@ -88,6 +95,7 @@ public interface LuckPermsApi { * @return a storage instance * @since 2.14 */ + @Nonnull Storage getStorage(); /** @@ -95,6 +103,7 @@ public interface LuckPermsApi { * * @return an optional that may contain a messaging service instance. */ + @Nonnull Optional getMessagingService(); /** @@ -102,6 +111,7 @@ public interface LuckPermsApi { * * @return the logger instance */ + @Nonnull Logger getLogger(); /** @@ -109,6 +119,7 @@ public interface LuckPermsApi { * * @return a uuid cache instance */ + @Nonnull UuidCache getUuidCache(); /** @@ -118,7 +129,8 @@ public interface LuckPermsApi { * @return a {@link User} object, if one matching the uuid is loaded, or null if not * @throws NullPointerException if the uuid is null */ - User getUser(UUID uuid); + @Nullable + User getUser(@Nonnull UUID uuid); /** * Gets a wrapped user object from the user storage. @@ -129,7 +141,8 @@ public interface LuckPermsApi { * @return an optional {@link User} object * @throws NullPointerException if the uuid is null */ - Optional getUserSafe(UUID uuid); + @Nonnull + Optional getUserSafe(@Nonnull UUID uuid); /** * Gets a wrapped user object from the user storage @@ -138,7 +151,8 @@ public interface LuckPermsApi { * @return a {@link User} object, if one matching the uuid is loaded, or null if not * @throws NullPointerException if the name is null */ - User getUser(String name); + @Nullable + User getUser(@Nonnull String name); /** * Gets a wrapped user object from the user storage. @@ -149,13 +163,15 @@ public interface LuckPermsApi { * @return an optional {@link User} object * @throws NullPointerException if the name is null */ - Optional getUserSafe(String name); + @Nonnull + Optional getUserSafe(@Nonnull String name); /** * Gets a set of all loaded users. * * @return a {@link Set} of {@link User} objects */ + @Nonnull Set getUsers(); /** @@ -165,7 +181,7 @@ public interface LuckPermsApi { * @return true if the user is loaded * @throws NullPointerException if the uuid is null */ - boolean isUserLoaded(UUID uuid); + boolean isUserLoaded(@Nonnull UUID uuid); /** * Unload a user from the internal storage, if they're not currently online. @@ -174,7 +190,7 @@ public interface LuckPermsApi { * @throws NullPointerException if the user is null * @since 2.6 */ - void cleanupUser(User user); + void cleanupUser(@Nonnull User user); /** * Gets a wrapped group object from the group storage @@ -183,7 +199,8 @@ public interface LuckPermsApi { * @return a {@link Group} object, if one matching the name exists, or null if not * @throws NullPointerException if the name is null */ - Group getGroup(String name); + @Nullable + Group getGroup(@Nonnull String name); /** * Gets a wrapped group object from the group storage. @@ -194,13 +211,15 @@ public interface LuckPermsApi { * @return an optional {@link Group} object * @throws NullPointerException if the name is null */ - Optional getGroupSafe(String name); + @Nonnull + Optional getGroupSafe(@Nonnull String name); /** * Gets a set of all loaded groups. * * @return a {@link Set} of {@link Group} objects */ + @Nonnull Set getGroups(); /** @@ -210,7 +229,7 @@ public interface LuckPermsApi { * @return true if the group is loaded * @throws NullPointerException if the name is null */ - boolean isGroupLoaded(String name); + boolean isGroupLoaded(@Nonnull String name); /** * Gets a wrapped track object from the track storage @@ -219,7 +238,8 @@ public interface LuckPermsApi { * @return a {@link Track} object, if one matching the name exists, or null if not * @throws NullPointerException if the name is null */ - Track getTrack(String name); + @Nullable + Track getTrack(@Nonnull String name); /** * Gets a wrapped track object from the track storage. @@ -230,13 +250,15 @@ public interface LuckPermsApi { * @return an optional {@link Track} object * @throws NullPointerException if the name is null */ - Optional getTrackSafe(String name); + @Nonnull + Optional getTrackSafe(@Nonnull String name); /** * Gets a set of all loaded tracks. * * @return a {@link Set} of {@link Track} objects */ + @Nonnull Set getTracks(); /** @@ -246,13 +268,14 @@ public interface LuckPermsApi { * @return true if the track is loaded * @throws NullPointerException if the name is null */ - boolean isTrackLoaded(String name); + boolean isTrackLoaded(@Nonnull String name); /** * Gets the node factory instance for the platform * * @return the node factory */ + @Nonnull NodeFactory getNodeFactory(); /** @@ -261,6 +284,7 @@ public interface LuckPermsApi { * @return the meta stack factory * @since 3.2 */ + @Nonnull MetaStackFactory getMetaStackFactory(); /** @@ -272,7 +296,8 @@ public interface LuckPermsApi { * @throws NullPointerException if the permission is null * @since 2.6 */ - Node.Builder buildNode(String permission) throws IllegalArgumentException; + @Nonnull + Node.Builder buildNode(@Nonnull String permission) throws IllegalArgumentException; /** * Register a custom context calculator to the server @@ -280,7 +305,7 @@ public interface LuckPermsApi { * @param contextCalculator the context calculator to register. The type MUST be the player class of the platform. * @throws ClassCastException if the type is not the player class of the platform. */ - void registerContextCalculator(ContextCalculator contextCalculator); + void registerContextCalculator(@Nonnull ContextCalculator contextCalculator); /** * Gets a calculated context instance for the user using the rules of the platform. @@ -290,7 +315,8 @@ public interface LuckPermsApi { * @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); + @Nonnull + Optional getContextForUser(@Nonnull User user); /** * Gets set of contexts applicable to a player using the platforms {@link ContextCalculator}s. @@ -299,6 +325,7 @@ public interface LuckPermsApi { * @return a set of contexts. * @since 2.17 */ - ContextSet getContextForPlayer(Object player); + @Nonnull + ContextSet getContextForPlayer(@Nonnull Object player); } 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 d6f4013e0..eac4aa8c1 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Node.java +++ b/api/src/main/java/me/lucko/luckperms/api/Node.java @@ -33,6 +33,9 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * An immutable permission node * @@ -47,6 +50,7 @@ public interface Node extends Map.Entry { * * @return the actual permission node */ + @Nonnull String getPermission(); /** @@ -55,6 +59,7 @@ public interface Node extends Map.Entry { * @return the permission's value */ @Override + @Nonnull Boolean getValue(); /** @@ -62,6 +67,7 @@ public interface Node extends Map.Entry { * * @return the value of this node as a Tristate */ + @Nonnull default Tristate getTristate() { return Tristate.fromBoolean(getValue()); } @@ -88,6 +94,7 @@ public interface Node extends Map.Entry { * * @return an {@link Optional} containing the server, if one is defined */ + @Nonnull Optional getServer(); /** @@ -95,6 +102,7 @@ public interface Node extends Map.Entry { * * @return an {@link Optional} containing the world, if one is defined */ + @Nonnull Optional getWorld(); /** @@ -139,7 +147,7 @@ public interface Node extends Map.Entry { * @return true if the node should apply, otherwise false * @since 3.1 */ - boolean shouldApply(boolean includeGlobal, boolean includeGlobalWorld, String server, String world, ContextSet context, boolean applyRegex); + boolean shouldApply(boolean includeGlobal, boolean includeGlobalWorld, @Nullable String server, @Nullable String world, @Nullable ContextSet context, boolean applyRegex); /** * If this node should apply on a specific server @@ -149,7 +157,7 @@ public interface Node extends Map.Entry { * @param applyRegex if regex should be applied * @return true if the node should apply */ - boolean shouldApplyOnServer(String server, boolean includeGlobal, boolean applyRegex); + boolean shouldApplyOnServer(@Nullable String server, boolean includeGlobal, boolean applyRegex); /** * If this node should apply on a specific world @@ -159,7 +167,7 @@ public interface Node extends Map.Entry { * @param applyRegex if regex should be applied * @return true if the node should apply */ - boolean shouldApplyOnWorld(String world, boolean includeGlobal, boolean applyRegex); + boolean shouldApplyOnWorld(@Nullable String world, boolean includeGlobal, boolean applyRegex); /** * If this node should apply in the given context @@ -169,7 +177,7 @@ public interface Node extends Map.Entry { * @return true if the node should apply * @since 2.13 */ - boolean shouldApplyWithContext(ContextSet context, boolean worldAndServer); + boolean shouldApplyWithContext(@Nonnull ContextSet context, boolean worldAndServer); /** * If this node should apply in the given context @@ -178,7 +186,7 @@ public interface Node extends Map.Entry { * @return true if the node should apply * @since 2.13 */ - boolean shouldApplyWithContext(ContextSet context); + boolean shouldApplyWithContext(@Nonnull ContextSet context); /** * Similar to {@link #shouldApplyOnServer(String, boolean, boolean)}, except this method accepts a List @@ -187,7 +195,7 @@ public interface Node extends Map.Entry { * @param includeGlobal if global permissions should apply * @return true if the node should apply */ - boolean shouldApplyOnAnyServers(List servers, boolean includeGlobal); + boolean shouldApplyOnAnyServers(@Nonnull List servers, boolean includeGlobal); /** * Similar to {@link #shouldApplyOnWorld(String, boolean, boolean)}, except this method accepts a List @@ -196,7 +204,7 @@ public interface Node extends Map.Entry { * @param includeGlobal if global permissions should apply * @return true if the node should apply */ - boolean shouldApplyOnAnyWorlds(List worlds, boolean includeGlobal); + boolean shouldApplyOnAnyWorlds(@Nonnull List worlds, boolean includeGlobal); /** * Resolves a list of wildcards that match this node @@ -204,13 +212,15 @@ public interface Node extends Map.Entry { * @param possibleNodes a list of possible permission nodes * @return a list of permissions that match this wildcard */ - List resolveWildcard(List possibleNodes); + @Nonnull + List resolveWildcard(@Nonnull List possibleNodes); /** * Resolves any shorthand parts of this node and returns the full list * * @return a list of full nodes */ + @Nonnull List resolveShorthand(); /** @@ -235,7 +245,7 @@ public interface Node extends Map.Entry { * @return the time in Unix time when this node will expire * @throws IllegalStateException if the node is not temporary */ - long getExpiryUnixTime(); + long getExpiryUnixTime() throws IllegalStateException; /** * Returns the date when this node will expire @@ -243,7 +253,8 @@ public interface Node extends Map.Entry { * @return the {@link Date} when this node will expire * @throws IllegalStateException if the node is not temporary */ - Date getExpiry(); + @Nonnull + Date getExpiry() throws IllegalStateException; /** * Return the number of seconds until this permission will expire @@ -251,7 +262,7 @@ public interface Node extends Map.Entry { * @return the number of seconds until this permission will expire * @throws IllegalStateException if the node is not temporary */ - long getSecondsTilExpiry(); + long getSecondsTilExpiry() throws IllegalStateException; /** * Return true if the node has expired. @@ -267,6 +278,7 @@ public interface Node extends Map.Entry { * @return the extra contexts required for this node to apply * @since 2.13 */ + @Nonnull ContextSet getContexts(); /** @@ -275,6 +287,7 @@ public interface Node extends Map.Entry { * @return the full contexts required for this node to apply * @since 3.1 */ + @Nonnull ContextSet getFullContexts(); /** @@ -284,6 +297,7 @@ public interface Node extends Map.Entry { * @deprecated because this serialized form is no longer used by the implementation. */ @Deprecated + @Nonnull String toSerializedNode(); /** @@ -299,7 +313,8 @@ public interface Node extends Map.Entry { * @return the name of the group * @throws IllegalStateException if this is not a group node. See {@link #isGroupNode()} */ - String getGroupName(); + @Nonnull + String getGroupName() throws IllegalStateException; /** * Returns if this node is a wildcard node @@ -314,7 +329,7 @@ public interface Node extends Map.Entry { * @return the wildcard level * @throws IllegalStateException if this is not a wildcard */ - int getWildcardLevel(); + int getWildcardLevel() throws IllegalStateException; /** * Returns if this node is a meta node @@ -329,7 +344,8 @@ public interface Node extends Map.Entry { * @return the meta value * @throws IllegalStateException if this node is not a meta node */ - Map.Entry getMeta(); + @Nonnull + Map.Entry getMeta() throws IllegalStateException; /** * Returns if this node is a prefix node @@ -344,7 +360,8 @@ public interface Node extends Map.Entry { * @return the prefix value * @throws IllegalStateException if this node is a not a prefix node */ - Map.Entry getPrefix(); + @Nonnull + Map.Entry getPrefix() throws IllegalStateException; /** * Returns if this node is a suffix node @@ -359,7 +376,8 @@ public interface Node extends Map.Entry { * @return the suffix value * @throws IllegalStateException if this node is a not a suffix node */ - Map.Entry getSuffix(); + @Nonnull + Map.Entry getSuffix() throws IllegalStateException; /** * Checks if this Node is equal to another node @@ -368,6 +386,7 @@ public interface Node extends Map.Entry { * @return true if this node is equal to the other provided * @see #equalsIgnoringValue(Node) for a less strict implementation of this method */ + @Override boolean equals(Object obj); /** @@ -376,7 +395,7 @@ public interface Node extends Map.Entry { * @param other the other node * @return true if the two nodes are almost equal */ - boolean equalsIgnoringValue(Node other); + boolean equalsIgnoringValue(@Nonnull Node other); /** * Similar to {@link Node#equals(Object)}, except doesn't take note of the expiry time or value @@ -384,7 +403,7 @@ public interface Node extends Map.Entry { * @param other the other node * @return true if the two nodes are almost equal */ - boolean almostEquals(Node other); + boolean almostEquals(@Nonnull Node other); /** * Similar to {@link Node#equals(Object)}, except doesn't take note of the value or if the node is temporary @@ -393,38 +412,51 @@ public interface Node extends Map.Entry { * @return true if the two nodes are almost equal * @since 2.8 */ - boolean equalsIgnoringValueOrTemp(Node other); + boolean equalsIgnoringValueOrTemp(@Nonnull Node other); /** * Builds a Node instance */ interface Builder { + + @Nonnull Builder setNegated(boolean negated); + @Nonnull Builder setValue(boolean value); /** * Warning: this value does not persist, and disappears when the holder is re-loaded. * It is therefore only useful for transient nodes. */ + @Nonnull Builder setOverride(boolean override); + @Nonnull Builder setExpiry(long expireAt); - Builder setWorld(String world); + @Nonnull + Builder setWorld(@Nonnull String world); - Builder setServer(String server) throws IllegalArgumentException; + @Nonnull + Builder setServer(@Nonnull String server) throws IllegalArgumentException; - Builder withExtraContext(String key, String value); + @Nonnull + Builder withExtraContext(@Nonnull String key, @Nonnull String value); - Builder withExtraContext(Map map); + @Nonnull + Builder withExtraContext(@Nonnull Map map); - Builder withExtraContext(Set> context); + @Nonnull + Builder withExtraContext(@Nonnull Set> context); - Builder withExtraContext(Map.Entry entry); + @Nonnull + Builder withExtraContext(@Nonnull Map.Entry entry); - Builder withExtraContext(ContextSet set); + @Nonnull + Builder withExtraContext(@Nonnull ContextSet set); + @Nonnull Node build(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/NodeFactory.java b/api/src/main/java/me/lucko/luckperms/api/NodeFactory.java index 7f817a6ef..5c69a5af0 100644 --- a/api/src/main/java/me/lucko/luckperms/api/NodeFactory.java +++ b/api/src/main/java/me/lucko/luckperms/api/NodeFactory.java @@ -25,6 +25,8 @@ package me.lucko.luckperms.api; +import javax.annotation.Nonnull; + /** * Builds {@link Node} instances * @@ -43,7 +45,8 @@ public interface NodeFactory { * @see Node#toSerializedNode() */ @Deprecated - Node fromSerialisedNode(String serialisedPermission, boolean value); + @Nonnull + Node fromSerialisedNode(@Nonnull String serialisedPermission, boolean value); /** @@ -53,7 +56,8 @@ public interface NodeFactory { * @return a node builder instance * @throws NullPointerException if the permission is null */ - Node.Builder newBuilder(String permission); + @Nonnull + Node.Builder newBuilder(@Nonnull String permission); /** * Creates a node builder instance from an existing node @@ -62,7 +66,8 @@ public interface NodeFactory { * @return a node builder instance * @throws NullPointerException if the other node is null */ - Node.Builder newBuilderFromExisting(Node other); + @Nonnull + Node.Builder newBuilderFromExisting(@Nonnull Node other); /** * Creates a node builder from a serialised node string @@ -75,7 +80,8 @@ public interface NodeFactory { * @see Node#toSerializedNode() */ @Deprecated - Node.Builder newBuilderFromSerialisedNode(String serialisedPermission, boolean value); + @Nonnull + Node.Builder newBuilderFromSerialisedNode(@Nonnull String serialisedPermission, boolean value); /** @@ -87,7 +93,8 @@ public interface NodeFactory { * @throws IllegalStateException if the group instance was not obtained from LuckPerms. * @since 3.1 */ - Node.Builder makeGroupNode(Group group); + @Nonnull + Node.Builder makeGroupNode(@Nonnull Group group); /** * Creates a node builder from a key value pair @@ -97,7 +104,8 @@ public interface NodeFactory { * @return a node builder instance * @throws NullPointerException if the key or value is null */ - Node.Builder makeMetaNode(String key, String value); + @Nonnull + Node.Builder makeMetaNode(@Nonnull String key, @Nonnull String value); /** * Creates a node builder for the given chat meta type @@ -108,7 +116,8 @@ public interface NodeFactory { * @throws NullPointerException if the type or value is null * @since 3.2 */ - Node.Builder makeChatMetaNode(ChatMetaType type, int priority, String value); + @Nonnull + Node.Builder makeChatMetaNode(@Nonnull ChatMetaType type, int priority, @Nonnull String value); /** * Creates a node builder from a prefix string and priority @@ -118,7 +127,8 @@ public interface NodeFactory { * @return a node builder instance * @throws NullPointerException if the prefix is null */ - Node.Builder makePrefixNode(int priority, String prefix); + @Nonnull + Node.Builder makePrefixNode(int priority, @Nonnull String prefix); /** * Creates a node builder from a prefix string and priority @@ -128,6 +138,7 @@ public interface NodeFactory { * @return a node builder instance * @throws NullPointerException if the suffix is null */ - Node.Builder makeSuffixNode(int priority, String suffix); + @Nonnull + Node.Builder makeSuffixNode(int priority, @Nonnull 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 e6d266a77..04083bddf 100644 --- a/api/src/main/java/me/lucko/luckperms/api/PermissionHolder.java +++ b/api/src/main/java/me/lucko/luckperms/api/PermissionHolder.java @@ -34,6 +34,9 @@ import java.util.Set; import java.util.SortedSet; import java.util.function.Predicate; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * An object capable of holding permissions * @@ -49,6 +52,7 @@ public interface PermissionHolder { * * @return the identifier for this object. Either a uuid string or name. */ + @Nonnull String getObjectName(); /** @@ -60,6 +64,7 @@ public interface PermissionHolder { * @return a friendly identifier for this holder * @since 3.2 */ + @Nonnull String getFriendlyName(); /** @@ -68,6 +73,7 @@ public interface PermissionHolder { * @return an immutable set of permissions in priority order * @since 2.6 */ + @Nonnull SortedSet getPermissions(); /** @@ -78,6 +84,7 @@ public interface PermissionHolder { * @return a set of nodes * @since 2.6 */ + @Nonnull Set getEnduringPermissions(); /** @@ -88,6 +95,7 @@ public interface PermissionHolder { * @return a set of nodes * @since 2.6 */ + @Nonnull Set getTransientPermissions(); /** @@ -96,6 +104,7 @@ public interface PermissionHolder { * @return a set of permanent nodes * @since 2.6 */ + @Nonnull Set getPermanentPermissionNodes(); /** @@ -104,6 +113,7 @@ public interface PermissionHolder { * @return a set of temporary nodes * @since 2.6 */ + @Nonnull Set getTemporaryPermissionNodes(); /** @@ -119,7 +129,8 @@ public interface PermissionHolder { * @throws NullPointerException if the context is null * @since 2.11 */ - SortedSet getAllNodes(Contexts contexts); + @Nonnull + SortedSet getAllNodes(@Nonnull Contexts contexts); /** * Gets a mutable set of the nodes that this object has and inherits, filtered by context. @@ -132,7 +143,8 @@ public interface PermissionHolder { * @throws NullPointerException if the context is null * @since 2.11 */ - Set getAllNodesFiltered(Contexts contexts); + @Nonnull + Set getAllNodesFiltered(@Nonnull Contexts contexts); /** * Converts the output of {@link #getAllNodesFiltered(Contexts)}, and expands shorthand permissions. @@ -141,7 +153,8 @@ public interface PermissionHolder { * @param lowerCase if the keys should be made lowercase whilst being exported * @return a mutable map of permissions */ - Map exportNodes(Contexts contexts, boolean lowerCase); + @Nonnull + Map exportNodes(@Nonnull Contexts contexts, boolean lowerCase); /** * Removes temporary permissions that have expired @@ -156,7 +169,8 @@ public interface PermissionHolder { * @throws NullPointerException if the node is null * @since 2.6 */ - Tristate hasPermission(Node node); + @Nonnull + Tristate hasPermission(@Nonnull Node node); /** * Checks to see if the object has a certain permission @@ -166,7 +180,8 @@ public interface PermissionHolder { * @throws NullPointerException if the node is null * @since 2.6 */ - Tristate hasTransientPermission(Node node); + @Nonnull + Tristate hasTransientPermission(@Nonnull Node node); /** * Checks to see if the object inherits a certain permission @@ -176,7 +191,8 @@ public interface PermissionHolder { * @throws NullPointerException if the node is null * @since 2.6 */ - Tristate inheritsPermission(Node node); + @Nonnull + Tristate inheritsPermission(@Nonnull Node node); /** * Sets a permission for the object @@ -186,7 +202,7 @@ public interface PermissionHolder { * @throws NullPointerException if the node is null * @since 2.6 */ - void setPermission(Node node) throws ObjectAlreadyHasException; + void setPermission(@Nonnull Node node) throws ObjectAlreadyHasException; /** * Sets a permission for the object @@ -196,7 +212,8 @@ public interface PermissionHolder { * @return the result of the operation * @since 3.1 */ - DataMutateResult setPermissionUnchecked(Node node); + @Nonnull + DataMutateResult setPermissionUnchecked(@Nonnull Node node); /** * Sets a transient permission for the object @@ -215,7 +232,7 @@ public interface PermissionHolder { * @throws NullPointerException if the node is null * @since 2.6 */ - void setTransientPermission(Node node) throws ObjectAlreadyHasException; + void setTransientPermission(@Nonnull Node node) throws ObjectAlreadyHasException; /** * Sets a transient permission for the object @@ -234,7 +251,8 @@ public interface PermissionHolder { * @return the result of the operation * @since 3.1 */ - DataMutateResult setTransientPermissionUnchecked(Node node); + @Nonnull + DataMutateResult setTransientPermissionUnchecked(@Nonnull Node node); /** * Unsets a permission for the object @@ -244,7 +262,7 @@ public interface PermissionHolder { * @throws NullPointerException if the node is null * @since 2.6 */ - void unsetPermission(Node node) throws ObjectLacksException; + void unsetPermission(@Nonnull Node node) throws ObjectLacksException; /** * Unsets a permission for the object @@ -254,7 +272,8 @@ public interface PermissionHolder { * @return the result of the operation * @since 3.1 */ - DataMutateResult unsetPermissionUnchecked(Node node); + @Nonnull + DataMutateResult unsetPermissionUnchecked(@Nonnull Node node); /** * Unsets a transient permission for the object @@ -264,7 +283,7 @@ public interface PermissionHolder { * @throws NullPointerException if the node is null * @since 2.6 */ - void unsetTransientPermission(Node node) throws ObjectLacksException; + void unsetTransientPermission(@Nonnull Node node) throws ObjectLacksException; /** * Unsets a transient permission for the object @@ -274,7 +293,8 @@ public interface PermissionHolder { * @return the result of the operation * @since 3.1 */ - DataMutateResult unsetTransientPermissionUnchecked(Node node); + @Nonnull + DataMutateResult unsetTransientPermissionUnchecked(@Nonnull Node node); /** * Clears any nodes from the holder which pass the predicate @@ -282,7 +302,7 @@ public interface PermissionHolder { * @param test the predicate to test for nodes which should be removed * @since 3.2 */ - void clearMatching(Predicate test); + void clearMatching(@Nonnull Predicate test); /** * Clears any transient nodes from the holder which pass the predicate @@ -290,7 +310,7 @@ public interface PermissionHolder { * @param test the predicate to test for nodes which should be removed * @since 3.2 */ - void clearMatchingTransient(Predicate test); + void clearMatchingTransient(@Nonnull Predicate test); /** * Clears all nodes held by the object @@ -305,7 +325,7 @@ public interface PermissionHolder { * @param contextSet the contexts to filter by * @since 3.2 */ - void clearNodes(ContextSet contextSet); + void clearNodes(@Nonnull ContextSet contextSet); /** * Clears all parent groups @@ -320,7 +340,7 @@ public interface PermissionHolder { * @param contextSet the contexts to filter by * @since 3.2 */ - void clearParents(ContextSet contextSet); + void clearParents(@Nonnull ContextSet contextSet); /** * Clears all meta held by the object @@ -335,7 +355,7 @@ public interface PermissionHolder { * @param contextSet the contexts to filter by * @since 3.2 */ - void clearMeta(ContextSet contextSet); + void clearMeta(@Nonnull ContextSet contextSet); /** * Clears all transient permissions the holder has. @@ -353,7 +373,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #hasPermission(Node)} */ @Deprecated - boolean hasPermission(String node, boolean b); + boolean hasPermission(@Nonnull String node, boolean b); /** * Checks to see the the object has a permission on a certain server @@ -367,7 +387,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #hasPermission(Node)} */ @Deprecated - boolean hasPermission(String node, boolean b, String server); + boolean hasPermission(@Nonnull String node, boolean b, @Nonnull String server); /** * Checks to see the the object has a permission on a certain server and world @@ -382,7 +402,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #hasPermission(Node)} */ @Deprecated - boolean hasPermission(String node, boolean b, String server, String world); + boolean hasPermission(@Nonnull String node, boolean b, @Nonnull String server, @Nonnull String world); /** * Checks to see the the object has a permission @@ -396,7 +416,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #hasPermission(Node)} */ @Deprecated - boolean hasPermission(String node, boolean b, boolean temporary); + boolean hasPermission(@Nonnull String node, boolean b, boolean temporary); /** * Checks to see the the object has a permission on a certain server @@ -411,7 +431,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #hasPermission(Node)} */ @Deprecated - boolean hasPermission(String node, boolean b, String server, boolean temporary); + boolean hasPermission(@Nonnull String node, boolean b, @Nonnull String server, boolean temporary); /** * Checks to see the the object has a permission on a certain server and world @@ -427,7 +447,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #hasPermission(Node)} */ @Deprecated - boolean hasPermission(String node, boolean b, String server, String world, boolean temporary); + boolean hasPermission(@Nonnull String node, boolean b, @Nonnull String server, @Nonnull String world, boolean temporary); /** * Checks to see if the object inherits a certain permission @@ -440,7 +460,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #hasPermission(Node)} */ @Deprecated - boolean inheritsPermission(String node, boolean b); + boolean inheritsPermission(@Nonnull String node, boolean b); /** * Checks to see the the object inherits a permission on a certain server @@ -454,7 +474,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #hasPermission(Node)} */ @Deprecated - boolean inheritsPermission(String node, boolean b, String server); + boolean inheritsPermission(@Nonnull String node, boolean b, @Nonnull String server); /** * Checks to see the the object inherits a permission on a certain server and world @@ -469,7 +489,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #hasPermission(Node)} */ @Deprecated - boolean inheritsPermission(String node, boolean b, String server, String world); + boolean inheritsPermission(@Nonnull String node, boolean b, @Nonnull String server, @Nonnull String world); /** * Checks to see if the object inherits a permission @@ -483,7 +503,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #hasPermission(Node)} */ @Deprecated - boolean inheritsPermission(String node, boolean b, boolean temporary); + boolean inheritsPermission(@Nonnull String node, boolean b, boolean temporary); /** * Checks to see if the object inherits a permission on a certain server @@ -498,7 +518,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #hasPermission(Node)} */ @Deprecated - boolean inheritsPermission(String node, boolean b, String server, boolean temporary); + boolean inheritsPermission(@Nonnull String node, boolean b, @Nonnull String server, boolean temporary); /** * Checks to see if the object inherits a permission on a certain server and world @@ -514,7 +534,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #hasPermission(Node)} */ @Deprecated - boolean inheritsPermission(String node, boolean b, String server, String world, boolean temporary); + boolean inheritsPermission(@Nonnull String node, boolean b, @Nonnull String server, @Nonnull String world, boolean temporary); /** * Sets a permission for the object @@ -527,7 +547,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #setPermission(Node)} */ @Deprecated - void setPermission(String node, boolean value) throws ObjectAlreadyHasException; + void setPermission(@Nonnull String node, boolean value) throws ObjectAlreadyHasException; /** * Sets a permission for the object on a specific server @@ -541,7 +561,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #setPermission(Node)} */ @Deprecated - void setPermission(String node, boolean value, String server) throws ObjectAlreadyHasException; + void setPermission(@Nonnull String node, boolean value, @Nonnull String server) throws ObjectAlreadyHasException; /** * Sets a permission for the object on a specific server and world @@ -556,7 +576,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #setPermission(Node)} */ @Deprecated - void setPermission(String node, boolean value, String server, String world) throws ObjectAlreadyHasException; + void setPermission(@Nonnull String node, boolean value, @Nonnull String server, @Nonnull String world) throws ObjectAlreadyHasException; /** * Sets a temporary permission for the object @@ -570,7 +590,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #setPermission(Node)} */ @Deprecated - void setPermission(String node, boolean value, long expireAt) throws ObjectAlreadyHasException; + void setPermission(@Nonnull String node, boolean value, long expireAt) throws ObjectAlreadyHasException; /** * Sets a temporary permission for the object on a specific server @@ -585,7 +605,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #setPermission(Node)} */ @Deprecated - void setPermission(String node, boolean value, String server, long expireAt) throws ObjectAlreadyHasException; + void setPermission(@Nonnull String node, boolean value, @Nonnull String server, long expireAt) throws ObjectAlreadyHasException; /** * Sets a temporary permission for the object on a specific server and world @@ -601,7 +621,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #setPermission(Node)} */ @Deprecated - void setPermission(String node, boolean value, String server, String world, long expireAt) throws ObjectAlreadyHasException; + void setPermission(String node, boolean value, @Nonnull String server, @Nonnull String world, long expireAt) throws ObjectAlreadyHasException; /** * Unsets a permission for the object @@ -614,7 +634,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #unsetPermission(Node)} */ @Deprecated - void unsetPermission(String node, boolean temporary) throws ObjectLacksException; + void unsetPermission(@Nonnull String node, boolean temporary) throws ObjectLacksException; /** * Unsets a permission for the object @@ -626,7 +646,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #unsetPermission(Node)} */ @Deprecated - void unsetPermission(String node) throws ObjectLacksException; + void unsetPermission(@Nonnull String node) throws ObjectLacksException; /** * Unsets a permission for the object on a specific server @@ -639,7 +659,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #unsetPermission(Node)} */ @Deprecated - void unsetPermission(String node, String server) throws ObjectLacksException; + void unsetPermission(@Nonnull String node, @Nonnull String server) throws ObjectLacksException; /** * Unsets a permission for the object on a specific server and world @@ -653,7 +673,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #unsetPermission(Node)} */ @Deprecated - void unsetPermission(String node, String server, String world) throws ObjectLacksException; + void unsetPermission(@Nonnull String node, @Nonnull String server, @Nonnull String world) throws ObjectLacksException; /** * Unsets a permission for the object on a specific server @@ -667,7 +687,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #unsetPermission(Node)} */ @Deprecated - void unsetPermission(String node, String server, boolean temporary) throws ObjectLacksException; + void unsetPermission(@Nonnull String node, @Nonnull String server, boolean temporary) throws ObjectLacksException; /** * Unsets a permission for the object on a specific server and world @@ -682,7 +702,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #unsetPermission(Node)} */ @Deprecated - void unsetPermission(String node, String server, String world, boolean temporary) throws ObjectLacksException; + void unsetPermission(@Nonnull String node, @Nonnull String server, @Nonnull String world, boolean temporary) throws ObjectLacksException; /** * Clears all nodes held by the object on a specific server @@ -692,7 +712,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #clearNodes(ContextSet)} */ @Deprecated - void clearNodes(String server); + void clearNodes(@Nullable String server); /** * Clears all nodes held by the object on a specific server and world @@ -703,7 +723,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #clearNodes(ContextSet)} */ @Deprecated - void clearNodes(String server, String world); + void clearNodes(@Nullable String server, @Nullable String world); /** * Clears all parents on a specific server @@ -713,7 +733,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #clearParents(ContextSet)} */ @Deprecated - void clearParents(String server); + void clearParents(@Nullable String server); /** * Clears all parents on a specific server and world @@ -724,7 +744,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #clearParents(ContextSet)} */ @Deprecated - void clearParents(String server, String world); + void clearParents(@Nullable String server, @Nullable String world); /** * Clears all meta held by the object on a specific server @@ -734,7 +754,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #clearMeta(ContextSet)} */ @Deprecated - void clearMeta(String server); + void clearMeta(@Nullable String server); /** * Clears all meta held by the object on a specific server and world @@ -745,7 +765,7 @@ public interface PermissionHolder { * @deprecated in favour of {@link #clearMeta(ContextSet)} */ @Deprecated - void clearMeta(String server, String world); + void clearMeta(@Nullable String server, @Nullable String world); /** * Clears all meta for a given key. @@ -757,6 +777,6 @@ public interface PermissionHolder { * @deprecated in favour of {@link #clearMatching(Predicate)} */ @Deprecated - void clearMetaKeys(String key, String server, String world, boolean temporary); + void clearMetaKeys(@Nonnull String key, @Nullable String server, @Nullable String world, boolean temporary); } 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 80af581ff..5d74d08aa 100644 --- a/api/src/main/java/me/lucko/luckperms/api/PlatformType.java +++ b/api/src/main/java/me/lucko/luckperms/api/PlatformType.java @@ -25,6 +25,8 @@ package me.lucko.luckperms.api; +import javax.annotation.Nonnull; + /** * The platforms which LuckPerms can run on * @@ -42,6 +44,7 @@ public enum PlatformType { this.friendlyName = friendlyName; } + @Nonnull public String getFriendlyName() { return friendlyName; } 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 91ee11f2c..1bdb6ff41 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Storage.java +++ b/api/src/main/java/me/lucko/luckperms/api/Storage.java @@ -32,6 +32,9 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.function.Consumer; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * A means of loading and saving data to/from the Storage provider. * @@ -52,6 +55,7 @@ public interface Storage { * * @return the name of the implementation */ + @Nonnull String getName(); /** @@ -66,6 +70,7 @@ public interface Storage { * * @return an executor instance */ + @Nonnull Executor getSyncExecutor(); /** @@ -74,6 +79,7 @@ public interface Storage { * * @return an executor instance */ + @Nonnull Executor getAsyncExecutor(); /** @@ -83,13 +89,15 @@ public interface Storage { * @return true if the operation completed successfully. * @throws NullPointerException if entry is null */ - CompletableFuture logAction(LogEntry entry); + @Nonnull + CompletableFuture logAction(@Nonnull LogEntry entry); /** * Loads and returns the entire log from storage * * @return a log instance, could be null if loading failed */ + @Nonnull CompletableFuture getLog(); /** @@ -100,7 +108,8 @@ public interface Storage { * @return if the operation completed successfully * @throws NullPointerException if uuid is null */ - CompletableFuture loadUser(UUID uuid, String username); + @Nonnull + CompletableFuture loadUser(@Nonnull UUID uuid, @Nullable String username); /** * Loads a user's data from the main storage into the plugins local storage. @@ -109,7 +118,8 @@ public interface Storage { * @return if the operation completed successfully * @throws NullPointerException if uuid is null */ - default CompletableFuture loadUser(UUID uuid) { + @Nonnull + default CompletableFuture loadUser(@Nonnull UUID uuid) { return loadUser(uuid, null); } @@ -121,13 +131,15 @@ public interface Storage { * @throws NullPointerException if user is null * @throws IllegalStateException if the user instance was not obtained from LuckPerms. */ - CompletableFuture saveUser(User user); + @Nonnull + CompletableFuture saveUser(@Nonnull User user); /** * Removes users from the main storage who are "default". This is called every time the plugin loads. * * @return true if the operation completed successfully */ + @Nonnull CompletableFuture cleanupUsers(); /** @@ -136,6 +148,7 @@ public interface Storage { * * @return a set of uuids, or null if the operation failed. */ + @Nonnull CompletableFuture> getUniqueUsers(); /** @@ -146,7 +159,8 @@ public interface Storage { * @throws NullPointerException if the permission is null * @since 2.17 */ - CompletableFuture>> getUsersWithPermission(String permission); + @Nonnull + CompletableFuture>> getUsersWithPermission(@Nonnull String permission); /** * Creates and loads a group into the plugins local storage @@ -156,7 +170,8 @@ public interface Storage { * @throws NullPointerException if name is null * @throws IllegalArgumentException if the name is invalid */ - CompletableFuture createAndLoadGroup(String name); + @Nonnull + CompletableFuture createAndLoadGroup(@Nonnull String name); /** * Loads a group into the plugins local storage. @@ -166,13 +181,15 @@ public interface Storage { * @throws NullPointerException if name is null * @throws IllegalArgumentException if the name is invalid */ - CompletableFuture loadGroup(String name); + @Nonnull + CompletableFuture loadGroup(@Nonnull String name); /** * Loads all groups from the storage into memory * * @return true if the operation completed successfully. */ + @Nonnull CompletableFuture loadAllGroups(); /** @@ -183,7 +200,8 @@ public interface Storage { * @throws NullPointerException if group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ - CompletableFuture saveGroup(Group group); + @Nonnull + CompletableFuture saveGroup(@Nonnull Group group); /** * Permanently deletes a group from storage. @@ -193,7 +211,8 @@ public interface Storage { * @throws NullPointerException if group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ - CompletableFuture deleteGroup(Group group); + @Nonnull + CompletableFuture deleteGroup(@Nonnull Group group); /** * Searches for a list of groups with a given permission. @@ -203,7 +222,8 @@ public interface Storage { * @throws NullPointerException if the permission is null * @since 2.17 */ - CompletableFuture>> getGroupsWithPermission(String permission); + @Nonnull + CompletableFuture>> getGroupsWithPermission(@Nonnull String permission); /** * Creates and loads a track into the plugins local storage @@ -213,7 +233,8 @@ public interface Storage { * @throws NullPointerException if name is null * @throws IllegalArgumentException if the name is invalid */ - CompletableFuture createAndLoadTrack(String name); + @Nonnull + CompletableFuture createAndLoadTrack(@Nonnull String name); /** * Loads a track into the plugins local storage. @@ -223,13 +244,15 @@ public interface Storage { * @throws NullPointerException if name is null * @throws IllegalArgumentException if the name is invalid */ - CompletableFuture loadTrack(String name); + @Nonnull + CompletableFuture loadTrack(@Nonnull String name); /** * Loads all tracks from the storage into memory * * @return true if the operation completed successfully. */ + @Nonnull CompletableFuture loadAllTracks(); /** @@ -240,7 +263,8 @@ public interface Storage { * @throws NullPointerException if track is null * @throws IllegalStateException if the track instance was not obtained from LuckPerms. */ - CompletableFuture saveTrack(Track track); + @Nonnull + CompletableFuture saveTrack(@Nonnull Track track); /** * Permanently deletes a track from storage @@ -250,7 +274,8 @@ public interface Storage { * @throws NullPointerException if track is null * @throws IllegalStateException if the track instance was not obtained from LuckPerms. */ - CompletableFuture deleteTrack(Track track); + @Nonnull + CompletableFuture deleteTrack(@Nonnull Track track); /** * Saves UUID caching data to the global cache @@ -261,7 +286,8 @@ public interface Storage { * @throws NullPointerException if either parameters are null * @throws IllegalArgumentException if the username is invalid */ - CompletableFuture saveUUIDData(String username, UUID uuid); + @Nonnull + CompletableFuture saveUUIDData(@Nonnull String username, @Nonnull UUID uuid); /** * Gets a UUID from a username @@ -271,7 +297,8 @@ public interface Storage { * @throws NullPointerException if either parameters are null * @throws IllegalArgumentException if the username is invalid */ - CompletableFuture getUUID(String username); + @Nonnull + CompletableFuture getUUID(@Nonnull String username); /** * Gets a username from a UUID @@ -281,6 +308,7 @@ public interface Storage { * @throws NullPointerException if either parameters are null * @since 2.17 */ - CompletableFuture getName(UUID uuid); + @Nonnull + CompletableFuture getName(@Nonnull 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 918358212..a6f9ddf6a 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Track.java +++ b/api/src/main/java/me/lucko/luckperms/api/Track.java @@ -30,6 +30,9 @@ import me.lucko.luckperms.exceptions.ObjectLacksException; import java.util.List; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * An ordered collection of groups for easy promotions and demotions */ @@ -39,6 +42,7 @@ public interface Track { * Gets the name of this track * @return the name of this track */ + @Nonnull String getName(); /** @@ -48,6 +52,7 @@ public interface Track { * * @return an ordered {@link List} of the groups on this track */ + @Nonnull List getGroups(); /** @@ -66,7 +71,8 @@ public interface Track { * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ - String getNext(Group current) throws ObjectLacksException; + @Nullable + String getNext(@Nonnull Group current) throws ObjectLacksException; /** * Gets the previous group on the track, before the one provided @@ -77,7 +83,8 @@ public interface Track { * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ - String getPrevious(Group current) throws ObjectLacksException; + @Nullable + String getPrevious(@Nonnull Group current) throws ObjectLacksException; /** * Appends a group to the end of this track @@ -87,7 +94,7 @@ public interface Track { * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ - void appendGroup(Group group) throws ObjectAlreadyHasException; + void appendGroup(@Nonnull Group group) throws ObjectAlreadyHasException; /** * Inserts a group at a certain position on this track @@ -99,7 +106,7 @@ public interface Track { * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ - void insertGroup(Group group, int position) throws ObjectAlreadyHasException, IndexOutOfBoundsException; + void insertGroup(@Nonnull Group group, int position) throws ObjectAlreadyHasException, IndexOutOfBoundsException; /** * Removes a group from this track @@ -109,7 +116,7 @@ public interface Track { * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ - void removeGroup(Group group) throws ObjectLacksException; + void removeGroup(@Nonnull Group group) throws ObjectLacksException; /** * Removes a group from this track @@ -118,7 +125,7 @@ public interface Track { * @throws ObjectLacksException if the group is not on this track * @throws NullPointerException if the group is null */ - void removeGroup(String group) throws ObjectLacksException; + void removeGroup(@Nonnull String group) throws ObjectLacksException; /** * Checks if a group features on this track @@ -128,7 +135,7 @@ public interface Track { * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ - boolean containsGroup(Group group); + boolean containsGroup(@Nonnull Group group); /** * Checks if a group features on this track @@ -137,7 +144,7 @@ public interface Track { * @return true if the group is on this track * @throws NullPointerException if the group is null */ - boolean containsGroup(String group); + boolean containsGroup(@Nonnull String group); /** * Clear all of the groups from this track 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 5fa100b22..587b1c5ef 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Tristate.java +++ b/api/src/main/java/me/lucko/luckperms/api/Tristate.java @@ -25,6 +25,8 @@ package me.lucko.luckperms.api; +import javax.annotation.Nonnull; + /** * Represents a permission setting. * @@ -54,6 +56,7 @@ public enum Tristate { * @param b the boolean * @return {@link #TRUE} or {@link #FALSE}, depending on the value of the boolean. */ + @Nonnull public static Tristate fromBoolean(boolean b) { return b ? TRUE : FALSE; } 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 c61b66cea..d87ba0c20 100644 --- a/api/src/main/java/me/lucko/luckperms/api/User.java +++ b/api/src/main/java/me/lucko/luckperms/api/User.java @@ -34,6 +34,9 @@ import java.util.List; import java.util.Optional; import java.util.UUID; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * A player holding permission data */ @@ -44,6 +47,7 @@ public interface User extends PermissionHolder { * * @return the users Mojang assigned unique id */ + @Nonnull UUID getUuid(); /** @@ -51,16 +55,18 @@ public interface User extends PermissionHolder { * * @return the users username */ + @Nullable String getName(); /** - * Gets the users current primary group. + * Gets the users current primary group. * *

The result of this method depends on which method is configured for primary group calculation. It may not * be the same as any value set through {@link #setPrimaryGroup(String)}.

* * @return the users primary group */ + @Nonnull String getPrimaryGroup(); /** @@ -71,7 +77,7 @@ public interface User extends PermissionHolder { * @throws IllegalStateException if the user is not a member of that group * @throws NullPointerException if the group is null */ - void setPrimaryGroup(String group) throws ObjectAlreadyHasException; + void setPrimaryGroup(@Nonnull String group) throws ObjectAlreadyHasException; /** * Refresh and re-assign the users permissions. @@ -87,6 +93,7 @@ public interface User extends PermissionHolder { * @return the users cached data. * @since 3.2 */ + @Nonnull UserData getCachedData(); /** @@ -97,7 +104,7 @@ public interface User extends PermissionHolder { * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ - boolean isInGroup(Group group); + boolean isInGroup(@Nonnull Group group); /** * Check to see if the user is a direct member of a group in a specific context @@ -108,7 +115,7 @@ public interface User extends PermissionHolder { * @throws IllegalStateException if the group instance was not obtained from LuckPerms. * @since 3.2 */ - boolean isInGroup(Group group, ContextSet contextSet); + boolean isInGroup(@Nonnull Group group, @Nonnull ContextSet contextSet); /** * Gets the user's {@link UserData} cache, if they have one setup. @@ -118,6 +125,7 @@ public interface User extends PermissionHolder { * @deprecated in version 3.2, as this cache is now always loaded */ @Deprecated + @Nonnull Optional getUserDataCache(); /** @@ -140,7 +148,7 @@ public interface User extends PermissionHolder { * @deprecated in favour of {@link #isInGroup(Group, ContextSet)} */ @Deprecated - boolean isInGroup(Group group, String server); + boolean isInGroup(@Nonnull Group group, @Nonnull String server); /** * Check to see if a user is a member of a group on a specific server and world @@ -154,7 +162,7 @@ public interface User extends PermissionHolder { * @deprecated in favour of {@link #isInGroup(Group, ContextSet)} */ @Deprecated - boolean isInGroup(Group group, String server, String world); + boolean isInGroup(@Nonnull Group group, @Nonnull String server, @Nonnull String world); /** * Add a user to a group @@ -166,7 +174,7 @@ public interface User extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void addGroup(Group group) throws ObjectAlreadyHasException; + void addGroup(@Nonnull Group group) throws ObjectAlreadyHasException; /** * Add a user to a group on a specific server @@ -180,7 +188,7 @@ public interface User extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void addGroup(Group group, String server) throws ObjectAlreadyHasException; + void addGroup(@Nonnull Group group, @Nonnull String server) throws ObjectAlreadyHasException; /** * Add a user to a group on a specific server and world @@ -195,7 +203,7 @@ public interface User extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void addGroup(Group group, String server, String world) throws ObjectAlreadyHasException; + void addGroup(@Nonnull Group group, @Nonnull String server, @Nonnull String world) throws ObjectAlreadyHasException; /** * Add a user to a group temporarily on a specific server @@ -209,7 +217,7 @@ public interface User extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void addGroup(Group group, long expireAt) throws ObjectAlreadyHasException; + void addGroup(@Nonnull Group group, long expireAt) throws ObjectAlreadyHasException; /** * Add a user to a group temporarily on a specific server @@ -224,7 +232,7 @@ public interface User extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void addGroup(Group group, String server, long expireAt) throws ObjectAlreadyHasException; + void addGroup(@Nonnull Group group, @Nonnull String server, long expireAt) throws ObjectAlreadyHasException; /** * Add a user to a group temporarily on a specific server and world @@ -240,7 +248,7 @@ public interface User extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void addGroup(Group group, String server, String world, long expireAt) throws ObjectAlreadyHasException; + void addGroup(@Nonnull Group group, @Nonnull String server, @Nonnull String world, long expireAt) throws ObjectAlreadyHasException; /** * Remove the user from a group @@ -252,7 +260,7 @@ public interface User extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void removeGroup(Group group) throws ObjectLacksException; + void removeGroup(@Nonnull Group group) throws ObjectLacksException; /** * Remove the user from a group @@ -265,7 +273,7 @@ public interface User extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void removeGroup(Group group, boolean temporary) throws ObjectLacksException; + void removeGroup(@Nonnull Group group, boolean temporary) throws ObjectLacksException; /** * Remove the user from a group on a specific server @@ -279,7 +287,7 @@ public interface User extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void removeGroup(Group group, String server) throws ObjectLacksException; + void removeGroup(@Nonnull Group group, @Nonnull String server) throws ObjectLacksException; /** * Remove the user from a group on a specific server and world @@ -294,7 +302,7 @@ public interface User extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void removeGroup(Group group, String server, String world) throws ObjectLacksException; + void removeGroup(@Nonnull Group group, @Nonnull String server, @Nonnull String world) throws ObjectLacksException; /** * Remove the user from a group on a specific server @@ -309,7 +317,7 @@ public interface User extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void removeGroup(Group group, String server, boolean temporary) throws ObjectLacksException; + void removeGroup(@Nonnull Group group, @Nonnull String server, boolean temporary) throws ObjectLacksException; /** * Remove the user from a group on a specific server and world @@ -325,7 +333,7 @@ public interface User extends PermissionHolder { * @deprecated in favour of {@link NodeFactory#makeGroupNode(Group)} */ @Deprecated - void removeGroup(Group group, String server, String world, boolean temporary) throws ObjectLacksException; + void removeGroup(@Nonnull Group group, @Nonnull String server, @Nonnull String world, boolean temporary) throws ObjectLacksException; /** * Get a {@link List} of all of the groups the user is a member of, on all servers @@ -334,6 +342,7 @@ public interface User extends PermissionHolder { * @deprecated in favour of just querying a users permissions */ @Deprecated + @Nonnull List getGroupNames(); /** @@ -347,7 +356,8 @@ public interface User extends PermissionHolder { * @deprecated in favour of just querying a users permissions */ @Deprecated - List getLocalGroups(String server, String world); + @Nonnull + List getLocalGroups(@Nonnull String server, @Nonnull String world); /** * Get a {@link List} of the groups the user is a member of on a specific server @@ -359,6 +369,7 @@ public interface User extends PermissionHolder { * @deprecated in favour of just querying a users permissions */ @Deprecated - List getLocalGroups(String server); + @Nonnull + List getLocalGroups(@Nonnull String server); } diff --git a/api/src/main/java/me/lucko/luckperms/api/UuidCache.java b/api/src/main/java/me/lucko/luckperms/api/UuidCache.java index 97f8c450e..d792c517f 100644 --- a/api/src/main/java/me/lucko/luckperms/api/UuidCache.java +++ b/api/src/main/java/me/lucko/luckperms/api/UuidCache.java @@ -27,6 +27,8 @@ package me.lucko.luckperms.api; import java.util.UUID; +import javax.annotation.Nonnull; + /** * A UUID cache for online users, between external Mojang UUIDs, and internal LuckPerms UUIDs. * @@ -48,7 +50,8 @@ public interface UuidCache { * @param external the UUID assigned by the server, through Player#getUniqueId or ProxiedPlayer#getUniqueId * @return the corresponding internal UUID */ - UUID getUUID(UUID external); + @Nonnull + UUID getUUID(@Nonnull UUID external); /** * Gets a users external, server assigned or Mojang assigned unique id, from the internal one used within LuckPerms. @@ -56,6 +59,7 @@ public interface UuidCache { * @param internal the UUID used within LuckPerms, through User#getUuid * @return the corresponding external UUID */ - UUID getExternalUUID(UUID internal); + @Nonnull + UUID getExternalUUID(@Nonnull UUID internal); } diff --git a/api/src/main/java/me/lucko/luckperms/api/caching/MetaContexts.java b/api/src/main/java/me/lucko/luckperms/api/caching/MetaContexts.java index 071fc33ed..baf2f3faf 100644 --- a/api/src/main/java/me/lucko/luckperms/api/caching/MetaContexts.java +++ b/api/src/main/java/me/lucko/luckperms/api/caching/MetaContexts.java @@ -30,6 +30,8 @@ import com.google.common.base.Preconditions; import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.metastacking.MetaStackDefinition; +import javax.annotation.Nonnull; + /** * Represents the context for a meta lookup, consisting of a standard {@link Contexts} element, plus options to define how * the meta stack should be constructed. @@ -46,7 +48,7 @@ public final class MetaContexts { * @param suffixStackDefinition the suffix stack definition to be used * @return the new instance */ - public static MetaContexts of(Contexts contexts, MetaStackDefinition prefixStackDefinition, MetaStackDefinition suffixStackDefinition) { + public static MetaContexts of(@Nonnull Contexts contexts, @Nonnull MetaStackDefinition prefixStackDefinition, @Nonnull MetaStackDefinition suffixStackDefinition) { return new MetaContexts(contexts, prefixStackDefinition, suffixStackDefinition); } @@ -61,25 +63,29 @@ public final class MetaContexts { * @param prefixStackDefinition the prefix stack definition to be used * @param suffixStackDefinition the suffix stack definition to be used */ - public MetaContexts(Contexts contexts, MetaStackDefinition prefixStackDefinition, MetaStackDefinition suffixStackDefinition) { + public MetaContexts(@Nonnull Contexts contexts, @Nonnull MetaStackDefinition prefixStackDefinition, @Nonnull MetaStackDefinition suffixStackDefinition) { this.contexts = Preconditions.checkNotNull(contexts, "contexts"); this.prefixStackDefinition = Preconditions.checkNotNull(prefixStackDefinition, "prefixStackDefinition"); this.suffixStackDefinition = Preconditions.checkNotNull(suffixStackDefinition, "suffixStackDefinition"); } + @Nonnull public Contexts getContexts() { return this.contexts; } + @Nonnull public MetaStackDefinition getPrefixStackDefinition() { return this.prefixStackDefinition; } + @Nonnull public MetaStackDefinition getSuffixStackDefinition() { return this.suffixStackDefinition; } @Override + @Nonnull public String toString() { return "MetaContexts(" + "contexts=" + this.getContexts() + ", " + diff --git a/api/src/main/java/me/lucko/luckperms/api/caching/MetaData.java b/api/src/main/java/me/lucko/luckperms/api/caching/MetaData.java index d31469573..3918e5ef3 100644 --- a/api/src/main/java/me/lucko/luckperms/api/caching/MetaData.java +++ b/api/src/main/java/me/lucko/luckperms/api/caching/MetaData.java @@ -32,6 +32,9 @@ import me.lucko.luckperms.api.metastacking.MetaStackDefinition; import java.util.Map; import java.util.SortedMap; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * Holds cached Meta lookup data for a specific set of contexts * @@ -51,6 +54,7 @@ public interface MetaData { * @return an immutable multimap of meta * @since 3.3 */ + @Nonnull ListMultimap getMetaMultimap(); /** @@ -61,6 +65,7 @@ public interface MetaData { * * @return an immutable map of meta */ + @Nonnull Map getMeta(); /** @@ -69,6 +74,7 @@ public interface MetaData { * * @return a sorted map of prefixes */ + @Nonnull SortedMap getPrefixes(); /** @@ -77,6 +83,7 @@ public interface MetaData { * * @return a sorted map of suffixes */ + @Nonnull SortedMap getSuffixes(); /** @@ -84,6 +91,7 @@ public interface MetaData { * * @return a prefix string, or null */ + @Nullable String getPrefix(); /** @@ -91,6 +99,7 @@ public interface MetaData { * * @return a suffix string, or null */ + @Nullable String getSuffix(); /** @@ -99,6 +108,7 @@ public interface MetaData { * @return the definition used for the prefix stack * @since 3.2 */ + @Nonnull MetaStackDefinition getPrefixStackDefinition(); /** @@ -107,6 +117,7 @@ public interface MetaData { * @return the definition used for the suffix stack * @since 3.2 */ + @Nonnull MetaStackDefinition getSuffixStackDefinition(); } 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 c481dd13d..6ea53e600 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 @@ -29,6 +29,8 @@ import me.lucko.luckperms.api.Tristate; import java.util.Map; +import javax.annotation.Nonnull; + /** * Holds cached Permission lookup data for a specific set of contexts * @@ -43,7 +45,8 @@ public interface PermissionData { * @return a tristate result * @throws NullPointerException if permission is null */ - Tristate getPermissionValue(String permission); + @Nonnull + Tristate getPermissionValue(@Nonnull String permission); /** * Invalidates the underlying permission calculator cache. @@ -57,6 +60,7 @@ public interface PermissionData { * * @return an immutable set of permissions */ + @Nonnull Map getImmutableBacking(); } 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 0e679b308..f8bd7f376 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 @@ -29,6 +29,8 @@ import me.lucko.luckperms.api.Contexts; import java.util.Set; +import javax.annotation.Nonnull; + /** * Holds cached permission and meta lookup data for a {@link me.lucko.luckperms.api.User}. * @@ -52,7 +54,8 @@ public interface UserData { * @return a permission data instance * @throws NullPointerException if contexts is null */ - PermissionData getPermissionData(Contexts contexts); + @Nonnull + PermissionData getPermissionData(@Nonnull Contexts contexts); /** * Gets MetaData from the cache, given a specified context. @@ -64,7 +67,8 @@ public interface UserData { * @throws NullPointerException if contexts is null * @since 3.2 */ - MetaData getMetaData(MetaContexts contexts); + @Nonnull + MetaData getMetaData(@Nonnull MetaContexts contexts); /** * Gets MetaData from the cache, given a specified context. @@ -75,7 +79,8 @@ public interface UserData { * @return a meta data instance * @throws NullPointerException if contexts is null */ - MetaData getMetaData(Contexts contexts); + @Nonnull + MetaData getMetaData(@Nonnull Contexts contexts); /** * Calculates permission data, bypassing the cache. @@ -84,7 +89,8 @@ public interface UserData { * @return a permission data instance * @throws NullPointerException if contexts is null */ - PermissionData calculatePermissions(Contexts contexts); + @Nonnull + PermissionData calculatePermissions(@Nonnull Contexts contexts); /** * Calculates meta data, bypassing the cache. @@ -94,7 +100,8 @@ public interface UserData { * @throws NullPointerException if contexts is null * @since 3.2 */ - MetaData calculateMeta(MetaContexts contexts); + @Nonnull + MetaData calculateMeta(@Nonnull MetaContexts contexts); /** * Calculates meta data, bypassing the cache. @@ -103,7 +110,8 @@ public interface UserData { * @return a meta data instance * @throws NullPointerException if contexts is null */ - MetaData calculateMeta(Contexts contexts); + @Nonnull + MetaData calculateMeta(@Nonnull Contexts contexts); /** * Calculates permission data and stores it in the cache. @@ -114,7 +122,7 @@ public interface UserData { * @param contexts the contexts to recalculate in. * @throws NullPointerException if contexts is null */ - void recalculatePermissions(Contexts contexts); + void recalculatePermissions(@Nonnull Contexts contexts); /** * Calculates meta data and stores it in the cache. @@ -126,7 +134,7 @@ public interface UserData { * @throws NullPointerException if contexts is null * @since 3.2 */ - void recalculateMeta(MetaContexts contexts); + void recalculateMeta(@Nonnull MetaContexts contexts); /** * Calculates meta data and stores it in the cache. @@ -137,7 +145,7 @@ public interface UserData { * @param contexts the contexts to recalculate in. * @throws NullPointerException if contexts is null */ - void recalculateMeta(Contexts contexts); + void recalculateMeta(@Nonnull Contexts contexts); /** * Calls {@link #recalculatePermissions(Contexts)} for all current loaded contexts @@ -155,7 +163,7 @@ public interface UserData { * @param contexts a set of contexts * @throws NullPointerException if contexts is null */ - void preCalculate(Set contexts); + void preCalculate(@Nonnull Set contexts); /** * Ensures that PermissionData and MetaData is cached for a context. @@ -165,7 +173,7 @@ public interface UserData { * @param contexts the contexts to pre-calculate for * @throws NullPointerException if contexts is null */ - void preCalculate(Contexts contexts); + void preCalculate(@Nonnull Contexts contexts); /** * Invalidates all of the underlying Permission calculators. diff --git a/api/src/main/java/me/lucko/luckperms/api/context/ContextCalculator.java b/api/src/main/java/me/lucko/luckperms/api/context/ContextCalculator.java index 38f74ce10..c3c1ceef9 100644 --- a/api/src/main/java/me/lucko/luckperms/api/context/ContextCalculator.java +++ b/api/src/main/java/me/lucko/luckperms/api/context/ContextCalculator.java @@ -25,6 +25,8 @@ package me.lucko.luckperms.api.context; +import javax.annotation.Nonnull; + /** * Calculates whether contexts are applicable to {@link T} * @@ -41,6 +43,7 @@ public interface ContextCalculator { * @return the map * @since 2.13 */ - MutableContextSet giveApplicableContext(T subject, MutableContextSet accumulator); + @Nonnull + MutableContextSet giveApplicableContext(@Nonnull T subject, @Nonnull MutableContextSet accumulator); } diff --git a/api/src/main/java/me/lucko/luckperms/api/context/ContextSet.java b/api/src/main/java/me/lucko/luckperms/api/context/ContextSet.java index 4a832c051..1b8250648 100644 --- a/api/src/main/java/me/lucko/luckperms/api/context/ContextSet.java +++ b/api/src/main/java/me/lucko/luckperms/api/context/ContextSet.java @@ -25,12 +25,15 @@ package me.lucko.luckperms.api.context; +import com.google.common.base.Preconditions; import com.google.common.collect.Multimap; import java.util.Map; import java.util.Optional; import java.util.Set; +import javax.annotation.Nonnull; + /** * Holder of contexts. * @@ -48,7 +51,8 @@ public interface ContextSet { * @return a new ImmutableContextSet containing one KV pair * @throws NullPointerException if key or value is null */ - static ImmutableContextSet singleton(String key, String value) { + @Nonnull + static ImmutableContextSet singleton(@Nonnull String key, @Nonnull String value) { return ImmutableContextSet.singleton(key, value); } @@ -63,7 +67,8 @@ public interface ContextSet { * @throws NullPointerException if any of the keys or values are null * @since 3.1 */ - static ImmutableContextSet of(String key1, String value1, String key2, String value2) { + @Nonnull + static ImmutableContextSet of(@Nonnull String key1, @Nonnull String value1, @Nonnull String key2, @Nonnull String value2) { return ImmutableContextSet.of(key1, value1, key2, value2); } @@ -74,7 +79,8 @@ public interface ContextSet { * @return a new ImmutableContextSet representing the pairs from the map * @throws NullPointerException if the map is null */ - static ImmutableContextSet fromMap(Map map) { + @Nonnull + static ImmutableContextSet fromMap(@Nonnull Map map) { return ImmutableContextSet.fromMap(map); } @@ -85,7 +91,8 @@ public interface ContextSet { * @return a new ImmutableContextSet representing the pairs in the iterable * @throws NullPointerException if the iterable is null */ - static ImmutableContextSet fromEntries(Iterable> iterable) { + @Nonnull + static ImmutableContextSet fromEntries(@Nonnull Iterable> iterable) { return ImmutableContextSet.fromEntries(iterable); } @@ -97,7 +104,8 @@ public interface ContextSet { * @throws NullPointerException if the multimap is null * @since 2.16 */ - static ImmutableContextSet fromMultimap(Multimap multimap) { + @Nonnull + static ImmutableContextSet fromMultimap(@Nonnull Multimap multimap) { return ImmutableContextSet.fromMultimap(multimap); } @@ -109,7 +117,8 @@ public interface ContextSet { * @return a new ImmutableContextSet with the same content and the one provided * @throws NullPointerException if contextSet is null */ - static ImmutableContextSet fromSet(ContextSet contextSet) { + @Nonnull + static ImmutableContextSet fromSet(@Nonnull ContextSet contextSet) { return ImmutableContextSet.fromSet(contextSet); } @@ -118,6 +127,7 @@ public interface ContextSet { * * @return a new ImmutableContextSet */ + @Nonnull static ImmutableContextSet empty() { return ImmutableContextSet.empty(); } @@ -134,6 +144,7 @@ public interface ContextSet { * * @return an immutable ContextSet */ + @Nonnull ImmutableContextSet makeImmutable(); /** @@ -142,6 +153,7 @@ public interface ContextSet { * @return a mutable ContextSet * @since 2.16 */ + @Nonnull MutableContextSet mutableCopy(); /** @@ -149,6 +161,7 @@ public interface ContextSet { * * @return an immutable set */ + @Nonnull Set> toSet(); /** @@ -159,6 +172,7 @@ public interface ContextSet { * * @return an immutable map */ + @Nonnull Map toMap(); /** @@ -167,6 +181,7 @@ public interface ContextSet { * @return a multimap * @since 2.16 */ + @Nonnull Multimap toMultimap(); /** @@ -176,7 +191,7 @@ public interface ContextSet { * @return true if the set contains a value for the key * @throws NullPointerException if the key is null */ - boolean containsKey(String key); + boolean containsKey(@Nonnull String key); /** * Gets a set of all of the values mapped to the given key @@ -185,7 +200,8 @@ public interface ContextSet { * @return a set of values * @throws NullPointerException if the key is null */ - Set getValues(String key); + @Nonnull + Set getValues(@Nonnull String key); /** * Returns any value from this set matching the key, if present. @@ -194,7 +210,8 @@ public interface ContextSet { * @return an optional containing any match * @since 3.1 */ - default Optional getAnyValue(String key) { + @Nonnull + default Optional getAnyValue(@Nonnull String key) { return getValues(key).stream().findAny(); } @@ -206,7 +223,7 @@ public interface ContextSet { * @return true if the set contains the KV pair * @throws NullPointerException if the key or value is null */ - boolean has(String key, String value); + boolean has(@Nonnull String key, @Nonnull String value); /** * Same as {@link #has(String, String)}, except ignores the case of the value. @@ -216,7 +233,7 @@ public interface ContextSet { * @return true if the set contains the KV pair * @throws NullPointerException if the key or value is null */ - boolean hasIgnoreCase(String key, String value); + boolean hasIgnoreCase(@Nonnull String key, @Nonnull String value); /** * Checks to see if all entries in this context set are also included in another set. @@ -225,7 +242,8 @@ public interface ContextSet { * @return true if all entries in this set are also in the other set * @since 3.1 */ - default boolean isSatisfiedBy(ContextSet other) { + default boolean isSatisfiedBy(@Nonnull ContextSet other) { + Preconditions.checkNotNull(other, "other"); if (this.isEmpty()) { // this is empty, so is therefore always satisfied. return true; diff --git a/api/src/main/java/me/lucko/luckperms/api/context/ImmutableContextSet.java b/api/src/main/java/me/lucko/luckperms/api/context/ImmutableContextSet.java index a86aaad1f..2ce13b72b 100644 --- a/api/src/main/java/me/lucko/luckperms/api/context/ImmutableContextSet.java +++ b/api/src/main/java/me/lucko/luckperms/api/context/ImmutableContextSet.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.api.context; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSetMultimap; @@ -35,6 +36,8 @@ import java.util.Collection; import java.util.Map; import java.util.Set; +import javax.annotation.Nonnull; + /** * An immutable implementation of {@link ContextSet}. * @@ -51,14 +54,10 @@ public final class ImmutableContextSet implements ContextSet { * @return a new ImmutableContextSet containing one KV pair * @throws NullPointerException if key or value is null */ - public static ImmutableContextSet singleton(String key, String value) { - if (key == null) { - throw new NullPointerException("key"); - } - if (value == null) { - throw new NullPointerException("value"); - } - + @Nonnull + public static ImmutableContextSet singleton(@Nonnull String key, @Nonnull String value) { + Preconditions.checkNotNull(key, "key"); + Preconditions.checkNotNull(value, "value"); return new ImmutableContextSet(ImmutableSetMultimap.of(key.toLowerCase(), value)); } @@ -73,20 +72,12 @@ public final class ImmutableContextSet implements ContextSet { * @throws NullPointerException if any of the keys or values are null * @since 3.1 */ - public static ImmutableContextSet of(String key1, String value1, String key2, String value2) { - if (key1 == null) { - throw new NullPointerException("key1"); - } - if (value1 == null) { - throw new NullPointerException("value1"); - } - if (key2 == null) { - throw new NullPointerException("key2"); - } - if (value2 == null) { - throw new NullPointerException("value2"); - } - + @Nonnull + public static ImmutableContextSet of(@Nonnull String key1, @Nonnull String value1, @Nonnull String key2, @Nonnull String value2) { + Preconditions.checkNotNull(key1, "key1"); + Preconditions.checkNotNull(value1, "value1"); + Preconditions.checkNotNull(key2, "key2"); + Preconditions.checkNotNull(value2, "value2"); return new ImmutableContextSet(ImmutableSetMultimap.of(key1.toLowerCase(), value1, key2.toLowerCase(), value2)); } @@ -97,10 +88,9 @@ public final class ImmutableContextSet implements ContextSet { * @return a new ImmutableContextSet representing the pairs from the map * @throws NullPointerException if the map is null */ - public static ImmutableContextSet fromMap(Map map) { - if (map == null) { - throw new NullPointerException("map"); - } + @Nonnull + public static ImmutableContextSet fromMap(@Nonnull Map map) { + Preconditions.checkNotNull(map, "map"); ImmutableSetMultimap.Builder b = ImmutableSetMultimap.builder(); for (Map.Entry e : map.entrySet()) { @@ -117,11 +107,9 @@ public final class ImmutableContextSet implements ContextSet { * @return a new ImmutableContextSet representing the pairs in the iterable * @throws NullPointerException if the iterable is null */ - public static ImmutableContextSet fromEntries(Iterable> iterable) { - if (iterable == null) { - throw new NullPointerException("iterable"); - } - + @Nonnull + public static ImmutableContextSet fromEntries(@Nonnull Iterable> iterable) { + Preconditions.checkNotNull(iterable, "iterable"); return MutableContextSet.fromEntries(iterable).makeImmutable(); } @@ -132,11 +120,9 @@ public final class ImmutableContextSet implements ContextSet { * @return a new ImmutableContextSet representing the pairs in the multimap * @throws NullPointerException if the multimap is null */ - public static ImmutableContextSet fromMultimap(Multimap multimap) { - if (multimap == null) { - throw new NullPointerException("multimap"); - } - + @Nonnull + public static ImmutableContextSet fromMultimap(@Nonnull Multimap multimap) { + Preconditions.checkNotNull(multimap, "multimap"); return MutableContextSet.fromMultimap(multimap).makeImmutable(); } @@ -148,8 +134,9 @@ public final class ImmutableContextSet implements ContextSet { * @return a new ImmutableContextSet with the same content and the one provided * @throws NullPointerException if contextSet is null */ - public static ImmutableContextSet fromSet(ContextSet contextSet) { - return contextSet.makeImmutable(); + @Nonnull + public static ImmutableContextSet fromSet(@Nonnull ContextSet contextSet) { + return Preconditions.checkNotNull(contextSet, "contextSet").makeImmutable(); } /** @@ -157,6 +144,7 @@ public final class ImmutableContextSet implements ContextSet { * * @return a new ContextSet */ + @Nonnull public static ImmutableContextSet empty() { return EMPTY; } @@ -174,21 +162,25 @@ public final class ImmutableContextSet implements ContextSet { @Override @Deprecated // This set is already immutable! + @Nonnull public ImmutableContextSet makeImmutable() { return this; } @Override + @Nonnull public MutableContextSet mutableCopy() { return MutableContextSet.fromSet(this); } @Override + @Nonnull public Set> toSet() { return ImmutableSet.copyOf(map.entries()); } @Override + @Nonnull public Map toMap() { ImmutableMap.Builder m = ImmutableMap.builder(); for (Map.Entry e : map.entries()) { @@ -199,49 +191,35 @@ public final class ImmutableContextSet implements ContextSet { } @Override + @Nonnull public Multimap toMultimap() { return map; } @Override - public boolean containsKey(String key) { - if (key == null) { - throw new NullPointerException("key"); - } - + public boolean containsKey(@Nonnull String key) { + Preconditions.checkNotNull(key, "key"); return map.containsKey(key); } @Override - public Set getValues(String key) { - if (key == null) { - throw new NullPointerException("key"); - } - + public Set getValues(@Nonnull String key) { + Preconditions.checkNotNull(key, "key"); Collection c = map.get(key); return c != null && !c.isEmpty() ? ImmutableSet.copyOf(c) : ImmutableSet.of(); } @Override - public boolean has(String key, String value) { - if (key == null) { - throw new NullPointerException("key"); - } - if (value == null) { - throw new NullPointerException("value"); - } - + public boolean has(@Nonnull String key, @Nonnull String value) { + Preconditions.checkNotNull(key, "key"); + Preconditions.checkNotNull(value, "value"); return map.containsEntry(key, value); } @Override - public boolean hasIgnoreCase(String key, String value) { - if (key == null) { - throw new NullPointerException("key"); - } - if (value == null) { - throw new NullPointerException("value"); - } + public boolean hasIgnoreCase(@Nonnull String key, @Nonnull String value) { + Preconditions.checkNotNull(key, "key"); + Preconditions.checkNotNull(value, "value"); Collection c = map.get(key); if (c == null || c.isEmpty()) { @@ -274,7 +252,7 @@ public final class ImmutableContextSet implements ContextSet { final Multimap thisContexts = this.toMultimap(); final Multimap otherContexts = other.toMultimap(); - return thisContexts == null ? otherContexts == null : thisContexts.equals(otherContexts); + return thisContexts.equals(otherContexts); } @Override diff --git a/api/src/main/java/me/lucko/luckperms/api/context/MutableContextSet.java b/api/src/main/java/me/lucko/luckperms/api/context/MutableContextSet.java index 4f9e7044e..544f56bfb 100644 --- a/api/src/main/java/me/lucko/luckperms/api/context/MutableContextSet.java +++ b/api/src/main/java/me/lucko/luckperms/api/context/MutableContextSet.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.api.context; +import com.google.common.base.Preconditions; import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -37,6 +38,8 @@ import java.util.Collection; import java.util.Map; import java.util.Set; +import javax.annotation.Nonnull; + /** * A mutable implementation of {@link ContextSet}. * @@ -52,14 +55,10 @@ public final class MutableContextSet implements ContextSet { * @return a new MutableContextSet containing one KV pair * @throws NullPointerException if key or value is null */ - public static MutableContextSet singleton(String key, String value) { - if (key == null) { - throw new NullPointerException("key"); - } - if (value == null) { - throw new NullPointerException("value"); - } - + @Nonnull + public static MutableContextSet singleton(@Nonnull String key, @Nonnull String value) { + Preconditions.checkNotNull(key, "key"); + Preconditions.checkNotNull(value, "value"); MutableContextSet set = new MutableContextSet(); set.add(key, value); return set; @@ -76,20 +75,12 @@ public final class MutableContextSet implements ContextSet { * @throws NullPointerException if any of the keys or values are null * @since 3.1 */ - public static MutableContextSet of(String key1, String value1, String key2, String value2) { - if (key1 == null) { - throw new NullPointerException("key1"); - } - if (value1 == null) { - throw new NullPointerException("value1"); - } - if (key2 == null) { - throw new NullPointerException("key2"); - } - if (value2 == null) { - throw new NullPointerException("value2"); - } - + @Nonnull + public static MutableContextSet of(@Nonnull String key1, @Nonnull String value1, @Nonnull String key2, @Nonnull String value2) { + Preconditions.checkNotNull(key1, "key1"); + Preconditions.checkNotNull(value1, "value1"); + Preconditions.checkNotNull(key2, "key2"); + Preconditions.checkNotNull(value2, "value2"); MutableContextSet ret = singleton(key1, value1); ret.add(key2, value2); return ret; @@ -102,11 +93,9 @@ public final class MutableContextSet implements ContextSet { * @return a new MutableContextSet representing the pairs from the map * @throws NullPointerException if the map is null */ - public static MutableContextSet fromMap(Map map) { - if (map == null) { - throw new NullPointerException("map"); - } - + @Nonnull + public static MutableContextSet fromMap(@Nonnull Map map) { + Preconditions.checkNotNull(map, "map"); MutableContextSet set = new MutableContextSet(); set.addAll(map); return set; @@ -119,11 +108,9 @@ public final class MutableContextSet implements ContextSet { * @return a new MutableContextSet representing the pairs in the iterable * @throws NullPointerException if the iterable is null */ - public static MutableContextSet fromEntries(Iterable> iterable) { - if (iterable == null) { - throw new NullPointerException("iterable"); - } - + @Nonnull + public static MutableContextSet fromEntries(@Nonnull Iterable> iterable) { + Preconditions.checkNotNull(iterable, "iterable"); MutableContextSet set = new MutableContextSet(); set.addAll(iterable); return set; @@ -136,11 +123,9 @@ public final class MutableContextSet implements ContextSet { * @return a new MutableContextSet representing the pairs in the multimap * @throws NullPointerException if the multimap is null */ - public static MutableContextSet fromMultimap(Multimap multimap) { - if (multimap == null) { - throw new NullPointerException("multimap"); - } - + @Nonnull + public static MutableContextSet fromMultimap(@Nonnull Multimap multimap) { + Preconditions.checkNotNull(multimap, "multimap"); return fromEntries(multimap.entries()); } @@ -152,11 +137,9 @@ public final class MutableContextSet implements ContextSet { * @return a new MutableContextSet with the same content and the one provided * @throws NullPointerException if contextSet is null */ - public static MutableContextSet fromSet(ContextSet contextSet) { - if (contextSet == null) { - throw new NullPointerException("contextSet"); - } - + @Nonnull + public static MutableContextSet fromSet(@Nonnull ContextSet contextSet) { + Preconditions.checkNotNull(contextSet, "contextSet"); MutableContextSet set = new MutableContextSet(); set.addAll(contextSet.toSet()); return set; @@ -167,6 +150,7 @@ public final class MutableContextSet implements ContextSet { * * @return a new MutableContextSet */ + @Nonnull public static MutableContextSet create() { return new MutableContextSet(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/data/DatastoreConfiguration.java b/api/src/main/java/me/lucko/luckperms/api/data/DatastoreConfiguration.java index 7a86bb787..72a1c6206 100644 --- a/api/src/main/java/me/lucko/luckperms/api/data/DatastoreConfiguration.java +++ b/api/src/main/java/me/lucko/luckperms/api/data/DatastoreConfiguration.java @@ -25,18 +25,24 @@ package me.lucko.luckperms.api.data; +import javax.annotation.Nullable; + /** * Represents the data section of the main LuckPerms configuration. * All methods could return null. */ public interface DatastoreConfiguration { + @Nullable String getAddress(); + @Nullable String getDatabase(); + @Nullable String getUsername(); + @Nullable String getPassword(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/Cancellable.java b/api/src/main/java/me/lucko/luckperms/api/event/Cancellable.java index 201aeb97e..4df77003a 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/Cancellable.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/Cancellable.java @@ -27,6 +27,8 @@ package me.lucko.luckperms.api.event; import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.Nonnull; + /** * Represents an event that can be cancelled */ @@ -37,6 +39,7 @@ public interface Cancellable { * * @return the cancellation */ + @Nonnull AtomicBoolean getCancellationState(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/EventBus.java b/api/src/main/java/me/lucko/luckperms/api/event/EventBus.java index 8cbc9b9bc..5345113f4 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/EventBus.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/EventBus.java @@ -28,6 +28,8 @@ package me.lucko.luckperms.api.event; import java.util.Set; import java.util.function.Consumer; +import javax.annotation.Nonnull; + /** * The LuckPerms event bus. Used for subscribing (or registering listeners) to events. * @@ -43,7 +45,8 @@ public interface EventBus { * @param the event class * @return an event handler instance representing this subscription */ - EventHandler subscribe(Class eventClass, Consumer handler); + @Nonnull + EventHandler subscribe(@Nonnull Class eventClass, @Nonnull Consumer handler); /** * Gets a set of all registered handlers for a given event @@ -52,6 +55,7 @@ public interface EventBus { * @param the event class * @return an immutable set of event handlers */ - Set> getHandlers(Class eventClass); + @Nonnull + Set> getHandlers(@Nonnull Class eventClass); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/EventHandler.java b/api/src/main/java/me/lucko/luckperms/api/event/EventHandler.java index 216eec1bb..f20857be9 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/EventHandler.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/EventHandler.java @@ -27,6 +27,8 @@ package me.lucko.luckperms.api.event; import java.util.function.Consumer; +import javax.annotation.Nonnull; + /** * Represents a handler for a LuckPerms event * @@ -39,6 +41,7 @@ public interface EventHandler { * * @return the event class */ + @Nonnull Class getEventClass(); /** @@ -60,6 +63,7 @@ public interface EventHandler { * * @return the event consumer */ + @Nonnull Consumer getConsumer(); /** diff --git a/api/src/main/java/me/lucko/luckperms/api/event/LuckPermsEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/LuckPermsEvent.java index a1a598464..56050c5e8 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/LuckPermsEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/LuckPermsEvent.java @@ -27,6 +27,8 @@ package me.lucko.luckperms.api.event; import me.lucko.luckperms.api.LuckPermsApi; +import javax.annotation.Nonnull; + /** * The base event interface * @@ -39,6 +41,7 @@ public interface LuckPermsEvent { * * @return the api instance */ + @Nonnull LuckPermsApi getApi(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/group/GroupCreateEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/group/GroupCreateEvent.java index 3bcaac1ae..01a8c86fe 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/group/GroupCreateEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/group/GroupCreateEvent.java @@ -29,6 +29,8 @@ import me.lucko.luckperms.api.Group; import me.lucko.luckperms.api.event.LuckPermsEvent; import me.lucko.luckperms.api.event.cause.CreationCause; +import javax.annotation.Nonnull; + /** * Called when a group is created */ @@ -39,6 +41,7 @@ public interface GroupCreateEvent extends LuckPermsEvent { * * @return the new group */ + @Nonnull Group getGroup(); /** @@ -46,6 +49,7 @@ public interface GroupCreateEvent extends LuckPermsEvent { * * @return the cause of the creation */ + @Nonnull CreationCause getCause(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/group/GroupDeleteEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/group/GroupDeleteEvent.java index 175d16108..48fe48576 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/group/GroupDeleteEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/group/GroupDeleteEvent.java @@ -31,6 +31,8 @@ import me.lucko.luckperms.api.event.cause.DeletionCause; import java.util.Set; +import javax.annotation.Nonnull; + /** * Called when a group is deleted */ @@ -41,6 +43,7 @@ public interface GroupDeleteEvent extends LuckPermsEvent { * * @return the name of the deleted group */ + @Nonnull String getGroupName(); /** @@ -48,6 +51,7 @@ public interface GroupDeleteEvent extends LuckPermsEvent { * * @return a copy of the groups existing data */ + @Nonnull Set getExistingData(); /** @@ -55,6 +59,7 @@ public interface GroupDeleteEvent extends LuckPermsEvent { * * @return the cause of the deletion */ + @Nonnull DeletionCause getCause(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/group/GroupLoadEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/group/GroupLoadEvent.java index 9df112a9e..eb414f6e4 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/group/GroupLoadEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/group/GroupLoadEvent.java @@ -28,6 +28,8 @@ package me.lucko.luckperms.api.event.group; import me.lucko.luckperms.api.Group; import me.lucko.luckperms.api.event.LuckPermsEvent; +import javax.annotation.Nonnull; + /** * Called when a group is loaded into memory from the storage. * @@ -40,6 +42,7 @@ public interface GroupLoadEvent extends LuckPermsEvent { * * @return the group that was loaded */ + @Nonnull Group getGroup(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/log/LogBroadcastEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/log/LogBroadcastEvent.java index 96e95d8c2..8d676d4ad 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/log/LogBroadcastEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/log/LogBroadcastEvent.java @@ -29,6 +29,8 @@ import me.lucko.luckperms.api.LogEntry; import me.lucko.luckperms.api.event.Cancellable; import me.lucko.luckperms.api.event.LuckPermsEvent; +import javax.annotation.Nonnull; + /** * Called when a log entry is about to be sent to notifiable players on the platform */ @@ -39,6 +41,7 @@ public interface LogBroadcastEvent extends LuckPermsEvent, Cancellable { * * @return the log entry to be broadcasted */ + @Nonnull LogEntry getEntry(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/log/LogPublishEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/log/LogPublishEvent.java index 546dcec92..15c2a990e 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/log/LogPublishEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/log/LogPublishEvent.java @@ -29,6 +29,8 @@ import me.lucko.luckperms.api.LogEntry; import me.lucko.luckperms.api.event.Cancellable; import me.lucko.luckperms.api.event.LuckPermsEvent; +import javax.annotation.Nonnull; + /** * Called when a log is about to be published to the storage file/table */ @@ -39,6 +41,7 @@ public interface LogPublishEvent extends LuckPermsEvent, Cancellable { * * @return the log entry to be published */ + @Nonnull LogEntry getEntry(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/node/NodeAddEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/node/NodeAddEvent.java index d0467f14e..5944c5f93 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/node/NodeAddEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/node/NodeAddEvent.java @@ -27,6 +27,8 @@ package me.lucko.luckperms.api.event.node; import me.lucko.luckperms.api.Node; +import javax.annotation.Nonnull; + /** * Called when a node is added to a holder */ @@ -37,6 +39,7 @@ public interface NodeAddEvent extends NodeMutateEvent { * * @return the node that was added */ + @Nonnull Node getNode(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/node/NodeMutateEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/node/NodeMutateEvent.java index 7927bb215..293147456 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/node/NodeMutateEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/node/NodeMutateEvent.java @@ -31,6 +31,8 @@ import me.lucko.luckperms.api.event.LuckPermsEvent; import java.util.Set; +import javax.annotation.Nonnull; + /** * Called when a node is added to/removed from a user/group */ @@ -41,6 +43,7 @@ public interface NodeMutateEvent extends LuckPermsEvent { * * @return the event target */ + @Nonnull PermissionHolder getTarget(); /** @@ -48,6 +51,7 @@ public interface NodeMutateEvent extends LuckPermsEvent { * * @return the data before the change */ + @Nonnull Set getDataBefore(); /** @@ -55,6 +59,7 @@ public interface NodeMutateEvent extends LuckPermsEvent { * * @return the data after the change */ + @Nonnull Set getDataAfter(); /** diff --git a/api/src/main/java/me/lucko/luckperms/api/event/node/NodeRemoveEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/node/NodeRemoveEvent.java index 053d6b7ae..8e2becbfa 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/node/NodeRemoveEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/node/NodeRemoveEvent.java @@ -27,6 +27,8 @@ package me.lucko.luckperms.api.event.node; import me.lucko.luckperms.api.Node; +import javax.annotation.Nonnull; + /** * Called when a node is removed from a holder */ @@ -37,6 +39,7 @@ public interface NodeRemoveEvent extends NodeMutateEvent { * * @return the node that was removed */ + @Nonnull Node getNode(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/sync/PreNetworkSyncEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/sync/PreNetworkSyncEvent.java index 7a209dda5..fec70ac0b 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/sync/PreNetworkSyncEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/sync/PreNetworkSyncEvent.java @@ -30,6 +30,8 @@ import me.lucko.luckperms.api.event.LuckPermsEvent; import java.util.UUID; +import javax.annotation.Nonnull; + /** * Called before a network sync task runs */ @@ -40,6 +42,7 @@ public interface PreNetworkSyncEvent extends LuckPermsEvent, Cancellable { * * @return the id of the sync request */ + @Nonnull UUID getSyncId(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/track/TrackCreateEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/track/TrackCreateEvent.java index f7ee4cc9e..816b7ac20 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/track/TrackCreateEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/track/TrackCreateEvent.java @@ -29,6 +29,8 @@ import me.lucko.luckperms.api.Track; import me.lucko.luckperms.api.event.LuckPermsEvent; import me.lucko.luckperms.api.event.cause.CreationCause; +import javax.annotation.Nonnull; + /** * Called when a track is created */ @@ -39,6 +41,7 @@ public interface TrackCreateEvent extends LuckPermsEvent { * * @return the new track */ + @Nonnull Track getTrack(); /** @@ -46,6 +49,7 @@ public interface TrackCreateEvent extends LuckPermsEvent { * * @return the cause of the creation */ + @Nonnull CreationCause getCause(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/track/TrackDeleteEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/track/TrackDeleteEvent.java index ae6cd97ec..3d753d59f 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/track/TrackDeleteEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/track/TrackDeleteEvent.java @@ -30,6 +30,8 @@ import me.lucko.luckperms.api.event.cause.DeletionCause; import java.util.List; +import javax.annotation.Nonnull; + /** * Called when a track is deleted */ @@ -40,6 +42,7 @@ public interface TrackDeleteEvent extends LuckPermsEvent { * * @return the name of the deleted track */ + @Nonnull String getTrackName(); /** @@ -47,6 +50,7 @@ public interface TrackDeleteEvent extends LuckPermsEvent { * * @return a copy of the tracks existing data */ + @Nonnull List getExistingData(); /** @@ -54,6 +58,7 @@ public interface TrackDeleteEvent extends LuckPermsEvent { * * @return the cause of the deletion */ + @Nonnull DeletionCause getCause(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/track/TrackLoadEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/track/TrackLoadEvent.java index 92f5255ed..b53271bd7 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/track/TrackLoadEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/track/TrackLoadEvent.java @@ -28,6 +28,8 @@ package me.lucko.luckperms.api.event.track; import me.lucko.luckperms.api.Track; import me.lucko.luckperms.api.event.LuckPermsEvent; +import javax.annotation.Nonnull; + /** * Called when a track is loaded into memory from the storage. * @@ -40,6 +42,7 @@ public interface TrackLoadEvent extends LuckPermsEvent { * * @return the track that was loaded */ + @Nonnull Track getTrack(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/track/mutate/TrackAddGroupEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/track/mutate/TrackAddGroupEvent.java index 35e8eda9a..76a3294f5 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/track/mutate/TrackAddGroupEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/track/mutate/TrackAddGroupEvent.java @@ -25,6 +25,8 @@ package me.lucko.luckperms.api.event.track.mutate; +import javax.annotation.Nonnull; + /** * Called when a group is added to a track */ @@ -35,6 +37,7 @@ public interface TrackAddGroupEvent extends TrackMutateEvent { * * @return the group that was added */ + @Nonnull String getGroup(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/track/mutate/TrackMutateEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/track/mutate/TrackMutateEvent.java index 999386fb4..d9fad7491 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/track/mutate/TrackMutateEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/track/mutate/TrackMutateEvent.java @@ -30,6 +30,8 @@ import me.lucko.luckperms.api.event.LuckPermsEvent; import java.util.List; +import javax.annotation.Nonnull; + /** * Called when a track is changed */ @@ -40,6 +42,7 @@ public interface TrackMutateEvent extends LuckPermsEvent { * * @return the track that was mutated */ + @Nonnull Track getTrack(); /** @@ -47,6 +50,7 @@ public interface TrackMutateEvent extends LuckPermsEvent { * * @return the data before the change */ + @Nonnull List getDataBefore(); /** @@ -54,6 +58,7 @@ public interface TrackMutateEvent extends LuckPermsEvent { * * @return the data after the change */ + @Nonnull List getDataAfter(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/track/mutate/TrackRemoveGroupEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/track/mutate/TrackRemoveGroupEvent.java index 3bec4cfd0..f582cbd8f 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/track/mutate/TrackRemoveGroupEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/track/mutate/TrackRemoveGroupEvent.java @@ -25,6 +25,8 @@ package me.lucko.luckperms.api.event.track.mutate; +import javax.annotation.Nonnull; + /** * Called when a group is removed from a track */ @@ -35,6 +37,7 @@ public interface TrackRemoveGroupEvent extends TrackMutateEvent { * * @return the group that was removed */ + @Nonnull String getGroup(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/user/UserCacheLoadEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/user/UserCacheLoadEvent.java index 87d22d34b..d0e311040 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/user/UserCacheLoadEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/user/UserCacheLoadEvent.java @@ -29,6 +29,8 @@ import me.lucko.luckperms.api.User; import me.lucko.luckperms.api.caching.UserData; import me.lucko.luckperms.api.event.LuckPermsEvent; +import javax.annotation.Nonnull; + /** * Called when a users {@link me.lucko.luckperms.api.caching.UserData} is loaded. */ @@ -39,6 +41,7 @@ public interface UserCacheLoadEvent extends LuckPermsEvent { * * @return the user */ + @Nonnull User getUser(); /** @@ -46,6 +49,7 @@ public interface UserCacheLoadEvent extends LuckPermsEvent { * * @return the loaded data */ + @Nonnull UserData getLoadedData(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/user/UserDataRecalculateEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/user/UserDataRecalculateEvent.java index 0a594c132..354fd6d89 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/user/UserDataRecalculateEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/user/UserDataRecalculateEvent.java @@ -29,6 +29,8 @@ import me.lucko.luckperms.api.User; import me.lucko.luckperms.api.caching.UserData; import me.lucko.luckperms.api.event.LuckPermsEvent; +import javax.annotation.Nonnull; + /** * Called when a users cached data is refreshed */ @@ -39,6 +41,7 @@ public interface UserDataRecalculateEvent extends LuckPermsEvent { * * @return the user */ + @Nonnull User getUser(); /** @@ -46,6 +49,7 @@ public interface UserDataRecalculateEvent extends LuckPermsEvent { * * @return the data */ + @Nonnull UserData getData(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/user/UserFirstLoginEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/user/UserFirstLoginEvent.java index de195a2c4..0807e9d25 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/user/UserFirstLoginEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/user/UserFirstLoginEvent.java @@ -29,6 +29,8 @@ import me.lucko.luckperms.api.event.LuckPermsEvent; import java.util.UUID; +import javax.annotation.Nonnull; + /** * Called when the user logs into the network for the first time. * @@ -47,6 +49,7 @@ public interface UserFirstLoginEvent extends LuckPermsEvent { * * @return the uuid of the user */ + @Nonnull UUID getUuid(); /** @@ -54,6 +57,7 @@ public interface UserFirstLoginEvent extends LuckPermsEvent { * * @return the username of the user */ + @Nonnull String getUsername(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/user/UserLoadEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/user/UserLoadEvent.java index f64ad0af4..847fc7138 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/user/UserLoadEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/user/UserLoadEvent.java @@ -28,6 +28,8 @@ package me.lucko.luckperms.api.event.user; import me.lucko.luckperms.api.User; import me.lucko.luckperms.api.event.LuckPermsEvent; +import javax.annotation.Nonnull; + /** * Called when a user is loaded into memory from the storage. */ @@ -38,6 +40,7 @@ public interface UserLoadEvent extends LuckPermsEvent { * * @return the user that was loaded */ + @Nonnull User getUser(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/user/track/UserTrackEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/user/track/UserTrackEvent.java index e60083192..690f08db8 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/user/track/UserTrackEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/user/track/UserTrackEvent.java @@ -31,6 +31,8 @@ import me.lucko.luckperms.api.event.LuckPermsEvent; import java.util.Optional; +import javax.annotation.Nonnull; + /** * Called when a user interacts with a track through a promotion or demotion */ @@ -41,6 +43,7 @@ public interface UserTrackEvent extends LuckPermsEvent { * * @return the track involved in the event */ + @Nonnull Track getTrack(); /** @@ -48,6 +51,7 @@ public interface UserTrackEvent extends LuckPermsEvent { * * @return the user involved in the event */ + @Nonnull User getUser(); /** @@ -55,6 +59,7 @@ public interface UserTrackEvent extends LuckPermsEvent { * * @return the action performed */ + @Nonnull TrackAction getAction(); /** @@ -64,6 +69,7 @@ public interface UserTrackEvent extends LuckPermsEvent { * * @return the group the user was promoted/demoted from */ + @Nonnull Optional getGroupFrom(); /** @@ -71,6 +77,7 @@ public interface UserTrackEvent extends LuckPermsEvent { * * @return the group the user was promoted/demoted to */ + @Nonnull Optional getGroupTo(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackDefinition.java b/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackDefinition.java index a60b8244d..5baea00f1 100644 --- a/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackDefinition.java +++ b/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackDefinition.java @@ -27,6 +27,8 @@ package me.lucko.luckperms.api.metastacking; import java.util.List; +import javax.annotation.Nonnull; + /** * Represents a meta stack model, consisting of a chain of elements, separated by spacers. * @@ -45,6 +47,7 @@ public interface MetaStackDefinition { * * @return the elements in this stack */ + @Nonnull List getElements(); /** @@ -52,6 +55,7 @@ public interface MetaStackDefinition { * * @return the start spacer */ + @Nonnull String getStartSpacer(); /** @@ -59,6 +63,7 @@ public interface MetaStackDefinition { * * @return the middle spacer */ + @Nonnull String getMiddleSpacer(); /** @@ -66,6 +71,7 @@ public interface MetaStackDefinition { * * @return the end spacer */ + @Nonnull String getEndSpacer(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackElement.java b/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackElement.java index a54e919ed..048b4a611 100644 --- a/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackElement.java +++ b/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackElement.java @@ -31,6 +31,9 @@ import me.lucko.luckperms.api.Node; import java.util.Map; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * Represents an element within a {@link MetaStackDefinition}. * @@ -48,6 +51,6 @@ public interface MetaStackElement { * @param current the current value being used. If this returns true, the current value will be replaced by this entry * @return true if the node should be accumulated into this element, replacing the current value */ - boolean shouldAccumulate(LocalizedNode node, ChatMetaType type, Map.Entry current); + boolean shouldAccumulate(@Nonnull LocalizedNode node, @Nonnull ChatMetaType type, @Nullable Map.Entry current); } diff --git a/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackFactory.java b/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackFactory.java index 253689722..0eccae0d3 100644 --- a/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackFactory.java +++ b/api/src/main/java/me/lucko/luckperms/api/metastacking/MetaStackFactory.java @@ -28,6 +28,8 @@ package me.lucko.luckperms.api.metastacking; import java.util.List; import java.util.Optional; +import javax.annotation.Nonnull; + /** * Factory to create meta stack elements and definitions. * @@ -41,7 +43,8 @@ public interface MetaStackFactory { * @param definition the definition * @return the parsed element, if present */ - Optional fromString(String definition); + @Nonnull + Optional fromString(@Nonnull String definition); /** * Parses a list of {@link MetaStackElement}s from string, using the pre-defined elements in the plugin. @@ -51,7 +54,8 @@ public interface MetaStackFactory { * @param definitions the definition strings * @return a list of parsed elements */ - List fromStrings(List definitions); + @Nonnull + List fromStrings(@Nonnull List definitions); /** * Creates a new {@link MetaStackDefinition} with the given properties. @@ -62,6 +66,7 @@ public interface MetaStackFactory { * @param endSpacer the spacer to be included at the end of the stacks output * @return the new stack definition instance */ - MetaStackDefinition createDefinition(List elements, String startSpacer, String middleSpacer, String endSpacer); + @Nonnull + MetaStackDefinition createDefinition(@Nonnull List elements, @Nonnull String startSpacer, @Nonnull String middleSpacer, @Nonnull String endSpacer); } 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 ea2186745..1854c1636 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 @@ -217,18 +217,18 @@ public class ApiProvider implements LuckPermsApi { @SuppressWarnings("unchecked") @Override - public void registerContextCalculator(ContextCalculator contextCalculator) { + public void registerContextCalculator(@NonNull ContextCalculator contextCalculator) { plugin.getContextManager().registerCalculator(contextCalculator); } @Override - public Optional getContextForUser(User user) { + public Optional getContextForUser(@NonNull User user) { return Optional.ofNullable(plugin.getContextForUser(UserDelegate.cast(user))); } @SuppressWarnings("unchecked") @Override - public ContextSet getContextForPlayer(Object player) { + public ContextSet getContextForPlayer(@NonNull Object player) { return plugin.getContextManager().getApplicableContext(player); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/SenderLogger.java b/common/src/main/java/me/lucko/luckperms/common/utils/SenderLogger.java index 46ca90a34..2aa4a213f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/SenderLogger.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/SenderLogger.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.utils; import lombok.AllArgsConstructor; +import lombok.NonNull; import me.lucko.luckperms.api.Logger; import me.lucko.luckperms.common.commands.sender.Sender; @@ -36,17 +37,17 @@ public class SenderLogger implements Logger { private final Sender console; @Override - public void info(String s) { + public void info(@NonNull String s) { Message.LOG_INFO.send(console, s); } @Override - public void warn(String s) { + public void warn(@NonNull String s) { Message.LOG_WARN.send(console, s); } @Override - public void severe(String s) { + public void severe(@NonNull String s) { Message.LOG_ERROR.send(console, s); } }