diff --git a/api/pom.xml b/api/pom.xml index 061c52529..12f6c336a 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -1,11 +1,11 @@ - luckperms me.lucko.luckperms - 2.15-SNAPSHOT + 2.16-SNAPSHOT 4.0.0 diff --git a/api/src/main/java/me/lucko/luckperms/LuckPerms.java b/api/src/main/java/me/lucko/luckperms/LuckPerms.java index 9745bad05..75080202c 100644 --- a/api/src/main/java/me/lucko/luckperms/LuckPerms.java +++ b/api/src/main/java/me/lucko/luckperms/LuckPerms.java @@ -34,6 +34,7 @@ public final class LuckPerms { /** * Gets an instance of {@link LuckPermsApi} + * * @return an api instance * @throws IllegalStateException if the api is not loaded */ @@ -47,6 +48,7 @@ public final class LuckPerms { /** * Gets an instance of {@link LuckPermsApi} safely. Unlike {@link LuckPerms#getApi}, this method will not throw an * {@link IllegalStateException} if the api is not loaded, rather return an empty {@link Optional}. + * * @return an optional api instance */ public static Optional getApiSafe() { 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 a38723c00..5638ec840 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Contexts.java +++ b/api/src/main/java/me/lucko/luckperms/api/Contexts.java @@ -29,15 +29,17 @@ import java.util.Map; /** * Represents the context and options for a permission lookup. * All values are immutable. + * * @since 2.11 */ public class Contexts { - private static final Contexts ALLOW_ALL = new Contexts(ContextSet.empty(), true, true, true, true, true, true); public static final String SERVER_KEY = "server"; public static final String WORLD_KEY = "world"; + private static final Contexts ALLOW_ALL = new Contexts(ContextSet.empty(), true, true, true, true, true, true); /** * Gets a context that will allow all nodes + * * @return a context that will not apply any filters */ public static Contexts allowAll() { @@ -48,6 +50,50 @@ public class Contexts { return new Contexts(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups, op); } + @SuppressWarnings("deprecation") + @Deprecated + public static Contexts of(Map context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups) { + return new Contexts(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups); + } + + @SuppressWarnings("deprecation") + @Deprecated + public static Contexts of(Map context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) { + return new Contexts(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups, op); + } + + /** + * The contexts that apply for this lookup + * The keys for servers and worlds are defined as static values. + */ + private final ContextSet context; + /** + * The mode to parse defaults on Bukkit + * + * @since 2.12 + */ + private final boolean op; + /** + * If global or non server specific nodes should be applied + */ + private final boolean includeGlobal; + /** + * If global or non world specific nodes should be applied + */ + private final boolean includeGlobalWorld; + /** + * If parent groups should be applied + */ + private final boolean applyGroups; + /** + * If global or non server specific group memberships should be applied + */ + private final boolean applyGlobalGroups; + /** + * If global or non world specific group memberships should be applied + */ + private final boolean applyGlobalWorldGroups; + public Contexts(ContextSet context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) { if (context == null) { throw new NullPointerException("context"); @@ -62,18 +108,6 @@ public class Contexts { this.op = op; } - @SuppressWarnings("deprecation") - @Deprecated - public static Contexts of(Map context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups) { - return new Contexts(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups); - } - - @SuppressWarnings("deprecation") - @Deprecated - public static Contexts of(Map context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) { - return new Contexts(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups, op); - } - @Deprecated public Contexts(Map context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) { this(context == null ? null : ContextSet.fromMap(context), includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups, op); @@ -85,45 +119,9 @@ public class Contexts { this(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups, false); } - /** - * The contexts that apply for this lookup - * The keys for servers and worlds are defined as static values. - */ - private final ContextSet context; - - /** - * The mode to parse defaults on Bukkit - * @since 2.12 - */ - private final boolean op; - - /** - * If global or non server specific nodes should be applied - */ - private final boolean includeGlobal; - - /** - * If global or non world specific nodes should be applied - */ - private final boolean includeGlobalWorld; - - /** - * If parent groups should be applied - */ - private final boolean applyGroups; - - /** - * If global or non server specific group memberships should be applied - */ - private final boolean applyGlobalGroups; - - /** - * If global or non world specific group memberships should be applied - */ - private final boolean applyGlobalWorldGroups; - /** * Gets the contexts that apply for this lookup + * * @return an immutable set of context key value pairs * @since 2.13 */ @@ -133,6 +131,7 @@ public class Contexts { /** * Gets the contexts that apply for this lookup + * * @return an immutable map of context key value pairs * @deprecated in favour of {@link #getContexts()} */ @@ -143,6 +142,7 @@ public class Contexts { /** * Gets if OP defaults should be included + * * @return true if op defaults should be included */ public boolean isOp() { @@ -151,6 +151,7 @@ public class Contexts { /** * Gets if global or non server specific nodes should be applied + * * @return true if global or non server specific nodes should be applied */ public boolean isIncludeGlobal() { @@ -159,6 +160,7 @@ public class Contexts { /** * Gets if global or non world specific nodes should be applied + * * @return true if global or non world specific nodes should be applied */ public boolean isIncludeGlobalWorld() { @@ -167,6 +169,7 @@ public class Contexts { /** * Gets if parent groups should be applied + * * @return true if parent groups should be applied */ public boolean isApplyGroups() { @@ -175,6 +178,7 @@ public class Contexts { /** * Gets if global or non server specific group memberships should be applied + * * @return true if global or non server specific group memberships should be applied */ public boolean isApplyGlobalGroups() { @@ -183,6 +187,7 @@ public class Contexts { /** * Gets if global or non world specific group memberships should be applied + * * @return true if global or non world specific group memberships should be applied */ public boolean isApplyGlobalWorldGroups() { @@ -207,6 +212,7 @@ public class Contexts { /** * Check for equality + * * @param o the other * @return true if equal * @since 2.12 @@ -229,6 +235,7 @@ public class Contexts { /** * Gets the hashcode + * * @return the hashcode * @since 2.12 */ diff --git a/api/src/main/java/me/lucko/luckperms/api/Datastore.java b/api/src/main/java/me/lucko/luckperms/api/Datastore.java index bed075443..2d10880c6 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Datastore.java +++ b/api/src/main/java/me/lucko/luckperms/api/Datastore.java @@ -29,12 +29,14 @@ import java.util.UUID; /** * Interface for the internal Datastore instance + * * @deprecated as of version 2.14 in favour of {@link Storage}. */ @Deprecated public interface Datastore { String getName(); + boolean isAcceptingLogins(); @Deprecated @@ -49,78 +51,135 @@ public interface Datastore { @Deprecated interface Sync { boolean logAction(LogEntry entry); + Log getLog(); + @Deprecated boolean loadOrCreateUser(UUID uuid, String username); + @Deprecated boolean loadUser(UUID uuid); + boolean loadUser(UUID uuid, String username); + boolean saveUser(User user); + boolean cleanupUsers(); + Set getUniqueUsers(); + boolean createAndLoadGroup(String name); + boolean loadGroup(String name); + boolean loadAllGroups(); + boolean saveGroup(Group group); + boolean deleteGroup(Group group); + boolean createAndLoadTrack(String name); + boolean loadTrack(String name); + boolean loadAllTracks(); + boolean saveTrack(Track track); + boolean deleteTrack(Track track); + boolean saveUUIDData(String username, UUID uuid); + UUID getUUID(String username); } @Deprecated interface Async { void logAction(LogEntry entry, Callback callback); + void getLog(Callback callback); + @Deprecated void loadOrCreateUser(UUID uuid, String username, Callback callback); + @Deprecated void loadUser(UUID uuid, Callback callback); + void loadUser(UUID uuid, String username, Callback callback); + void saveUser(User user, Callback callback); + void cleanupUsers(Callback callback); + void getUniqueUsers(Callback> callback); + void createAndLoadGroup(String name, Callback callback); + void loadGroup(String name, Callback callback); + void loadAllGroups(Callback callback); + void saveGroup(Group group, Callback callback); + void deleteGroup(Group group, Callback callback); + void createAndLoadTrack(String name, Callback callback); + void loadTrack(String name, Callback callback); + void loadAllTracks(Callback callback); + void saveTrack(Track track, Callback callback); + void deleteTrack(Track track, Callback callback); + void saveUUIDData(String username, UUID uuid, Callback callback); + void getUUID(String username, Callback callback); } @Deprecated interface Future { java.util.concurrent.Future logAction(LogEntry entry); + java.util.concurrent.Future getLog(); + @Deprecated java.util.concurrent.Future loadOrCreateUser(UUID uuid, String username); + @Deprecated java.util.concurrent.Future loadUser(UUID uuid); + java.util.concurrent.Future loadUser(UUID uuid, String username); + java.util.concurrent.Future saveUser(User user); + java.util.concurrent.Future cleanupUsers(); + java.util.concurrent.Future> getUniqueUsers(); + java.util.concurrent.Future createAndLoadGroup(String name); + java.util.concurrent.Future loadGroup(String name); + java.util.concurrent.Future loadAllGroups(); + java.util.concurrent.Future saveGroup(Group group); + java.util.concurrent.Future deleteGroup(Group group); + java.util.concurrent.Future createAndLoadTrack(String name); + java.util.concurrent.Future loadTrack(String name); + java.util.concurrent.Future loadAllTracks(); + java.util.concurrent.Future saveTrack(Track track); + java.util.concurrent.Future deleteTrack(Track track); + java.util.concurrent.Future saveUUIDData(String username, UUID uuid); + java.util.concurrent.Future getUUID(String username); } } 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 9b65199a0..f1d27a70f 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Group.java +++ b/api/src/main/java/me/lucko/luckperms/api/Group.java @@ -40,167 +40,182 @@ public interface Group extends PermissionHolder { /** * Check to see if a group inherits a group + * * @param group The group to check membership of * @return true if the group inherits the other group - * @throws NullPointerException if the group is null + * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ boolean inheritsGroup(Group group); /** * Check to see if the group inherits a group on a specific server - * @param group The group to check membership of + * + * @param group The group to check membership of * @param server The server to check on * @return true if the group inherits the group on the server - * @throws NullPointerException if the group or server is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws NullPointerException if the group or server is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. * @throws IllegalArgumentException if the server is invalid */ boolean inheritsGroup(Group group, String server); /** * Check to see if the group inherits a group on a specific server and world - * @param group The group to check membership of + * + * @param group The group to check membership of * @param server The server to check on - * @param world The world to check on + * @param world The world to check on * @return true if the group inherits the group on the server and world - * @throws NullPointerException if the group, server or world is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws NullPointerException if the group, server or world is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. * @throws IllegalArgumentException if the server or world is invalid */ boolean inheritsGroup(Group group, String server, String world); /** * Make this group inherit another group + * * @param group the group to be inherited * @throws ObjectAlreadyHasException if the group already inherits the group - * @throws NullPointerException if the group is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws NullPointerException if the group is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ void setInheritGroup(Group group) throws ObjectAlreadyHasException; /** * Make this group inherit another group on a specific server - * @param group the group to be inherited + * + * @param group the group to be inherited * @param server The server to inherit the group on * @throws ObjectAlreadyHasException if the group already inherits the group on that server - * @throws NullPointerException if the group or server is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. - * @throws IllegalArgumentException if the server is invalid + * @throws NullPointerException if the group or server is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws IllegalArgumentException if the server is invalid */ void setInheritGroup(Group group, String server) throws ObjectAlreadyHasException; /** * Make this group inherit another group on a specific server and world - * @param group the group to be inherited + * + * @param group the group to be inherited * @param server The server to inherit the group on - * @param world The world to inherit the group on + * @param world The world to inherit the group on * @throws ObjectAlreadyHasException if the group already inherits the group on that server and world - * @throws NullPointerException if the group, server or world is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. - * @throws IllegalArgumentException if the server or world is invalid + * @throws NullPointerException if the group, server or world is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws IllegalArgumentException if the server or world is invalid */ void setInheritGroup(Group group, String server, String world) throws ObjectAlreadyHasException; /** * Make this group inherit another group temporarily - * @param group the group to be inherited + * + * @param group the group to be inherited * @param expireAt the unix time when the group should expire * @throws ObjectAlreadyHasException if the group already inherits the group temporarily - * @throws NullPointerException if the group is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. - * @throws IllegalArgumentException if the expiry time is in the past + * @throws NullPointerException if the group is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws IllegalArgumentException if the expiry time is in the past */ void setInheritGroup(Group group, long expireAt) throws ObjectAlreadyHasException; /** * Make this group inherit another group on a specific server temporarily - * @param group the group to be inherited - * @param server The server inherit add the group on + * + * @param group the group to be inherited + * @param server The server inherit add the group on * @param expireAt when the group should expire * @throws ObjectAlreadyHasException if the group already inherits the group on that server temporarily - * @throws NullPointerException if the group or server is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. - * @throws IllegalArgumentException if the expiry time is in the past or the server is invalid + * @throws NullPointerException if the group or server is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws IllegalArgumentException if the expiry time is in the past or the server is invalid */ void setInheritGroup(Group group, String server, long expireAt) throws ObjectAlreadyHasException; /** * Make this group inherit another group on a specific server and world temporarily - * @param group the group to be inherited - * @param server The server to inherit the group on - * @param world The world to inherit the group on + * + * @param group the group to be inherited + * @param server The server to inherit the group on + * @param world The world to inherit the group on * @param expireAt when the group should expire * @throws ObjectAlreadyHasException if the group already inherits the group on that server and world temporarily - * @throws NullPointerException if the group, server or world is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. - * @throws IllegalArgumentException if the expiry time is in the past or the server/world is invalid + * @throws NullPointerException if the group, server or world is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws IllegalArgumentException if the expiry time is in the past or the server/world is invalid */ void setInheritGroup(Group group, String server, String world, long expireAt) throws ObjectAlreadyHasException; /** * Remove a previously set inheritance rule + * * @param group the group to uninherit - * @throws ObjectLacksException if the group does not already inherit the group - * @throws NullPointerException if the group is null + * @throws ObjectLacksException if the group does not already inherit the group + * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ void unsetInheritGroup(Group group) throws ObjectLacksException; /** * Remove a previously set inheritance rule - * @param group the group to uninherit + * + * @param group the group to uninherit * @param temporary if the group being removed is temporary - * @throws ObjectLacksException if the group does not already inherit the group - * @throws NullPointerException if the group is null + * @throws ObjectLacksException if the group does not already inherit the group + * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ void unsetInheritGroup(Group group, boolean temporary) throws ObjectLacksException; /** * Remove a previously set inheritance rule on a specific server - * @param group the group to uninherit + * + * @param group the group to uninherit * @param server The server to remove the group on - * @throws ObjectLacksException if the group does not already inherit the group on that server - * @throws NullPointerException if the group or server is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws ObjectLacksException if the group does not already inherit the group on that server + * @throws NullPointerException if the group or server is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. * @throws IllegalArgumentException if the server is invalid */ void unsetInheritGroup(Group group, String server) throws ObjectLacksException; /** * Remove a previously set inheritance rule on a specific server and world - * @param group the group to uninherit + * + * @param group the group to uninherit * @param server The server to remove the group on - * @param world The world to remove the group on - * @throws ObjectLacksException if the group does not already inherit the group - * @throws NullPointerException if the group, server or world is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @param world The world to remove the group on + * @throws ObjectLacksException if the group does not already inherit the group + * @throws NullPointerException if the group, server or world is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. * @throws IllegalArgumentException if the server or world is invalid */ void unsetInheritGroup(Group group, String server, String world) throws ObjectLacksException; /** * Remove a previously set inheritance rule on a specific server - * @param group the group to uninherit - * @param server The server to remove the group on + * + * @param group the group to uninherit + * @param server The server to remove the group on * @param temporary if the group being removed is temporary - * @throws ObjectLacksException if the group does not already inherit the group - * @throws NullPointerException if the group or server is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws ObjectLacksException if the group does not already inherit the group + * @throws NullPointerException if the group or server is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. * @throws IllegalArgumentException if the expiry time is in the past or the server is invalid */ void unsetInheritGroup(Group group, String server, boolean temporary) throws ObjectLacksException; /** * Remove a previously set inheritance rule on a specific server and world - * @param group the group to uninherit - * @param server The server to remove the group on - * @param world The world to remove the group on + * + * @param group the group to uninherit + * @param server The server to remove the group on + * @param world The world to remove the group on * @param temporary if the group being removed was set temporarily - * @throws ObjectLacksException if the group does not already inherit the group - * @throws NullPointerException if the group, server or world is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws ObjectLacksException if the group does not already inherit the group + * @throws NullPointerException if the group, server or world is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. * @throws IllegalArgumentException if the expiry time is in the past or the server/world is invalid */ void unsetInheritGroup(Group group, String server, String world, boolean temporary) throws ObjectLacksException; @@ -212,25 +227,28 @@ public interface Group extends PermissionHolder { /** * Get a {@link List} of all of the groups the group inherits, on all servers + * * @return a {@link List} of group names */ List getGroupNames(); /** * Get a {@link List} of the groups the group inherits on a specific server + * * @param server the server to check - * @param world the world to check + * @param world the world to check * @return a {@link List} of group names - * @throws NullPointerException if the server or world is null + * @throws NullPointerException if the server or world is null * @throws IllegalArgumentException if the server or world is invalid */ List getLocalGroups(String server, String world); /** * Get a {@link List} of the groups the group inherits on a specific server + * * @param server the server to check * @return a {@link List} of group names - * @throws NullPointerException if the server is null + * @throws NullPointerException if the server is null * @throws IllegalArgumentException if the server is invalid */ List getLocalGroups(String server); 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 74737019e..84f5d5f80 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LPConfiguration.java +++ b/api/src/main/java/me/lucko/luckperms/api/LPConfiguration.java @@ -169,8 +169,8 @@ public interface LPConfiguration { boolean getSplitStorage(); /** - * @return a map of split storage options, where the key is the storage section, and the value is the storage method. - * For example: key = user, value = json + * @return a map of split storage options, where the key is the storage section, and the value is the storage + * method. For example: key = user, value = json * @since 2.7 */ 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 ac38982be..ada9fbdfa 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LocalizedNode.java +++ b/api/src/main/java/me/lucko/luckperms/api/LocalizedNode.java @@ -24,18 +24,21 @@ package me.lucko.luckperms.api; /** * Represents a Node and where it was inherited from. + * * @since 2.11 */ public interface LocalizedNode extends Node { /** * Gets the node + * * @return the node this instance is representing */ Node getNode(); /** * Gets the location where the {@link Node} is inherited from + * * @return where the node was inherited from. Will not return null. * @see PermissionHolder#getObjectName() */ 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 346048e04..fd8086cf3 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Log.java +++ b/api/src/main/java/me/lucko/luckperms/api/Log.java @@ -27,8 +27,8 @@ import java.util.SortedSet; import java.util.UUID; /** - * Represents the internal LuckPerms log. - * All content internally is immutable. You can add to the log using the {@link Datastore}, and then request an updated copy. + * Represents the internal LuckPerms log. All content internally is immutable. You can add to the log using the {@link + * Datastore}, and then request an updated copy. */ @SuppressWarnings("unused") public interface Log { @@ -45,6 +45,7 @@ public interface Log { /** * Gets the recent content separated by page + * * @param pageNo the page number * @return the page content */ @@ -64,8 +65,9 @@ public interface Log { /** * Gets the recent content for the uuid, separated into pages + * * @param pageNo the page number - * @param actor the uuid of the actor to filter by + * @param actor the uuid of the actor to filter by * @return the page content */ SortedMap getRecent(int pageNo, UUID actor); @@ -85,8 +87,9 @@ public interface Log { /** * Gets the user history content, separated by pages + * * @param pageNo the page number - * @param uuid the uuid of the acted user to filter by + * @param uuid the uuid of the acted user to filter by * @return the page content */ SortedMap getUserHistory(int pageNo, UUID uuid); @@ -97,7 +100,7 @@ public interface Log { */ int getUserHistoryMaxPages(UUID uuid); - + /** * @param name the name to filter by * @return all content in this log where the group = name @@ -106,8 +109,9 @@ public interface Log { /** * Gets the group history content, separated by pages + * * @param pageNo the page number - * @param name the name of the acted group to filter by + * @param name the name of the acted group to filter by * @return the page content */ SortedMap getGroupHistory(int pageNo, String name); @@ -127,8 +131,9 @@ public interface Log { /** * Gets the track history content, separated by pages + * * @param pageNo the page number - * @param name the name of the acted track to filter by + * @param name the name of the acted track to filter by * @return the page content */ SortedMap getTrackHistory(int pageNo, String name); @@ -147,8 +152,9 @@ public interface Log { /** * Gets the search content, separated by pages + * * @param pageNo the page number - * @param query the query to filter by + * @param query the query to filter by * @return the page content */ SortedMap getSearch(int pageNo, String query); diff --git a/api/src/main/java/me/lucko/luckperms/api/LogEntry.java b/api/src/main/java/me/lucko/luckperms/api/LogEntry.java index f8c857c42..2e35e1aaf 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LogEntry.java +++ b/api/src/main/java/me/lucko/luckperms/api/LogEntry.java @@ -29,12 +29,12 @@ import java.util.UUID; */ @SuppressWarnings({"unused", "WeakerAccess"}) public class LogEntry implements Comparable { + private static final String FORMAT = "&8(&e%s&8) [&a%s&8] (&b%s&8) &7--> &f%s"; + public static LogEntryBuilder builder() { return new LogEntryBuilder(); } - private static final String FORMAT = "&8(&e%s&8) [&a%s&8] (&b%s&8) &7--> &f%s"; - private long timestamp; private UUID actor; private String actorName; @@ -100,54 +100,54 @@ public class LogEntry implements Comparable { return timestamp; } - public UUID getActor() { - return actor; - } - - public String getActorName() { - return actorName; - } - - public char getType() { - return type; - } - - public UUID getActed() { - return acted; - } - - public String getActedName() { - return actedName; - } - - public String getAction() { - return action; - } - void setTimestamp(long timestamp) { this.timestamp = timestamp; } + public UUID getActor() { + return actor; + } + void setActor(UUID actor) { this.actor = actor; } + public String getActorName() { + return actorName; + } + void setActorName(String actorName) { this.actorName = actorName; } + public char getType() { + return type; + } + void setType(char type) { this.type = type; } + public UUID getActed() { + return acted; + } + void setActed(UUID acted) { this.acted = acted; } + public String getActedName() { + return actedName; + } + void setActedName(String actedName) { this.actedName = actedName; } + public String getAction() { + return action; + } + void setAction(String action) { this.action = action; } @@ -226,6 +226,7 @@ public class LogEntry implements Comparable { } protected abstract T createObj(); + protected abstract B getThis(); public long getTimestamp() { 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 bf74eb9b2..16289269d 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Logger.java +++ b/api/src/main/java/me/lucko/luckperms/api/Logger.java @@ -25,13 +25,15 @@ package me.lucko.luckperms.api; /** * A wrapper interface for platform logger instances. * - *

Bukkit/Bungee both use java.util.logging, and Sponge uses org.slf4j. This class wraps those classes so the commons - * module can access a logger. + *

Bukkit/Bungee both use java.util.logging, and Sponge uses org.slf4j. This class wraps those classes so the + * commons module can access a logger. */ public interface Logger { void info(String s); + void warn(String s); + void severe(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 068a60c7e..75b435d03 100644 --- a/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java +++ b/api/src/main/java/me/lucko/luckperms/api/LuckPermsApi.java @@ -60,6 +60,7 @@ public interface LuckPermsApi { /** * Registers a listener to be sent LuckPerms events + * * @param listener the listener instance * @throws NullPointerException if the listener is null */ @@ -67,6 +68,7 @@ public interface LuckPermsApi { /** * Unregisters a previously registered listener from the EventBus + * * @param listener the listener instance to unregister * @throws NullPointerException if the listener is null */ @@ -74,12 +76,14 @@ public interface LuckPermsApi { /** * Gets a wrapped {@link LPConfiguration} instance, with read only access + * * @return a configuration instance */ LPConfiguration getConfiguration(); /** * Gets a wrapped {@link Storage} instance. + * * @return a storage instance * @since 2.14 */ @@ -87,6 +91,7 @@ public interface LuckPermsApi { /** * Gets a wrapped Datastore instance. + * * @return a datastore instance * @deprecated in favour of {@link #getStorage()} */ @@ -96,24 +101,28 @@ public interface LuckPermsApi { /** * Gets the messaging service in use on the platform, if present. + * * @return an optional that may contain a messaging service instance. */ Optional getMessagingService(); /** * Gets the {@link Logger} wrapping used by the platform + * * @return the logger instance */ Logger getLogger(); /** * Gets a wrapped {@link UuidCache} instance, providing read access to the LuckPerms internal uuid caching system + * * @return a uuid cache instance */ UuidCache getUuidCache(); /** * Gets a wrapped user object from the user storage + * * @param uuid the uuid of the user to get * @return a {@link User} object, if one matching the uuid is loaded, or null if not * @throws NullPointerException if the uuid is null @@ -122,6 +131,7 @@ public interface LuckPermsApi { /** * Gets a wrapped user object from the user storage. This method does not return null, unlike {@link #getUser(UUID)} + * * @param uuid the uuid of the user to get * @return an optional {@link User} object * @throws NullPointerException if the uuid is null @@ -130,6 +140,7 @@ public interface LuckPermsApi { /** * Gets a wrapped user object from the user storage + * * @param name the username of the user to get * @return a {@link User} object, if one matching the uuid is loaded, or null if not * @throws NullPointerException if the name is null @@ -137,7 +148,9 @@ public interface LuckPermsApi { User getUser(String name); /** - * Gets a wrapped user object from the user storage. This method does not return null, unlike {@link #getUser(String)} + * Gets a wrapped user object from the user storage. This method does not return null, unlike {@link + * #getUser(String)} + * * @param name the username of the user to get * @return an optional {@link User} object * @throws NullPointerException if the name is null @@ -146,12 +159,14 @@ public interface LuckPermsApi { /** * Gets a set of all loaded users. + * * @return a {@link Set} of {@link User} objects */ Set getUsers(); /** * Check if a user is loaded in memory + * * @param uuid the uuid to check for * @return true if the user is loaded * @throws NullPointerException if the uuid is null @@ -160,6 +175,7 @@ public interface LuckPermsApi { /** * Unload a user from the internal storage, if they're not currently online. + * * @param user the user to unload * @throws NullPointerException if the user is null * @since 2.6 @@ -168,6 +184,7 @@ public interface LuckPermsApi { /** * Gets a wrapped group object from the group storage + * * @param name the name of the group to get * @return a {@link Group} object, if one matching the name exists, or null if not * @throws NullPointerException if the name is null @@ -176,6 +193,7 @@ public interface LuckPermsApi { /** * Gets a wrapped group object from the group storage. This method does not return null, unlike {@link #getGroup} + * * @param name the name of the group to get * @return an optional {@link Group} object * @throws NullPointerException if the name is null @@ -184,12 +202,14 @@ public interface LuckPermsApi { /** * Gets a set of all loaded groups. + * * @return a {@link Set} of {@link Group} objects */ Set getGroups(); /** * Check if a group is loaded in memory + * * @param name the name to check for * @return true if the group is loaded * @throws NullPointerException if the name is null @@ -198,6 +218,7 @@ public interface LuckPermsApi { /** * Gets a wrapped track object from the track storage + * * @param name the name of the track to get * @return a {@link Track} object, if one matching the name exists, or null if not * @throws NullPointerException if the name is null @@ -206,6 +227,7 @@ public interface LuckPermsApi { /** * Gets a wrapped track object from the track storage. This method does not return null, unlike {@link #getTrack} + * * @param name the name of the track to get * @return an optional {@link Track} object * @throws NullPointerException if the name is null @@ -214,12 +236,14 @@ public interface LuckPermsApi { /** * Gets a set of all loaded tracks. + * * @return a {@link Set} of {@link Track} objects */ Set getTracks(); /** * Check if a track is loaded in memory + * * @param name the name to check for * @return true if the track is loaded * @throws NullPointerException if the name is null @@ -228,16 +252,18 @@ public interface LuckPermsApi { /** * Returns a permission builder instance + * * @param permission the main permission node to build * @return a {@link Node.Builder} instance * @throws IllegalArgumentException if the permission is invalid - * @throws NullPointerException if the permission is null + * @throws NullPointerException if the permission is null * @since 2.6 */ Node.Builder buildNode(String permission) throws IllegalArgumentException; /** * Register a custom context calculator to the server + * * @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. */ @@ -245,6 +271,7 @@ public interface LuckPermsApi { /** * Registers a custom context listener to the server, + * * @param contextListener the context listener 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. */ @@ -253,6 +280,7 @@ public interface LuckPermsApi { /** * Gets a calculated context instance for the user using the rules of the platform. * These values are calculated using the options in the configuration, and the provided calculators. + * * @param user the user to get contexts for * @return an optional containing contexts. Will return empty if the user is not online. */ diff --git a/api/src/main/java/me/lucko/luckperms/api/MessagingService.java b/api/src/main/java/me/lucko/luckperms/api/MessagingService.java index 7ab870ab1..7cf51aacb 100644 --- a/api/src/main/java/me/lucko/luckperms/api/MessagingService.java +++ b/api/src/main/java/me/lucko/luckperms/api/MessagingService.java @@ -24,6 +24,7 @@ package me.lucko.luckperms.api; /** * Exposes any networking provider being used on the platform. e.g. Redis + * * @since 2.14 */ public interface MessagingService { diff --git a/api/src/main/java/me/lucko/luckperms/api/MetaUtils.java b/api/src/main/java/me/lucko/luckperms/api/MetaUtils.java index dd26e8802..503fb9684 100644 --- a/api/src/main/java/me/lucko/luckperms/api/MetaUtils.java +++ b/api/src/main/java/me/lucko/luckperms/api/MetaUtils.java @@ -32,14 +32,14 @@ import java.util.Set; /** * A collection of utilities to help retrieve meta values for {@link PermissionHolder}s + * * @since 2.7 */ public class MetaUtils { - private MetaUtils(){} - /** * Escapes special characters used within LuckPerms, so the string can be saved without issues + * * @param s the string to escape * @return an escaped string * @throws NullPointerException if the string is null @@ -48,7 +48,7 @@ public class MetaUtils { if (s == null) { throw new NullPointerException(); } - + s = s.replace(".", "{SEP}"); s = s.replace("/", "{FSEP}"); s = s.replace("$", "{DSEP}"); @@ -58,6 +58,7 @@ public class MetaUtils { /** * Unescapes special characters used within LuckPerms, the inverse of {@link #escapeCharacters(String)} + * * @param s the string to unescape * @return an unescaped string * @throws NullPointerException if the string is null @@ -66,7 +67,7 @@ public class MetaUtils { if (s == null) { throw new NullPointerException(); } - + s = s.replace("{SEP}", "."); s = s.replace("{FSEP}", "/"); s = s.replace("{DSEP}", "$"); @@ -76,19 +77,20 @@ public class MetaUtils { /** * Sets a meta value on a holder + * * @param holder the holder to apply the meta node to * @param server the server to apply the meta on, can be null - * @param world the world to apply the meta on, can be null - * @param node the meta node - * @param value the meta value - * @throws NullPointerException if the holder, node or value is null + * @param world the world to apply the meta on, can be null + * @param node the meta node + * @param value the meta value + * @throws NullPointerException if the holder, node or value is null * @throws IllegalArgumentException if the node or value is empty */ public static void setMeta(PermissionHolder holder, String server, String world, String node, String value) { if (holder == null) { throw new NullPointerException("holder"); } - + if (node == null) { throw new NullPointerException("node"); } @@ -108,7 +110,7 @@ public class MetaUtils { if (server == null || server.equals("")) { server = "global"; } - + node = escapeCharacters(node); value = escapeCharacters(value); @@ -118,11 +120,12 @@ public class MetaUtils { toRemove.add(n); } } - + for (Node n : toRemove) { try { holder.unsetPermission(n); - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } } Node.Builder metaNode = LuckPerms.getApi().buildNode("meta." + node + "." + value).setValue(true); @@ -135,19 +138,21 @@ public class MetaUtils { try { holder.setPermission(metaNode.build()); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } } /** * Gets a meta value for the holder - * @param holder the holder to get the meta from - * @param server the server to retrieve the meta on, can be null - * @param world the world to retrieve the meta on, can be null - * @param node the node to get - * @param defaultValue the default value to return if the node is not set + * + * @param holder the holder to get the meta from + * @param server the server to retrieve the meta on, can be null + * @param world the world to retrieve the meta on, can be null + * @param node the node to get + * @param defaultValue the default value to return if the node is not set * @param includeGlobal if global nodes should be considered when retrieving the meta * @return a meta string, or the default value if the user does not have the meta node - * @throws NullPointerException if the holder or node is null + * @throws NullPointerException if the holder or node is null * @throws IllegalArgumentException if the node is empty */ public static String getMeta(PermissionHolder holder, String server, String world, String node, String defaultValue, boolean includeGlobal) { @@ -217,17 +222,19 @@ public class MetaUtils { try { holder.setPermission(node.build()); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } } /** * Adds a prefix to a holder on a specific server and world - * @param holder the holder to set the prefix for - * @param prefix the prefix value + * + * @param holder the holder to set the prefix for + * @param prefix the prefix value * @param priority the priority to set the prefix at - * @param server the server to set the prefix on, can be null - * @param world the world to set the prefix on, can be null - * @throws NullPointerException if the holder is null + * @param server the server to set the prefix on, can be null + * @param world the world to set the prefix on, can be null + * @throws NullPointerException if the holder is null * @throws IllegalArgumentException if the prefix is null or empty */ public static void setPrefix(PermissionHolder holder, String prefix, int priority, String server, String world) { @@ -236,12 +243,13 @@ public class MetaUtils { /** * Adds a suffix to a holder on a specific server and world - * @param holder the holder to set the suffix for - * @param suffix the suffix value + * + * @param holder the holder to set the suffix for + * @param suffix the suffix value * @param priority the priority to set the suffix at - * @param server the server to set the suffix on, can be null - * @param world the world to set the suffix on, can be null - * @throws NullPointerException if the holder is null + * @param server the server to set the suffix on, can be null + * @param world the world to set the suffix on, can be null + * @throws NullPointerException if the holder is null * @throws IllegalArgumentException if the suffix is null or empty */ public static void setSuffix(PermissionHolder holder, String suffix, int priority, String server, String world) { @@ -272,7 +280,7 @@ public class MetaUtils { if (!n.shouldApplyOnWorld(world, includeGlobal, false)) { continue; } - + if (prefix ? !n.isPrefix() : !n.isSuffix()) { continue; } @@ -289,9 +297,10 @@ public class MetaUtils { /** * Returns a holders highest priority prefix, if they have one - * @param holder the holder - * @param server the server to retrieve the prefix on - * @param world the world to retrieve the prefix on + * + * @param holder the holder + * @param server the server to retrieve the prefix on + * @param world the world to retrieve the prefix on * @param includeGlobal if global nodes should be considered when retrieving the prefix * @return a prefix string, if the holder has one, or an empty string if not. * @throws NullPointerException if the holder is null @@ -302,9 +311,10 @@ public class MetaUtils { /** * Returns a holders highest priority suffix, if they have one - * @param holder the holder - * @param server the server to retrieve the suffix on - * @param world the world to retrieve the suffix on + * + * @param holder the holder + * @param server the server to retrieve the suffix on + * @param world the world to retrieve the suffix on * @param includeGlobal if global nodes should be considered when retrieving the suffix * @return a suffix string, if the holder has one, or an empty string if not. * @throws NullPointerException if the holder is null @@ -312,5 +322,8 @@ public class MetaUtils { public static String getSuffix(PermissionHolder holder, String server, String world, boolean includeGlobal) { return getChatMeta(false, holder, server, world, includeGlobal); } - + + private MetaUtils() { + } + } 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 67796d4f5..3023dea07 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Node.java +++ b/api/src/main/java/me/lucko/luckperms/api/Node.java @@ -24,11 +24,16 @@ package me.lucko.luckperms.api; import me.lucko.luckperms.api.context.ContextSet; -import java.util.*; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; /** * Represents an immutable node object *

Use {@link LuckPermsApi#buildNode(String)} to get an instance. + * * @since 2.6 */ @SuppressWarnings("unused") @@ -41,6 +46,7 @@ public interface Node extends Map.Entry { /** * Get what value the permission is set to. A negated node would return false. + * * @return the permission's value */ @Override @@ -59,18 +65,21 @@ public interface Node extends Map.Entry { /** * If this node is set to override explicitly. * This value does not persist across saves, and is therefore only useful for transient nodes + * * @return true if this node is set to override explicitly */ boolean isOverride(); /** * Gets the server this node applies on, if the node is server specific + * * @return an {@link Optional} containing the server, if one is defined */ Optional getServer(); /** * Gets the world this node applies on, if the node is world specific + * * @return an {@link Optional} containing the world, if one is defined */ Optional getWorld(); @@ -87,25 +96,28 @@ public interface Node extends Map.Entry { /** * If this node should apply on a specific server - * @param server the name of the server + * + * @param server the name of the server * @param includeGlobal if global permissions should apply - * @param applyRegex if regex should be applied + * @param applyRegex if regex should be applied * @return true if the node should apply */ boolean shouldApplyOnServer(String server, boolean includeGlobal, boolean applyRegex); /** * If this node should apply on a specific world - * @param world the name of the world + * + * @param world the name of the world * @param includeGlobal if global permissions should apply - * @param applyRegex if regex should be applied + * @param applyRegex if regex should be applied * @return true if the node should apply */ boolean shouldApplyOnWorld(String world, boolean includeGlobal, boolean applyRegex); /** * If this node should apply in the given context - * @param context the context key value pairs + * + * @param context the context key value pairs * @param worldAndServer if world and server contexts should be checked * @return true if the node should apply * @since 2.13 @@ -114,6 +126,7 @@ public interface Node extends Map.Entry { /** * If this node should apply in the given context + * * @param context the context key value pairs * @return true if the node should apply * @since 2.13 @@ -122,7 +135,8 @@ public interface Node extends Map.Entry { /** * If this node should apply in the given context - * @param context the context key value pairs + * + * @param context the context key value pairs * @param worldAndServer if world and server contexts should be checked * @return true if the node should apply * @deprecated in favour of {@link #shouldApplyWithContext(ContextSet, boolean)} @@ -134,6 +148,7 @@ public interface Node extends Map.Entry { /** * If this node should apply in the given context + * * @param context the context key value pairs * @return true if the node should apply * @deprecated in favour of {@link #shouldApplyWithContext(ContextSet)} @@ -145,7 +160,8 @@ public interface Node extends Map.Entry { /** * Similar to {@link #shouldApplyOnServer(String, boolean, boolean)}, except this method accepts a List - * @param servers the list of servers + * + * @param servers the list of servers * @param includeGlobal if global permissions should apply * @return true if the node should apply */ @@ -153,7 +169,8 @@ public interface Node extends Map.Entry { /** * Similar to {@link #shouldApplyOnWorld(String, boolean, boolean)}, except this method accepts a List - * @param worlds the list of world + * + * @param worlds the list of world * @param includeGlobal if global permissions should apply * @return true if the node should apply */ @@ -161,6 +178,7 @@ public interface Node extends Map.Entry { /** * Resolves a list of wildcards that match this node + * * @param possibleNodes a list of possible permission nodes * @return a list of permissions that match this wildcard */ @@ -168,6 +186,7 @@ public interface Node extends Map.Entry { /** * Resolves any shorthand parts of this node and returns the full list + * * @return a list of full nodes */ List resolveShorthand(); @@ -225,6 +244,7 @@ public interface Node extends Map.Entry { /** * Converts this node into a serialized form + * * @return a serialized node string */ String toSerializedNode(); @@ -247,6 +267,7 @@ public interface Node extends Map.Entry { /** * Gets the level of this wildcard, higher is more specific + * * @return the wildcard level * @throws IllegalStateException if this is not a wildcard */ @@ -259,6 +280,7 @@ public interface Node extends Map.Entry { /** * Gets the meta value from this node + * * @return the meta value * @throws IllegalStateException if this node is not a meta node */ @@ -271,6 +293,7 @@ public interface Node extends Map.Entry { /** * Gets the prefix value from this node + * * @return the prefix value * @throws IllegalStateException if this node is a not a prefix node */ @@ -283,6 +306,7 @@ public interface Node extends Map.Entry { /** * Gets the suffix value from this node + * * @return the suffix value * @throws IllegalStateException if this node is a not a suffix node */ @@ -290,6 +314,7 @@ public interface Node extends Map.Entry { /** * Checks if this Node is equal to another node + * * @param obj the other node * @return true if this node is equal to the other provided * @see #equalsIgnoringValue(Node) for a less strict implementation of this method @@ -298,6 +323,7 @@ public interface Node extends Map.Entry { /** * Similar to {@link Node#equals(Object)}, except doesn't take note of the value + * * @param other the other node * @return true if the two nodes are almost equal */ @@ -305,6 +331,7 @@ public interface Node extends Map.Entry { /** * Similar to {@link Node#equals(Object)}, except doesn't take note of the expiry time or value + * * @param other the other node * @return true if the two nodes are almost equal */ @@ -312,6 +339,7 @@ public interface Node extends Map.Entry { /** * Similar to {@link Node#equals(Object)}, except doesn't take note of the value or if the node is temporary + * * @param other the other node * @return true if the two nodes are almost equal * @since 2.8 @@ -323,6 +351,7 @@ public interface Node extends Map.Entry { */ interface Builder { Builder setNegated(boolean negated); + Builder setValue(boolean value); /** @@ -332,13 +361,21 @@ public interface Node extends Map.Entry { Builder setOverride(boolean override); Builder setExpiry(long expireAt); + Builder setWorld(String world); + Builder setServer(String server) throws IllegalArgumentException; + Builder withExtraContext(String key, String value); + Builder withExtraContext(Map map); + Builder withExtraContext(Set> context); + Builder withExtraContext(Map.Entry entry); + Builder withExtraContext(ContextSet set); + Node build(); } 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 5c49e1bcd..0f38d19d2 100644 --- a/api/src/main/java/me/lucko/luckperms/api/PermissionHolder.java +++ b/api/src/main/java/me/lucko/luckperms/api/PermissionHolder.java @@ -37,13 +37,14 @@ import java.util.SortedSet; public interface PermissionHolder { /** - * @return the identifier for this object. either a uuid string or name - * However, you should really just use {@link User#getUuid()}, {@link User#getName()} or {@link Group#getName()} + * @return the identifier for this object. either a uuid string or name However, you should really just use {@link + * User#getUuid()}, {@link User#getName()} or {@link Group#getName()} */ String getObjectName(); /** * Gets an immutable Set of the objects permission nodes + * * @return an immutable set of permissions in priority order * @since 2.6 */ @@ -51,6 +52,7 @@ public interface PermissionHolder { /** * Similar to {@link #getPermissions()}, except excluding transient permissions + * * @return a set of nodes * @since 2.6 */ @@ -58,6 +60,7 @@ public interface PermissionHolder { /** * Similar to {@link #getPermissions()}, except excluding non-transient permissions + * * @return a set of nodes * @since 2.6 */ @@ -66,6 +69,7 @@ public interface PermissionHolder { /** * Gets an immutable set of the nodes that this object has and inherits + * * @return an immutable set of permissions * @since 2.6 * @deprecated in favour of {@link #getAllNodes(Contexts)} @@ -78,6 +82,7 @@ public interface PermissionHolder { * Unlike {@link #getAllNodesFiltered(Contexts)}, this method will not filter individual nodes. The context is only * used to determine which groups should apply. * Nodes are sorted into priority order. + * * @param contexts the context for the lookup, * @return a mutable sorted set of permissions * @throws NullPointerException if the context is null @@ -89,6 +94,7 @@ public interface PermissionHolder { * Gets a mutable set of the nodes that is objects has and inherits, filtered by context. * Unlike {@link #getAllNodes(Contexts)}, this method WILL filter individual nodes, and only return ones that fully * meet the context provided. + * * @param contexts the context for the lookup * @return a mutable set of permissions * @throws NullPointerException if the context is null @@ -98,6 +104,7 @@ public interface PermissionHolder { /** * Gets an immutable Map of the objects permission nodes + * * @return an immutable map of permissions * @deprecated in favour of {@link #getPermissions()} */ @@ -106,6 +113,7 @@ public interface PermissionHolder { /** * Checks to see if the object has a certain permission + * * @param node the node to check for * @return a Tristate for the holders permission status for the node * @throws NullPointerException if the node is null @@ -115,6 +123,7 @@ public interface PermissionHolder { /** * Checks to see if the object has a certain permission + * * @param node the node to check for * @return a Tristate for the holders permission status for the node * @throws NullPointerException if the node is null @@ -124,75 +133,82 @@ public interface PermissionHolder { /** * Checks to see if the object has a certain permission + * * @param node The permission node - * @param b If the node is true/false(negated) + * @param b If the node is true/false(negated) * @return true if the object has the permission - * @throws NullPointerException if the node is null + * @throws NullPointerException if the node is null * @throws IllegalArgumentException if the node is invalid */ boolean hasPermission(String node, boolean b); /** * Checks to see the the object has a permission on a certain server - * @param node The permission node - * @param b If the node is true/false(negated) + * + * @param node The permission node + * @param b If the node is true/false(negated) * @param server The server * @return true if the object has the permission - * @throws NullPointerException if the node or server is null + * @throws NullPointerException if the node or server is null * @throws IllegalArgumentException if the node or server is invalid */ boolean hasPermission(String node, boolean b, String server); /** * Checks to see the the object has a permission on a certain server and world - * @param node The permission node - * @param b If the node is true/false(negated) + * + * @param node The permission node + * @param b If the node is true/false(negated) * @param server The server - * @param world The world + * @param world The world * @return true if the object has the permission - * @throws NullPointerException if the node, server or world is null + * @throws NullPointerException if the node, server or world is null * @throws IllegalArgumentException if the node, server or world is invalid */ boolean hasPermission(String node, boolean b, String server, String world); /** * Checks to see the the object has a permission - * @param node The permission node - * @param b If the node is true/false(negated) + * + * @param node The permission node + * @param b If the node is true/false(negated) * @param temporary if the permission is temporary * @return true if the object has the permission - * @throws NullPointerException if the node is null + * @throws NullPointerException if the node is null * @throws IllegalArgumentException if the node is invalid */ boolean hasPermission(String node, boolean b, boolean temporary); /** * Checks to see the the object has a permission on a certain server - * @param node The permission node - * @param b If the node is true/false(negated) - * @param server The server to check on + * + * @param node The permission node + * @param b If the node is true/false(negated) + * @param server The server to check on * @param temporary if the permission is temporary * @return true if the object has the permission - * @throws NullPointerException if the node or server is null + * @throws NullPointerException if the node or server is null * @throws IllegalArgumentException if the node or server is invalid */ boolean hasPermission(String node, boolean b, String server, boolean temporary); /** * Checks to see the the object has a permission on a certain server and world - * @param node The permission node - * @param b If the node is true/false(negated) - * @param server The server to check on - * @param world The world to check on + * + * @param node The permission node + * @param b If the node is true/false(negated) + * @param server The server to check on + * @param world The world to check on * @param temporary if the permission is temporary * @return true if the object has the permission - * @throws NullPointerException if the node, server or world is null + * @throws NullPointerException if the node, server or world is null * @throws IllegalArgumentException if the node, server or world is invalid */ boolean hasPermission(String node, boolean b, String server, String world, boolean temporary); /** * Cheks to see if the object inherits a certain permission + * * @param node the node to check for * @return a Tristate for the holders inheritance status for the node * @throws NullPointerException if the node is null @@ -202,78 +218,85 @@ public interface PermissionHolder { /** * Checks to see if the object inherits a certain permission + * * @param node The permission node - * @param b If the node is true/false(negated) + * @param b If the node is true/false(negated) * @return true if the object inherits the permission - * @throws NullPointerException if the node is null + * @throws NullPointerException if the node is null * @throws IllegalArgumentException if the node is invalid */ boolean inheritsPermission(String node, boolean b); /** * Checks to see the the object inherits a permission on a certain server - * @param node The permission node - * @param b If the node is true/false(negated) + * + * @param node The permission node + * @param b If the node is true/false(negated) * @param server The server * @return true if the object inherits the permission - * @throws NullPointerException if the node or server is null + * @throws NullPointerException if the node or server is null * @throws IllegalArgumentException if the node or server is invalid */ boolean inheritsPermission(String node, boolean b, String server); /** * Checks to see the the object inherits a permission on a certain server and world - * @param node The permission node - * @param b If the node is true/false(negated) + * + * @param node The permission node + * @param b If the node is true/false(negated) * @param server The server - * @param world The world + * @param world The world * @return true if the object inherits the permission - * @throws NullPointerException if the node, server or world is null + * @throws NullPointerException if the node, server or world is null * @throws IllegalArgumentException if the node server or world is invalid */ boolean inheritsPermission(String node, boolean b, String server, String world); /** * Checks to see if the object inherits a permission - * @param node The permission node - * @param b If the node is true/false(negated) + * + * @param node The permission node + * @param b If the node is true/false(negated) * @param temporary if the permission is temporary * @return true if the object inherits the permission - * @throws NullPointerException if the node is null + * @throws NullPointerException if the node is null * @throws IllegalArgumentException if the node is invalid */ boolean inheritsPermission(String node, boolean b, boolean temporary); /** * Checks to see if the object inherits a permission on a certain server - * @param node The permission node - * @param b If the node is true/false(negated) - * @param server The server + * + * @param node The permission node + * @param b If the node is true/false(negated) + * @param server The server * @param temporary if the permission is temporary * @return true if the object inherits the permission - * @throws NullPointerException if the node or server is null + * @throws NullPointerException if the node or server is null * @throws IllegalArgumentException if the node or server is invalid */ boolean inheritsPermission(String node, boolean b, String server, boolean temporary); /** * Checks to see if the object inherits a permission on a certain server and world - * @param node The permission node - * @param b If the node is true/false(negated) - * @param server The server - * @param world The world + * + * @param node The permission node + * @param b If the node is true/false(negated) + * @param server The server + * @param world The world * @param temporary if the permission is temporary * @return true if the object inherits the permission - * @throws NullPointerException if the node, server or world is null + * @throws NullPointerException if the node, server or world is null * @throws IllegalArgumentException if the node, server or world if invalid */ boolean inheritsPermission(String node, boolean b, String server, String world, boolean temporary); /** * Sets a permission for the object + * * @param node The node to be set * @throws ObjectAlreadyHasException if the object already has the permission - * @throws NullPointerException if the node is null + * @throws NullPointerException if the node is null * @since 2.6 */ void setPermission(Node node) throws ObjectAlreadyHasException; @@ -289,20 +312,22 @@ public interface PermissionHolder { * want it to persist, and have to worry about removing it when they log out. * *

For unsetting a transient permission, see {@link #unsetTransientPermission(Node)} + * * @param node The node to be set * @throws ObjectAlreadyHasException if the object already has the permission - * @throws NullPointerException if the node is null + * @throws NullPointerException if the node is null * @since 2.6 */ void setTransientPermission(Node node) throws ObjectAlreadyHasException; /** * Sets a permission for the object - * @param node The node to be set + * + * @param node The node to be set * @param value What to set the node to - true/false(negated) * @throws ObjectAlreadyHasException if the object already has the permission - * @throws NullPointerException if the node is null - * @throws IllegalArgumentException if the node is invalid + * @throws NullPointerException if the node is null + * @throws IllegalArgumentException if the node is invalid * @deprecated in favour of {@link #setPermission(Node)} */ @Deprecated @@ -310,12 +335,13 @@ public interface PermissionHolder { /** * Sets a permission for the object on a specific server - * @param node The node to set - * @param value What to set the node to - true/false(negated) + * + * @param node The node to set + * @param value What to set the node to - true/false(negated) * @param server The server to set the permission on * @throws ObjectAlreadyHasException if the object already has the permission - * @throws NullPointerException if the node or server is null - * @throws IllegalArgumentException if the node or server is invalid + * @throws NullPointerException if the node or server is null + * @throws IllegalArgumentException if the node or server is invalid * @deprecated in favour of {@link #setPermission(Node)} */ @Deprecated @@ -323,13 +349,14 @@ public interface PermissionHolder { /** * Sets a permission for the object on a specific server and world - * @param node The node to set - * @param value What to set the node to - true/false(negated) + * + * @param node The node to set + * @param value What to set the node to - true/false(negated) * @param server The server to set the permission on - * @param world The world to set the permission on + * @param world The world to set the permission on * @throws ObjectAlreadyHasException if the object already has the permission - * @throws NullPointerException if the node, server or world is null - * @throws IllegalArgumentException if the node, server or world is invalid + * @throws NullPointerException if the node, server or world is null + * @throws IllegalArgumentException if the node, server or world is invalid * @deprecated in favour of {@link #setPermission(Node)} */ @Deprecated @@ -337,12 +364,13 @@ public interface PermissionHolder { /** * Sets a temporary permission for the object - * @param node The node to set - * @param value What to set the node to - true/false(negated) + * + * @param node The node to set + * @param value What to set the node to - true/false(negated) * @param expireAt The time in unixtime when the permission will expire * @throws ObjectAlreadyHasException if the object already has the permission - * @throws NullPointerException if the node is null - * @throws IllegalArgumentException if the node is invalid or if the expiry time is in the past + * @throws NullPointerException if the node is null + * @throws IllegalArgumentException if the node is invalid or if the expiry time is in the past * @deprecated in favour of {@link #setPermission(Node)} */ @Deprecated @@ -350,13 +378,14 @@ public interface PermissionHolder { /** * Sets a temporary permission for the object on a specific server - * @param node The node to set - * @param value What to set the node to - true/false(negated) - * @param server The server to set the permission on + * + * @param node The node to set + * @param value What to set the node to - true/false(negated) + * @param server The server to set the permission on * @param expireAt The time in unixtime when the permission will expire * @throws ObjectAlreadyHasException if the object already has the permission - * @throws NullPointerException if the node or server is null - * @throws IllegalArgumentException if the node/server is invalid or if the expiry time is in the past + * @throws NullPointerException if the node or server is null + * @throws IllegalArgumentException if the node/server is invalid or if the expiry time is in the past * @deprecated in favour of {@link #setPermission(Node)} */ @Deprecated @@ -364,14 +393,15 @@ public interface PermissionHolder { /** * Sets a temporary permission for the object on a specific server and world - * @param node The node to set - * @param value What to set the node to - true/false(negated) - * @param server The server to set the permission on - * @param world The world to set the permission on + * + * @param node The node to set + * @param value What to set the node to - true/false(negated) + * @param server The server to set the permission on + * @param world The world to set the permission on * @param expireAt The time in unixtime when the permission will expire * @throws ObjectAlreadyHasException if the object already has the permission - * @throws NullPointerException if the node, server or world is null - * @throws IllegalArgumentException if the node/server/world is invalid, or if the expiry time is in the past + * @throws NullPointerException if the node, server or world is null + * @throws IllegalArgumentException if the node/server/world is invalid, or if the expiry time is in the past * @deprecated in favour of {@link #setPermission(Node)} */ @Deprecated @@ -379,6 +409,7 @@ public interface PermissionHolder { /** * Unsets a permission for the object + * * @param node The node to be unset * @throws ObjectLacksException if the node wasn't already set * @throws NullPointerException if the node is null @@ -388,6 +419,7 @@ public interface PermissionHolder { /** * Unsets a transient permission for the object + * * @param node The node to be unset * @throws ObjectLacksException if the node wasn't already set * @throws NullPointerException if the node is null @@ -397,10 +429,11 @@ public interface PermissionHolder { /** * Unsets a permission for the object - * @param node The node to be unset + * + * @param node The node to be unset * @param temporary if the permission being removed is temporary - * @throws ObjectLacksException if the node wasn't already set - * @throws NullPointerException if the node is null + * @throws ObjectLacksException if the node wasn't already set + * @throws NullPointerException if the node is null * @throws IllegalArgumentException if the node is invalid * @deprecated in favour of {@link #unsetPermission(Node)} */ @@ -409,9 +442,10 @@ public interface PermissionHolder { /** * Unsets a permission for the object + * * @param node The node to be unset - * @throws ObjectLacksException if the node wasn't already set - * @throws NullPointerException if the node is null + * @throws ObjectLacksException if the node wasn't already set + * @throws NullPointerException if the node is null * @throws IllegalArgumentException if the node is invalid * @deprecated in favour of {@link #unsetPermission(Node)} */ @@ -420,10 +454,11 @@ public interface PermissionHolder { /** * Unsets a permission for the object on a specific server - * @param node The node to be unset + * + * @param node The node to be unset * @param server The server to unset the node on - * @throws ObjectLacksException if the node wasn't already set - * @throws NullPointerException if the node or server is null + * @throws ObjectLacksException if the node wasn't already set + * @throws NullPointerException if the node or server is null * @throws IllegalArgumentException if the node or server is invalid * @deprecated in favour of {@link #unsetPermission(Node)} */ @@ -432,11 +467,12 @@ public interface PermissionHolder { /** * Unsets a permission for the object on a specific server and world - * @param node The node to be unset + * + * @param node The node to be unset * @param server The server to unset the node on - * @param world The world to unset the node on - * @throws ObjectLacksException if the node wasn't already set - * @throws NullPointerException if the node, server or world is null + * @param world The world to unset the node on + * @throws ObjectLacksException if the node wasn't already set + * @throws NullPointerException if the node, server or world is null * @throws IllegalArgumentException if the node, server or world is invalid * @deprecated in favour of {@link #unsetPermission(Node)} */ @@ -445,11 +481,12 @@ public interface PermissionHolder { /** * Unsets a permission for the object on a specific server - * @param node The node to be unset - * @param server The server to unset the node on + * + * @param node The node to be unset + * @param server The server to unset the node on * @param temporary if the permission being unset is temporary - * @throws ObjectLacksException if the node wasn't already set - * @throws NullPointerException if the node or server is null + * @throws ObjectLacksException if the node wasn't already set + * @throws NullPointerException if the node or server is null * @throws IllegalArgumentException if the node or server is invalid * @deprecated in favour of {@link #unsetPermission(Node)} */ @@ -458,12 +495,13 @@ public interface PermissionHolder { /** * Unsets a permission for the object on a specific server and world - * @param node The node to be unset - * @param server The server to unset the node on - * @param world The world to unset the node on + * + * @param node The node to be unset + * @param server The server to unset the node on + * @param world The world to unset the node on * @param temporary if the permission being unset is temporary - * @throws ObjectLacksException if the node wasn't already set - * @throws NullPointerException if the node, server or world is null + * @throws ObjectLacksException if the node wasn't already set + * @throws NullPointerException if the node, server or world is null * @throws IllegalArgumentException if the node, server or world is invalid * @deprecated in favour of {@link #unsetPermission(Node)} */ @@ -472,10 +510,11 @@ public interface PermissionHolder { /** * Gets the permissions and inherited permissions that apply to a specific server and world - * @param server The server to get nodes for - * @param world The world to get nodes for + * + * @param server The server to get nodes for + * @param world The world to get nodes for * @param excludedGroups Groups that shouldn't be inherited (to prevent circular inheritance issues) - * @param possibleNodes A list of possible permission nodes for wildcard permission handling + * @param possibleNodes A list of possible permission nodes for wildcard permission handling * @return a {@link Map} of the permissions * @deprecated in favour of {@link #getPermissions(String, String, Map, boolean, List, boolean)} */ @@ -484,8 +523,9 @@ public interface PermissionHolder { /** * Gets the permissions and inherited permissions that apply to a specific server and world - * @param server The server to get nodes for - * @param world The world to get nodes for + * + * @param server The server to get nodes for + * @param world The world to get nodes for * @param excludedGroups Groups that shouldn't be inherited (to prevent circular inheritance issues) * @return a {@link Map} of the permissions * @deprecated in favour of {@link #getPermissions(String, String, Map, boolean, List, boolean)} @@ -495,9 +535,10 @@ public interface PermissionHolder { /** * Gets the permissions and inherited permissions that apply to a specific server - * @param server The server to get nodes for + * + * @param server The server to get nodes for * @param excludedGroups Groups that shouldn't be inherited (to prevent circular inheritance issues) - * @param possibleNodes A list of possible permission nodes for wildcard permission handling + * @param possibleNodes A list of possible permission nodes for wildcard permission handling * @return a {@link Map} of the permissions * @deprecated in favour of {@link #getPermissions(String, String, Map, boolean, List, boolean)} */ @@ -506,7 +547,8 @@ public interface PermissionHolder { /** * Gets the permissions and inherited permissions that apply to a specific server - * @param server The server to get nodes for + * + * @param server The server to get nodes for * @param excludedGroups Groups that shouldn't be inherited (to prevent circular inheritance issues) * @return a {@link Map} of the permissions * @deprecated in favour of {@link #getPermissions(String, String, Map, boolean, List, boolean)} @@ -516,12 +558,13 @@ public interface PermissionHolder { /** * Convert the holders nodes into a Map of permissions to be applied on the platform - * @param server the server - * @param world the world - * @param extraContext any extra context to filter by + * + * @param server the server + * @param world the world + * @param extraContext any extra context to filter by * @param includeGlobal whether to include global nodes * @param possibleNodes a list of possible permissions for resolving wildcards - * @param applyGroups if inherited group permissions should be included + * @param applyGroups if inherited group permissions should be included * @return a map of permissions * @since 2.6 * @deprecated in favour of {@link #getAllNodesFiltered(Contexts)} @@ -531,6 +574,7 @@ public interface PermissionHolder { /** * Processes the nodes and returns the temporary ones. + * * @return a map of temporary nodes * @deprecated in favour of {@link #getTemporaryPermissionNodes()} */ @@ -539,6 +583,7 @@ public interface PermissionHolder { /** * Processes the nodes and returns the temporary ones. + * * @return a set of temporary nodes * @since 2.6 */ @@ -546,6 +591,7 @@ public interface PermissionHolder { /** * Processes the nodes and returns the non-temporary ones. + * * @return a map of permanent nodes * @deprecated in favour of {@link #getPermanentPermissionNodes()} */ @@ -554,6 +600,7 @@ public interface PermissionHolder { /** * Processes the nodes and returns the non-temporary ones. + * * @return a set of permanent nodes * @since 2.6 */ 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 ca8937b33..18ace418c 100644 --- a/api/src/main/java/me/lucko/luckperms/api/PlatformType.java +++ b/api/src/main/java/me/lucko/luckperms/api/PlatformType.java @@ -24,6 +24,7 @@ package me.lucko.luckperms.api; /** * Represents the platform type that LuckPerms is running on + * * @since 2.7 */ public enum PlatformType { 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 9bcce3b67..fd2e66e9d 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Storage.java +++ b/api/src/main/java/me/lucko/luckperms/api/Storage.java @@ -31,12 +31,13 @@ import java.util.function.Consumer; /** * Interface for the internal Storage instance * - * All methods return {@link CompletableFuture}s, which will be populated with the result once the data has been loaded - * asynchronously. Care should be taken when using the methods to ensure that the main server thread is not blocked. + *

All methods return {@link CompletableFuture}s, which will be populated with the result once the data has been + * loaded asynchronously. Care should be taken when using the methods to ensure that the main server thread is not + * blocked. * - * Methods such as {@link CompletableFuture#get()} and equivalent should not be called on the main server thread. - * If you need to use the result of these operations on the main server thread, please register a callback using - * {@link CompletableFuture#thenAcceptAsync(Consumer, Executor)} and {@link #getSyncExecutor()}. + *

Methods such as {@link CompletableFuture#get()} and equivalent should not be called on the main + * server thread. If you need to use the result of these operations on the main server thread, please register a + * callback using {@link CompletableFuture#thenAcceptAsync(Consumer, Executor)} and {@link #getSyncExecutor()}. * * @since 2.14 */ @@ -44,30 +45,36 @@ public interface Storage { /** * Get the name of the storage implementation. + * * @return the name of the implementation */ String getName(); /** * Return whether the storage instance is allowing logins on the platform. + * * @return true if logins are enabled */ boolean isAcceptingLogins(); /** * Returns an executor which will run all passed runnables on the main server thread. + * * @return an executor instance */ Executor getSyncExecutor(); /** - * Returns an executor which will run all passed runnables asynchronously using the platforms scheduler and thread pools. + * Returns an executor which will run all passed runnables asynchronously using the platforms scheduler and thread + * pools. + * * @return an executor instance */ Executor getAsyncExecutor(); /** * Saves an action to storage + * * @param entry the log entry to be saved * @return true if the operation completed successfully. * @throws NullPointerException if entry is null @@ -76,14 +83,17 @@ public interface Storage { /** * Loads and returns the entire log from storage + * * @return a log instance, could be null if loading failed */ CompletableFuture getLog(); /** * Loads a user's data from the main storage into the plugins local storage. - * @param uuid the uuid of the user to load - * @param username the users username. (if you want to specify null here, just input "null" as a string.) + * + * @param uuid the uuid of the user to load + * @param username the users username. (if you want to specify null here, just input "null" as a + * string.) * @return if the operation completed successfully * @throws NullPointerException if uuid or username is null */ @@ -91,15 +101,17 @@ public interface Storage { /** * Saves a user object back to storage. You should call this after you make any changes to a user. + * * @param user the user to save * @return true if the operation completed successfully. - * @throws NullPointerException if user is null + * @throws NullPointerException if user is null * @throws IllegalStateException if the user instance was not obtained from LuckPerms. */ CompletableFuture saveUser(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 */ CompletableFuture cleanupUsers(); @@ -107,109 +119,122 @@ public interface Storage { /** * Gets a set all "unique" user UUIDs. * "Unique" meaning the user isn't just a member of the "default" group. + * * @return a set of uuids, or null if the operation failed. */ CompletableFuture> getUniqueUsers(); /** * Creates and loads a group into the plugins local storage + * * @param name the name of the group * @return true if the operation completed successfully - * @throws NullPointerException if name is null + * @throws NullPointerException if name is null * @throws IllegalArgumentException if the name is invalid */ CompletableFuture createAndLoadGroup(String name); /** * Loads a group into the plugins local storage. + * * @param name the name of the group * @return true if the operation completed successfully - * @throws NullPointerException if name is null + * @throws NullPointerException if name is null * @throws IllegalArgumentException if the name is invalid */ CompletableFuture loadGroup(String name); /** * Loads all groups from the storage into memory + * * @return true if the operation completed successfully. */ CompletableFuture loadAllGroups(); /** * Saves a group back to storage. You should call this after you make any changes to a group. + * * @param group the group to save * @return true if the operation completed successfully. - * @throws NullPointerException if group is null + * @throws NullPointerException if group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ CompletableFuture saveGroup(Group group); /** * Permanently deletes a group from storage. + * * @param group the group to delete * @return true if the operation completed successfully. - * @throws NullPointerException if group is null + * @throws NullPointerException if group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ CompletableFuture deleteGroup(Group group); /** * Creates and loads a track into the plugins local storage + * * @param name the name of the track * @return true if the operation completed successfully - * @throws NullPointerException if name is null + * @throws NullPointerException if name is null * @throws IllegalArgumentException if the name is invalid */ CompletableFuture createAndLoadTrack(String name); /** * Loads a track into the plugins local storage. + * * @param name the name of the track * @return true if the operation completed successfully - * @throws NullPointerException if name is null + * @throws NullPointerException if name is null * @throws IllegalArgumentException if the name is invalid */ CompletableFuture loadTrack(String name); /** * Loads all tracks from the storage into memory + * * @return true if the operation completed successfully. */ CompletableFuture loadAllTracks(); /** * Saves a track back to storage. You should call this after you make any changes to a track. + * * @param track the track to save * @return true if the operation completed successfully. - * @throws NullPointerException if track is null + * @throws NullPointerException if track is null * @throws IllegalStateException if the track instance was not obtained from LuckPerms. */ CompletableFuture saveTrack(Track track); /** * Permanently deletes a track from storage + * * @param track the track to delete * @return true if the operation completed successfully. - * @throws NullPointerException if track is null + * @throws NullPointerException if track is null * @throws IllegalStateException if the track instance was not obtained from LuckPerms. */ CompletableFuture deleteTrack(Track track); /** * Saves UUID caching data to the global cache + * * @param username the users username - * @param uuid the users mojang unique id + * @param uuid the users mojang unique id * @return true if the operation completed successfully. - * @throws NullPointerException if either parameters are null + * @throws NullPointerException if either parameters are null * @throws IllegalArgumentException if the username is invalid */ CompletableFuture saveUUIDData(String username, UUID uuid); /** * Gets a UUID from a username + * * @param username the corresponding username * @return a uuid object, could be null - * @throws NullPointerException if either parameters are null + * @throws NullPointerException if either parameters are null * @throws IllegalArgumentException if the username is invalid */ CompletableFuture getUUID(String username); 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 e10f2f880..4318af803 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Track.java +++ b/api/src/main/java/me/lucko/luckperms/api/Track.java @@ -41,67 +41,75 @@ public interface Track { /** * Gets an ordered list of the groups on this track * Index 0 is the first/lowest group in (or start of) the track + * * @return an ordered {@link List} of the groups on this track */ List getGroups(); /** * Gets the number of groups on this track + * * @return the number of groups on this track */ int getSize(); /** * Gets the next group on the track, after the one provided + * * @param current the group before the group being requested * @return the group name, or null if the end of the track has been reached - * @throws ObjectLacksException if the track does not contain the group given - * @throws NullPointerException if the group is null + * @throws ObjectLacksException if the track does not contain the group given + * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ String getNext(Group current) throws ObjectLacksException; /** * Gets the previous group on the track, before the one provided + * * @param current the group after the group being requested * @return the group name, or null if the start of the track has been reached - * @throws ObjectLacksException if the track does not contain the group given - * @throws NullPointerException if the group is null + * @throws ObjectLacksException if the track does not contain the group given + * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ String getPrevious(Group current) throws ObjectLacksException; /** * Appends a group to the end of this track + * * @param group the group to append * @throws ObjectAlreadyHasException if the group is already on this track somewhere - * @throws NullPointerException if the group is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws NullPointerException if the group is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ void appendGroup(Group group) throws ObjectAlreadyHasException; /** * Inserts a group at a certain position on this track - * @param group the group to be inserted + * + * @param group the group to be inserted * @param position the index position (a value of 0 inserts at the start) * @throws ObjectAlreadyHasException if the group is already on this track somewhere * @throws IndexOutOfBoundsException if the position is less than 0 or greater than the size of the track - * @throws NullPointerException if the group is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @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; /** * Removes a group from this track + * * @param group the group to remove - * @throws ObjectLacksException if the group is not on this track - * @throws NullPointerException if the group is null + * @throws ObjectLacksException if the group is not on this 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; /** * Removes a group from this track + * * @param group the group to remove * @throws ObjectLacksException if the group is not on this track * @throws NullPointerException if the group is null @@ -110,15 +118,17 @@ public interface Track { /** * Checks if a group features on this track + * * @param group the group to check * @return true if the group is on this track - * @throws NullPointerException if the group is null + * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ boolean containsGroup(Group group); /** * Checks if a group features on this track + * * @param group the group to check * @return true if the group is on this track * @throws NullPointerException if the group is null 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 02f2d1bbb..3a0bf33db 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Tristate.java +++ b/api/src/main/java/me/lucko/luckperms/api/Tristate.java @@ -31,6 +31,10 @@ public enum Tristate { FALSE(false), UNDEFINED(false); + public static Tristate fromBoolean(boolean b) { + return b ? TRUE : FALSE; + } + private final boolean booleanValue; Tristate(boolean booleanValue) { @@ -40,8 +44,4 @@ public enum Tristate { public boolean asBoolean() { return booleanValue; } - - 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 70a13a7a0..84c93f7fa 100644 --- a/api/src/main/java/me/lucko/luckperms/api/User.java +++ b/api/src/main/java/me/lucko/luckperms/api/User.java @@ -48,16 +48,18 @@ public interface User extends PermissionHolder { /** * Gets the users primary group + * * @return the users primary group */ String getPrimaryGroup(); /** * Sets a users primary group + * * @param group the new primary group * @throws ObjectAlreadyHasException if the user already has this set as their primary group - * @throws IllegalStateException if the user is not a member of that group - * @throws NullPointerException if the group is null + * @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; @@ -68,6 +70,7 @@ public interface User extends PermissionHolder { /** * Gets the user's {@link UserData} cache, if they have one setup. + * * @return an optional, possibly containing the user's cached lookup data. * @since 2.13 */ @@ -75,6 +78,7 @@ public interface User extends PermissionHolder { /** * Check to see if the user is a member of a group + * * @param group The group to check membership of * @return true if the user is a member of the group * @throws NullPointerException if the group is null @@ -83,156 +87,170 @@ public interface User extends PermissionHolder { /** * Check to see if a user is a member of a group on a specific server - * @param group The group to check membership of + * + * @param group The group to check membership of * @param server The server to check on * @return true if the user is a member of the group - * @throws NullPointerException if the group or server is null + * @throws NullPointerException if the group or server is null * @throws IllegalArgumentException if the server is invalid */ boolean isInGroup(Group group, String server); /** * Check to see if a user is a member of a group on a specific server and world - * @param group The group to check membership of + * + * @param group The group to check membership of * @param server The server to check on - * @param world The world to check on + * @param world The world to check on * @return true if the user is a member of the group - * @throws NullPointerException if the group, server or world is null + * @throws NullPointerException if the group, server or world is null * @throws IllegalArgumentException if the server or world is invalid */ boolean isInGroup(Group group, String server, String world); /** * Add a user to a group + * * @param group The group to add the user to * @throws ObjectAlreadyHasException if the user is already a member of the group - * @throws NullPointerException if the group is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws NullPointerException if the group is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ void addGroup(Group group) throws ObjectAlreadyHasException; /** * Add a user to a group on a specific server - * @param group The group to add the user to + * + * @param group The group to add the user to * @param server The server to add the group on * @throws ObjectAlreadyHasException if the user is already a member of the group on that server - * @throws NullPointerException if the group or server is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. - * @throws IllegalArgumentException if the server is invalid + * @throws NullPointerException if the group or server is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws IllegalArgumentException if the server is invalid */ void addGroup(Group group, String server) throws ObjectAlreadyHasException; /** * Add a user to a group on a specific server and world - * @param group The group to add the user to + * + * @param group The group to add the user to * @param server The server to add the group on - * @param world The world to add the group on + * @param world The world to add the group on * @throws ObjectAlreadyHasException if the user is already a member of the group on that server - * @throws NullPointerException if the group, server or world is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. - * @throws IllegalArgumentException if the server or world is invalid + * @throws NullPointerException if the group, server or world is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws IllegalArgumentException if the server or world is invalid */ void addGroup(Group group, String server, String world) throws ObjectAlreadyHasException; /** * Add a user to a group temporarily on a specific server - * @param group The group to add the user to + * + * @param group The group to add the user to * @param expireAt when the group should expire * @throws ObjectAlreadyHasException if the user is already a member of the group on that server - * @throws NullPointerException if the group is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. - * @throws IllegalArgumentException if the expiry time is in the past + * @throws NullPointerException if the group is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws IllegalArgumentException if the expiry time is in the past */ void addGroup(Group group, long expireAt) throws ObjectAlreadyHasException; /** * Add a user to a group temporarily on a specific server - * @param group The group to add the user to - * @param server The server to add the group on + * + * @param group The group to add the user to + * @param server The server to add the group on * @param expireAt when the group should expire * @throws ObjectAlreadyHasException if the user is already a member of the group on that server - * @throws NullPointerException if the group or server is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. - * @throws IllegalArgumentException if the expiry time is in the past or the server is invalid + * @throws NullPointerException if the group or server is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws IllegalArgumentException if the expiry time is in the past or the server is invalid */ void addGroup(Group group, String server, long expireAt) throws ObjectAlreadyHasException; /** * Add a user to a group temporarily on a specific server and world - * @param group The group to add the user to - * @param server The server to add the group on - * @param world The world to add the group on + * + * @param group The group to add the user to + * @param server The server to add the group on + * @param world The world to add the group on * @param expireAt when the group should expire * @throws ObjectAlreadyHasException if the user is already a member of the group on that server - * @throws NullPointerException if the group, server or world is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. - * @throws IllegalArgumentException if the expiry time is in the past or the server/world is invalid + * @throws NullPointerException if the group, server or world is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws IllegalArgumentException if the expiry time is in the past or the server/world is invalid */ void addGroup(Group group, String server, String world, long expireAt) throws ObjectAlreadyHasException; /** * Remove the user from a group + * * @param group the group to remove the user from - * @throws ObjectLacksException if the user isn't a member of the group - * @throws NullPointerException if the group is null + * @throws ObjectLacksException if the user isn't a member of the group + * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ void removeGroup(Group group) throws ObjectLacksException; /** * Remove the user from a group - * @param group the group to remove the user from + * + * @param group the group to remove the user from * @param temporary if the group being removed is temporary - * @throws ObjectLacksException if the user isn't a member of the group - * @throws NullPointerException if the group is null + * @throws ObjectLacksException if the user isn't a member of the group + * @throws NullPointerException if the group is null * @throws IllegalStateException if the group instance was not obtained from LuckPerms. */ void removeGroup(Group group, boolean temporary) throws ObjectLacksException; /** * Remove the user from a group on a specific server - * @param group The group to remove the user from + * + * @param group The group to remove the user from * @param server The server to remove the group on - * @throws ObjectLacksException if the user isn't a member of the group - * @throws NullPointerException if the group or server is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws ObjectLacksException if the user isn't a member of the group + * @throws NullPointerException if the group or server is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. * @throws IllegalArgumentException if the server is invalid */ void removeGroup(Group group, String server) throws ObjectLacksException; /** * Remove the user from a group on a specific server and world - * @param group The group to remove the user from + * + * @param group The group to remove the user from * @param server The server to remove the group on - * @param world The world to remove the group on - * @throws ObjectLacksException if the user isn't a member of the group - * @throws NullPointerException if the group, server or world is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @param world The world to remove the group on + * @throws ObjectLacksException if the user isn't a member of the group + * @throws NullPointerException if the group, server or world is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. * @throws IllegalArgumentException if the server or world is invalid */ void removeGroup(Group group, String server, String world) throws ObjectLacksException; /** * Remove the user from a group on a specific server - * @param group The group to remove the user from - * @param server The server to remove the group on + * + * @param group The group to remove the user from + * @param server The server to remove the group on * @param temporary if the group being removed is temporary - * @throws ObjectLacksException if the user isn't a member of the group - * @throws NullPointerException if the group or server is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws ObjectLacksException if the user isn't a member of the group + * @throws NullPointerException if the group or server is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. * @throws IllegalArgumentException if the expiry time is in the past or the server is invalid */ void removeGroup(Group group, String server, boolean temporary) throws ObjectLacksException; /** * Remove the user from a group on a specific server and world - * @param group The group to remove the user from - * @param server The server to remove the group on - * @param world The world to remove the group on + * + * @param group The group to remove the user from + * @param server The server to remove the group on + * @param world The world to remove the group on * @param temporary if the group being removed is temporary - * @throws ObjectLacksException if the user isn't a member of the group - * @throws NullPointerException if the group, server or world is null - * @throws IllegalStateException if the group instance was not obtained from LuckPerms. + * @throws ObjectLacksException if the user isn't a member of the group + * @throws NullPointerException if the group, server or world is null + * @throws IllegalStateException if the group instance was not obtained from LuckPerms. * @throws IllegalArgumentException if the expiry time is in the past or the server/world is invalid */ void removeGroup(Group group, String server, String world, boolean temporary) throws ObjectLacksException; @@ -244,25 +262,28 @@ public interface User extends PermissionHolder { /** * Get a {@link List} of all of the groups the user is a member of, on all servers + * * @return a {@link List} of group names */ List getGroupNames(); /** * Get a {@link List} of the groups the user is a member of on a specific server + * * @param server the server to check - * @param world the world to check + * @param world the world to check * @return a {@link List} of group names - * @throws NullPointerException if the server or world is null + * @throws NullPointerException if the server or world is null * @throws IllegalArgumentException if the server or world is invalid */ List getLocalGroups(String server, String world); /** * Get a {@link List} of the groups the user is a member of on a specific server + * * @param server the server to check * @return a {@link List} of group names - * @throws NullPointerException if the server is null + * @throws NullPointerException if the server is null * @throws IllegalArgumentException if the server is invalid */ List getLocalGroups(String server); diff --git a/api/src/main/java/me/lucko/luckperms/api/UuidCache.java b/api/src/main/java/me/lucko/luckperms/api/UuidCache.java index e093837e9..cc75f0ec4 100644 --- a/api/src/main/java/me/lucko/luckperms/api/UuidCache.java +++ b/api/src/main/java/me/lucko/luckperms/api/UuidCache.java @@ -27,13 +27,13 @@ import java.util.UUID; /** * A UUID cache for online users, between external Mojang UUIDs, and internal LuckPerms UUIDs. * - *

This UuidCache is a means of allowing users to have the same internal UUID across a network of offline mode servers - * or mixed offline mode and online mode servers. Platforms running in offline mode generate a random UUID for a user when - * they first join the server, but this UUID will then not be consistent across the network. LuckPerms will instead check - * the datastore cache, to get a UUID for a user that is consistent across an entire network. + *

This UuidCache is a means of allowing users to have the same internal UUID across a network of offline mode + * servers or mixed offline mode and online mode servers. Platforms running in offline mode generate a random UUID for a + * user when they first join the server, but this UUID will then not be consistent across the network. LuckPerms will + * instead check the datastore cache, to get a UUID for a user that is consistent across an entire network. * - *

If you want to get a user object from the Storage using the api on a server in offline mode, you will need to use this cache, - * OR use Storage#getUUID, for users that are not online. + *

If you want to get a user object from the Storage using the api on a server in offline mode, you will need to use + * this cache, OR use Storage#getUUID, for users that are not online. * *

WARNING: THIS IS ONLY EFFECTIVE FOR ONLINE PLAYERS. USE THE DATASTORE METHODS FOR OFFLINE PLAYERS. */ @@ -42,6 +42,7 @@ public interface UuidCache { /** * Gets a users internal "LuckPerms" UUID, from the one given by the server. + * * @param external the UUID assigned by the server, through Player#getUniqueId or ProxiedPlayer#getUniqueId * @return the corresponding internal UUID */ @@ -49,6 +50,7 @@ public interface UuidCache { /** * Gets a users external, server assigned or Mojang assigned unique id, from the internal one used within LuckPerms. + * * @param internal the UUID used within LuckPerms, through User#getUuid * @return the corresponding external UUID */ 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 efa39e9f7..87b1b3952 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 @@ -27,36 +27,44 @@ import java.util.SortedMap; /** * Holds cached Meta lookup data for a specific set of contexts + * * @since 2.13 */ public interface MetaData { /** * Gets an immutable copy of the meta this user has + * * @return an immutable map of meta */ Map getMeta(); /** - * Gets an immutable sorted map of all of the prefixes the user has, whereby the first value is the highest priority prefix. + * Gets an immutable sorted map of all of the prefixes the user has, whereby the first value is the highest priority + * prefix. + * * @return a sorted map of prefixes */ SortedMap getPrefixes(); /** - * Gets an immutable sorted map of all of the suffixes the user has, whereby the first value is the highest priority suffix. + * Gets an immutable sorted map of all of the suffixes the user has, whereby the first value is the highest priority + * suffix. + * * @return a sorted map of suffixes */ SortedMap getSuffixes(); /** * Gets the user's highest priority prefix, or null if the user has no prefixes + * * @return a prefix string, or null */ String getPrefix(); /** * Gets the user's highest priority suffix, or null if the user has no suffixes + * * @return a suffix string, or null */ String getSuffix(); 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 f6d7bf4ab..ce10e57d3 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 @@ -28,12 +28,14 @@ import java.util.Map; /** * Holds cached Permission lookup data for a specific set of contexts + * * @since 2.13 */ public interface PermissionData { /** * Gets a permission value for the given permission node + * * @param permission the permission node * @return a tristate result * @throws NullPointerException if permission is null @@ -48,6 +50,7 @@ public interface PermissionData { /** * Gets an immutable copy of the permission map backing the permission calculator + * * @return an immutable set of permissions */ 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 8a58868bc..4a4e84d8d 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 @@ -28,7 +28,8 @@ import java.util.Set; /** * Holds cached permission and meta lookup data for a {@link me.lucko.luckperms.api.User}. - * Data is only likely to be available for online users. All calls will account for inheritance, as well as any + * + *

Data is only likely to be available for online users. All calls will account for inheritance, as well as any * default data provided by the platform. This calls are heavily cached and are therefore fast. * * @since 2.13 @@ -38,6 +39,7 @@ public interface UserData { /** * Gets PermissionData from the cache, given a specified context. * If the data is not cached, it is calculated. Therefore, this call could be costly. + * * @param contexts the contexts to get the permission data in * @return a permission data instance * @throws NullPointerException if contexts is null @@ -47,6 +49,7 @@ public interface UserData { /** * Gets MetaData from the cache, given a specified context. * If the data is not cached, it is calculated. Therefore, this call could be costly. + * * @param contexts the contexts to get the permission data in * @return a meta data instance * @throws NullPointerException if contexts is null @@ -55,6 +58,7 @@ public interface UserData { /** * Calculates permission data, bypassing the cache. + * * @param contexts the contexts to get permission data in * @return a permission data instance * @throws NullPointerException if contexts is null @@ -63,6 +67,7 @@ public interface UserData { /** * Calculates meta data, bypassing the cache. + * * @param contexts the contexts to get meta data in * @return a meta data instance * @throws NullPointerException if contexts is null @@ -72,6 +77,7 @@ public interface UserData { /** * Calculates permission data and stores it in the cache. If there is already data cached for the given contexts, * and if the resultant output is different, the cached value is updated. + * * @param contexts the contexts to recalculate in. * @throws NullPointerException if contexts is null */ @@ -80,6 +86,7 @@ public interface UserData { /** * Calculates meta data and stores it in the cache. If there is already data cached for the given contexts, * and if the resultant output is different, the cached value is updated. + * * @param contexts the contexts to recalculate in. * @throws NullPointerException if contexts is null */ @@ -97,6 +104,7 @@ public interface UserData { /** * Calls {@link #preCalculate(Contexts)} for the given contexts + * * @param contexts a set of contexts * @throws NullPointerException if contexts is null */ @@ -105,6 +113,7 @@ public interface UserData { /** * Ensures that PermissionData and MetaData is cached for a context. If the cache does not contain any data for the * context, it will be calculated and saved. + * * @param contexts the contexts to pre-calculate for * @throws NullPointerException if contexts is null */ diff --git a/api/src/main/java/me/lucko/luckperms/api/context/ContextCalculator.java b/api/src/main/java/me/lucko/luckperms/api/context/ContextCalculator.java index ecf7e4419..f26303bea 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 @@ -28,6 +28,7 @@ import java.util.concurrent.CopyOnWriteArrayList; /** * A simple implementation of the listener aspects of {@link IContextCalculator} + * * @param the subject type */ public abstract class ContextCalculator implements IContextCalculator { @@ -36,8 +37,9 @@ public abstract class ContextCalculator implements IContextCalculator { /** * Pushes an update to all registered {@link ContextListener}s. * Make sure any changes are applied internally before this method is called. + * * @param subject the subject that changed - * @param before the context state before the change + * @param before the context state before the change * @param current the context state after the change (now) * @throws NullPointerException if any parameters are null */ diff --git a/api/src/main/java/me/lucko/luckperms/api/context/ContextListener.java b/api/src/main/java/me/lucko/luckperms/api/context/ContextListener.java index 03882c72b..3b19c9bfc 100644 --- a/api/src/main/java/me/lucko/luckperms/api/context/ContextListener.java +++ b/api/src/main/java/me/lucko/luckperms/api/context/ContextListener.java @@ -26,14 +26,16 @@ import java.util.Map; /** * Listens to context changes + * * @param the subject type, Is ALWAYS the player class of the platform. */ public interface ContextListener { /** * Called whenever a context changes on the + * * @param subject the subject that had context changed - * @param before the context state before the change + * @param before the context state before the change * @param current the context state after the change (now) */ void onContextChange(T subject, Map.Entry before, Map.Entry current) throws Exception; 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 17864c655..c190a2c83 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 @@ -22,135 +22,114 @@ package me.lucko.luckperms.api.context; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Multimap; -import java.util.HashSet; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; /** * Holds contexts. - * All contained contexts are immutable, and unlike {@link MutableContextSet}, contexts cannot be added or removed. + * Implementations may be either mutable or immutable. * * @since 2.13 */ -public class ContextSet { - private static final ContextSet EMPTY = new ContextSet(); +public interface ContextSet { /** - * Make a singleton ContextSet from a context pair - * @param key the key + * Make a singleton ImmutableContextSet from a context pair + * + * @param key the key * @param value the value - * @return a new ContextSet containing one KV pair + * @return a new ImmutableContextSet containing one KV pair * @throws NullPointerException if key or value is null */ - public static ContextSet singleton(String key, String value) { - if (key == null) { - throw new NullPointerException("key"); - } - if (value == null) { - throw new NullPointerException("value"); - } - - MutableContextSet set = new MutableContextSet(); - set.add(key, value); - return set.immutableCopy(); + static ImmutableContextSet singleton(String key, String value) { + return ImmutableContextSet.singleton(key, value); } /** - * Creates a ContextSet from an existing map + * Creates a ImmutableContextSet from an existing map + * * @param map the map to copy from - * @return a new ContextSet representing the pairs from the map + * @return a new ImmutableContextSet representing the pairs from the map * @throws NullPointerException if the map is null */ - public static ContextSet fromMap(Map map) { - if (map == null) { - throw new NullPointerException("map"); - } - - MutableContextSet set = new MutableContextSet(); - set.addAll(map); - return set.immutableCopy(); + static ImmutableContextSet fromMap(Map map) { + return ImmutableContextSet.fromMap(map); } /** - * Creates a ContextSet from an existing iterable of Map Entries + * Creates a ImmutableContextSet from an existing iterable of Map Entries + * * @param iterable the iterable to copy from - * @return a new ContextSet representing the pairs in the iterable + * @return a new ImmutableContextSet representing the pairs in the iterable * @throws NullPointerException if the iterable is null */ - public static ContextSet fromEntries(Iterable> iterable) { - if (iterable == null) { - throw new NullPointerException("iterable"); - } - - MutableContextSet set = new MutableContextSet(); - set.addAll(iterable); - return set.immutableCopy(); + static ImmutableContextSet fromEntries(Iterable> iterable) { + return ImmutableContextSet.fromEntries(iterable); } /** - * Creates a new ContextSet from an existing set. + * Creates a ImmutableContextSet from an existing multimap + * + * @param multimap the multimap to copy from + * @return a new ImmutableContextSet representing the pairs in the multimap + * @throws NullPointerException if the multimap is null + * @since 2.16 + */ + static ImmutableContextSet fromMultimap(Multimap multimap) { + return ImmutableContextSet.fromMultimap(multimap); + } + + /** + * Creates a new ImmutableContextSet from an existing set. * Only really useful for converting between mutable and immutable types. + * * @param contextSet the context set to copy from - * @return a new ContextSet with the same content and the one provided + * @return a new ImmutableContextSet with the same content and the one provided * @throws NullPointerException if contextSet is null */ - public static ContextSet fromSet(ContextSet contextSet) { - if (contextSet == null) { - throw new NullPointerException("contextSet"); - } - - MutableContextSet set = new MutableContextSet(); - set.addAll(contextSet.toSet()); - return set.immutableCopy(); + static ImmutableContextSet fromSet(ContextSet contextSet) { + return ImmutableContextSet.fromSet(contextSet); } /** - * Creates a new empty ContextSet. - * @return a new ContextSet + * Creates a new empty ImmutableContextSet. + * + * @return a new ImmutableContextSet */ - public static ContextSet empty() { - return EMPTY; - } - - final Set> contexts; - - public ContextSet() { - this.contexts = new HashSet<>(); - } - - protected ContextSet(Set> contexts) { - this.contexts = contexts; + static ImmutableContextSet empty() { + return ImmutableContextSet.empty(); } /** * Check to see if this set is in an immutable form + * * @return true if the set is immutable */ - public boolean isImmutable() { - return true; - } + boolean isImmutable(); /** * If the set is mutable, this method will return an immutable copy. Otherwise just returns itself. + * * @return an immutable ContextSet */ - public ContextSet makeImmutable() { - return this; - } + ImmutableContextSet makeImmutable(); + + /** + * Creates a mutable copy of this set. + * + * @return a mutable ContextSet + * @since 2.16 + */ + MutableContextSet mutableCopy(); /** * Converts this ContextSet to an immutable {@link Set} of {@link Map.Entry}s. + * * @return an immutable set */ - public Set> toSet() { - synchronized (contexts) { - return ImmutableSet.copyOf(contexts); - } - } + Set> toSet(); /** * Converts this ContextSet to an immutable {@link Map} @@ -160,153 +139,66 @@ public class ContextSet { * * @return an immutable map */ - public Map toMap() { - synchronized (contexts) { - return ImmutableMap.copyOf(contexts.stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); - } - } + Map toMap(); + + /** + * Converts this ContextSet to an immutable {@link Multimap} + * + * @return a multimap + * @since 2.16 + */ + Multimap toMultimap(); /** * Check if the set contains at least one value for the given key. + * * @param key the key to check for * @return true if the set contains a value for the key * @throws NullPointerException if the key is null */ - public boolean containsKey(String key) { - if (key == null) { - throw new NullPointerException("key"); - } - - synchronized (contexts) { - for (Map.Entry e : contexts) { - if (e.getKey().equalsIgnoreCase(key)) { - return true; - } - } - } - return false; - } + boolean containsKey(String key); /** * Gets a set of all of the values mapped to the given key + * * @param key the key to find values for * @return a set of values * @throws NullPointerException if the key is null */ - public Set getValues(String key) { - if (key == null) { - throw new NullPointerException("key"); - } - - synchronized (contexts) { - return ImmutableSet.copyOf(contexts.stream() - .filter(e -> e.getKey().equalsIgnoreCase(key)) - .map(Map.Entry::getValue) - .collect(Collectors.toSet()) - ); - } - } + Set getValues(String key); /** * Check if thr set contains a given key mapped to a given value - * @param key the key to look for + * + * @param key the key to look for * @param value the value to look for (case sensitive) * @return true if the set contains the KV pair * @throws NullPointerException if the key or value is null */ - public boolean has(String key, String value) { - if (key == null) { - throw new NullPointerException("key"); - } - if (value == null) { - throw new NullPointerException("value"); - } - - synchronized (contexts) { - for (Map.Entry e : contexts) { - if (!e.getKey().equalsIgnoreCase(key)) { - continue; - } - - if (!e.getValue().equals(value)) { - continue; - } - - return true; - } - } - return false; - } + boolean has(String key, String value); /** * Same as {@link #has(String, String)}, except ignores the case of the value. - * @param key the key to look for + * + * @param key the key to look for * @param value the value to look for * @return true if the set contains the KV pair * @throws NullPointerException if the key or value is null */ - public boolean hasIgnoreCase(String key, String value) { - if (key == null) { - throw new NullPointerException("key"); - } - if (value == null) { - throw new NullPointerException("value"); - } - - synchronized (contexts) { - for (Map.Entry e : contexts) { - if (!e.getKey().equalsIgnoreCase(key)) { - continue; - } - - if (!e.getValue().equalsIgnoreCase(value)) { - continue; - } - - return true; - } - } - return false; - } + boolean hasIgnoreCase(String key, String value); /** * Check if the set is empty + * * @return true if the set is empty */ - public boolean isEmpty() { - synchronized (contexts) { - return contexts.isEmpty(); - } - } + boolean isEmpty(); /** * Gets the number of key-value context pairs in the set + * * @return the size of the set */ - public int size() { - synchronized (contexts) { - return contexts.size(); - } - } + int size(); - @Override - public boolean equals(Object o) { - if (o == this) return true; - if (!(o instanceof ContextSet)) return false; - final ContextSet other = (ContextSet) o; - - final Object thisContexts = this.contexts; - final Object otherContexts = other.contexts; - return thisContexts == null ? otherContexts == null : thisContexts.equals(otherContexts); - } - - @Override - public int hashCode() { - return 59 + (this.contexts == null ? 43 : this.contexts.hashCode()); - } - - @Override - public String toString() { - return "ContextSet(contexts=" + this.contexts + ")"; - } } diff --git a/api/src/main/java/me/lucko/luckperms/api/context/IContextCalculator.java b/api/src/main/java/me/lucko/luckperms/api/context/IContextCalculator.java index 2561e9bd7..754483d42 100644 --- a/api/src/main/java/me/lucko/luckperms/api/context/IContextCalculator.java +++ b/api/src/main/java/me/lucko/luckperms/api/context/IContextCalculator.java @@ -29,17 +29,19 @@ import java.util.Map; * Calculates whether contexts are applicable to {@link T} * *

Somewhat inspired by the system used on Sponge. + * * @param the subject type. Is ALWAYS the player class of the platform. */ public interface IContextCalculator { /** * Gives the subject all of the applicable contexts they meet - * @param subject the subject to add contexts to + * + * @param subject the subject to add contexts to * @param accumulator a map of contexts to add to * @return the map - * @deprecated in favour of {@link #giveApplicableContext(Object, MutableContextSet)}. Older implementations of this interface - * will still work, as the replacement method is given as a default, and falls back to using this method. + * @deprecated in favour of {@link #giveApplicableContext(Object, MutableContextSet)}. Older implementations of this + * interface will still work, as the replacement method is given as a default, and falls back to using this method. */ @Deprecated default Map giveApplicableContext(T subject, Map accumulator) { @@ -56,7 +58,7 @@ public interface IContextCalculator { *

You MUST implement this method. The default is only provided for backwards compatibility with * {@link #giveApplicableContext(Object, Map)}. * - * @param subject the subject to add contexts to + * @param subject the subject to add contexts to * @param accumulator a map of contexts to add to * @return the map * @since 2.13 @@ -72,6 +74,7 @@ public interface IContextCalculator { /** * Checks to see if a context is applicable to a subject + * * @param subject the subject to check against * @param context the context to check for * @return true if met, or false if not. If this calculator does not calculate the given context, return false. @@ -80,6 +83,7 @@ public interface IContextCalculator { /** * Adds a listener to be called whenever a context handled by this calculator changes + * * @param listener the listener instance * @throws NullPointerException if listener is null */ 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 new file mode 100644 index 000000000..8657114ac --- /dev/null +++ b/api/src/main/java/me/lucko/luckperms/api/context/ImmutableContextSet.java @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.lucko.luckperms.api.context; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Multimap; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * An immutable implementation of {@link ContextSet}. + * + * @since 2.16 + */ +public final class ImmutableContextSet implements ContextSet { + private static final ImmutableContextSet EMPTY = new ImmutableContextSet(ImmutableMultimap.of()); + + /** + * Make a singleton ImmutableContextSet from a context pair + * + * @param key the key + * @param value the value + * @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"); + } + + return new ImmutableContextSet(ImmutableMultimap.of(key.toLowerCase(), value)); + } + + /** + * Creates a ImmutableContextSet from an existing map + * + * @param map the map to copy from + * @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"); + } + + return new ImmutableContextSet(ImmutableMultimap.copyOf( + map.entrySet().stream() + .collect(Collectors.toMap( + e -> e.getKey().toLowerCase(), + Map.Entry::getValue + )).entrySet() + )); + } + + /** + * Creates a ImmutableContextSet from an existing iterable of Map Entries + * + * @param iterable the iterable to copy from + * @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"); + } + + return MutableContextSet.fromEntries(iterable).makeImmutable(); + } + + /** + * Creates a ImmutableContextSet from an existing multimap + * + * @param multimap the multimap to copy from + * @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"); + } + + return MutableContextSet.fromMultimap(multimap).makeImmutable(); + } + + /** + * Creates a new ImmutableContextSet from an existing set. + * Only really useful for converting between mutable and immutable types. + * + * @param contextSet the context set to copy from + * @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(); + } + + /** + * Creates a new empty ContextSet. + * + * @return a new ContextSet + */ + public static ImmutableContextSet empty() { + return EMPTY; + } + + private final Multimap map; + + ImmutableContextSet(Multimap contexts) { + this.map = ImmutableMultimap.copyOf(contexts); + } + + @Override + public boolean isImmutable() { + return true; + } + + @Override + @Deprecated // This set is already immutable! + public ImmutableContextSet makeImmutable() { + return this; + } + + @Override + public MutableContextSet mutableCopy() { + return MutableContextSet.fromSet(this); + } + + @Override + public Set> toSet() { + return ImmutableSet.copyOf(map.entries()); + } + + @Override + public Map toMap() { + return ImmutableMap.copyOf(map.entries()); + } + + @Override + public Multimap toMultimap() { + return map; + } + + @Override + public boolean containsKey(String key) { + if (key == null) { + throw new NullPointerException("key"); + } + + return map.containsKey(key); + } + + @Override + public Set getValues(String key) { + if (key == null) { + throw new NullPointerException("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"); + } + + 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"); + } + + Collection c = map.get(key); + if (c == null || c.isEmpty()) { + return false; + } + + for (String val : c) { + if (val.equalsIgnoreCase(value)) { + return true; + } + } + return false; + } + + @Override + public boolean isEmpty() { + return map.isEmpty(); + } + + @Override + public int size() { + return map.size(); + } + + @Override + public boolean equals(Object o) { + if (o == this) return true; + if (!(o instanceof ContextSet)) return false; + final ContextSet other = (ContextSet) o; + + final Multimap thisContexts = this.toMultimap(); + final Multimap otherContexts = other.toMultimap(); + return thisContexts == null ? otherContexts == null : thisContexts.equals(otherContexts); + } + + @Override + public int hashCode() { + return 59 + (this.map == null ? 43 : this.map.hashCode()); + } + + @Override + public String toString() { + return "ImmutableContextSet(contexts=" + this.map + ")"; + } +} 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 7aa71f8f2..a57f0359b 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 @@ -22,27 +22,39 @@ package me.lucko.luckperms.api.context; -import com.google.common.collect.Maps; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Multimap; +import com.google.common.collect.Multimaps; -import java.util.HashSet; +import java.util.Collection; import java.util.Map; +import java.util.Set; /** - * Holds contexts - * All contained contexts are immutable, but contexts can be added or removed from the set. + * A mutable implementation of {@link ContextSet}. * - * @since 2.13 + * @since 2.16 */ -public class MutableContextSet extends ContextSet { +public final class MutableContextSet implements ContextSet { /** * Make a singleton MutableContextSet from a context pair - * @param key the key + * + * @param key the key * @param value the value * @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"); + } + MutableContextSet set = new MutableContextSet(); set.add(key, value); return set; @@ -50,11 +62,16 @@ public class MutableContextSet extends ContextSet { /** * Creates a MutableContextSet from an existing map + * * @param map the map to copy from * @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"); + } + MutableContextSet set = new MutableContextSet(); set.addAll(map); return set; @@ -62,24 +79,49 @@ public class MutableContextSet extends ContextSet { /** * Creates a MutableContextSet from an existing iterable of Map Entries + * * @param iterable the iterable to copy from * @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"); + } + MutableContextSet set = new MutableContextSet(); set.addAll(iterable); return set; } + /** + * Creates a MutableContextSet from an existing multimap + * + * @param multimap the multimap to copy from + * @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"); + } + + return fromEntries(multimap.entries()); + } + /** * Creates a new MutableContextSet from an existing set. * Only really useful for converting between mutable and immutable types. + * * @param contextSet the context set to copy from * @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"); + } + MutableContextSet set = new MutableContextSet(); set.addAll(contextSet.toSet()); return set; @@ -87,35 +129,120 @@ public class MutableContextSet extends ContextSet { /** * Creates a new empty MutableContextSet. + * * @return a new MutableContextSet */ - public static MutableContextSet empty() { + public static MutableContextSet create() { return new MutableContextSet(); } + private final Multimap map; + + public MutableContextSet() { + this.map = Multimaps.synchronizedMultimap(HashMultimap.create()); + } + + private MutableContextSet(Multimap contexts) { + this.map = Multimaps.synchronizedMultimap(HashMultimap.create(contexts)); + } + @Override public boolean isImmutable() { return false; } @Override - public ContextSet makeImmutable() { - return immutableCopy(); + public ImmutableContextSet makeImmutable() { + return new ImmutableContextSet(map); } - /** - * Returns an immutable copy of this set. - * @return an immutable copy of this set - */ - public ContextSet immutableCopy() { - synchronized (contexts) { - return new ContextSet(new HashSet<>(contexts)); + @Override + public MutableContextSet mutableCopy() { + return new MutableContextSet(map); + } + + @Override + public Set> toSet() { + return ImmutableSet.copyOf(map.entries()); + } + + @Override + public Map toMap() { + return ImmutableMap.copyOf(map.entries()); + } + + @Override + public Multimap toMultimap() { + return map; + } + + @Override + public boolean containsKey(String key) { + if (key == null) { + throw new NullPointerException("key"); } + + return map.containsKey(key); + } + + @Override + public Set getValues(String key) { + if (key == null) { + throw new NullPointerException("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"); + } + + 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"); + } + + Collection c = map.get(key); + if (c == null || c.isEmpty()) { + return false; + } + + for (String val : c) { + if (val.equalsIgnoreCase(value)) { + return true; + } + } + return false; + } + + @Override + public boolean isEmpty() { + return map.isEmpty(); + } + + @Override + public int size() { + return map.size(); } /** * Adds a new key value pair to the set - * @param key the key to add + * + * @param key the key to add * @param value the value to add * @throws NullPointerException if the key or value is null */ @@ -127,13 +254,12 @@ public class MutableContextSet extends ContextSet { throw new NullPointerException("value"); } - synchronized (contexts) { - contexts.add(Maps.immutableEntry(key, value)); - } + map.put(key.toLowerCase(), value); } /** * Adds a new key value pair to the set + * * @param entry the entry to add * @throws NullPointerException if the entry is null */ @@ -142,13 +268,12 @@ public class MutableContextSet extends ContextSet { throw new NullPointerException("context"); } - synchronized (contexts) { - contexts.add(Maps.immutableEntry(entry.getKey(), entry.getValue())); - } + map.put(entry.getKey().toLowerCase(), entry.getValue()); } /** * Adds an iterable containing contexts to the set + * * @param iterable an iterable of key value context pairs * @throws NullPointerException if iterable is null */ @@ -157,15 +282,14 @@ public class MutableContextSet extends ContextSet { throw new NullPointerException("contexts"); } - synchronized (this.contexts) { - for (Map.Entry e : iterable) { - this.contexts.add(Maps.immutableEntry(e.getKey(), e.getValue())); - } + for (Map.Entry e : iterable) { + this.map.put(e.getKey().toLowerCase(), e.getValue()); } } /** * Adds the entry set of a map to the set + * * @param map the map to add from * @throws NullPointerException if the map is null */ @@ -178,6 +302,7 @@ public class MutableContextSet extends ContextSet { /** * Adds of of the values in another ContextSet to this set + * * @param contextSet the set to add from * @throws NullPointerException if the contextSet is null */ @@ -186,14 +311,13 @@ public class MutableContextSet extends ContextSet { throw new NullPointerException("contextSet"); } - synchronized (this.contexts) { - this.contexts.addAll(contextSet.toSet()); - } + this.map.putAll(contextSet.toMultimap()); } /** * Remove a key value pair from this set - * @param key the key to remove + * + * @param key the key to remove * @param value the value to remove (case sensitive) * @throws NullPointerException if the key or value is null */ @@ -205,14 +329,13 @@ public class MutableContextSet extends ContextSet { throw new NullPointerException("value"); } - synchronized (contexts) { - contexts.removeIf(e -> e.getKey().equalsIgnoreCase(key) && e.getValue().equals(value)); - } + map.entries().removeIf(entry -> entry.getKey().equalsIgnoreCase(key) && entry.getValue().equals(value)); } /** * Same as {@link #remove(String, String)}, except ignores the case of the value - * @param key the key to remove + * + * @param key the key to remove * @param value the value to remove * @throws NullPointerException if the key or value is null */ @@ -224,13 +347,12 @@ public class MutableContextSet extends ContextSet { throw new NullPointerException("value"); } - synchronized (contexts) { - contexts.removeIf(e -> e.getKey().equalsIgnoreCase(key) && e.getValue().equalsIgnoreCase(value)); - } + map.entries().removeIf(e -> e.getKey().equalsIgnoreCase(key) && e.getValue().equalsIgnoreCase(value)); } /** * Removes all pairs with the given key + * * @param key the key to remove * @throws NullPointerException if the key is null */ @@ -239,18 +361,14 @@ public class MutableContextSet extends ContextSet { throw new NullPointerException("key"); } - synchronized (contexts) { - contexts.removeIf(e -> e.getKey().equalsIgnoreCase(key)); - } + map.removeAll(key.toLowerCase()); } /** * Clears the set */ public void clear() { - synchronized (contexts) { - contexts.clear(); - } + map.clear(); } @Override @@ -259,14 +377,18 @@ public class MutableContextSet extends ContextSet { if (!(o instanceof ContextSet)) return false; final ContextSet other = (ContextSet) o; - final Object thisContexts = this.contexts; - final Object otherContexts = other.contexts; + final Multimap thisContexts = this.toMultimap(); + final Multimap otherContexts = other.toMultimap(); return thisContexts == null ? otherContexts == null : thisContexts.equals(otherContexts); } @Override public int hashCode() { - return 59 + (this.contexts == null ? 43 : this.contexts.hashCode()); + return 59 + (this.map == null ? 43 : this.map.hashCode()); } + @Override + public String toString() { + return "MutableContextSet(contexts=" + this.map + ")"; + } } diff --git a/api/src/main/java/me/lucko/luckperms/api/data/Callback.java b/api/src/main/java/me/lucko/luckperms/api/data/Callback.java index 6e0dac637..177262e8c 100644 --- a/api/src/main/java/me/lucko/luckperms/api/data/Callback.java +++ b/api/src/main/java/me/lucko/luckperms/api/data/Callback.java @@ -27,20 +27,16 @@ import java.util.function.Consumer; /** * A callback used to wait for the completion of asynchronous operations. * All callbacks are ran on the main server thread. + * * @param the return type * @deprecated in favour of {@link Consumer} */ @Deprecated public interface Callback { - /** - * Called when the operation completes. - * @param t the return value, may be null - */ - void onComplete(T t); - static Callback empty() { - return t -> {}; + return t -> { + }; } static Callback of(Runnable runnable) { @@ -58,9 +54,11 @@ public interface Callback { } /** - * Helper method for converting old {@link Callback}s to use the new {@link me.lucko.luckperms.api.Storage} interface. + * Helper method for converting old {@link Callback}s to use the new {@link me.lucko.luckperms.api.Storage} + * interface. + * * @param callback the callback to convert - * @param the return type + * @param the return type * @return a consumer instance * @since 2.14 * @deprecated in favour of just using {@link Consumer}s. @@ -70,4 +68,11 @@ public interface Callback { return callback::onComplete; } + /** + * Called when the operation completes. + * + * @param t the return value, may be null + */ + void onComplete(T t); + } 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 c10c2fb6c..c8f7dfa94 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 @@ -30,8 +30,11 @@ package me.lucko.luckperms.api.data; public interface DatastoreConfiguration extends MySQLConfiguration { String getAddress(); + String getDatabase(); + String getUsername(); + String getPassword(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/data/MySQLConfiguration.java b/api/src/main/java/me/lucko/luckperms/api/data/MySQLConfiguration.java index b564fecca..aedaf44fe 100644 --- a/api/src/main/java/me/lucko/luckperms/api/data/MySQLConfiguration.java +++ b/api/src/main/java/me/lucko/luckperms/api/data/MySQLConfiguration.java @@ -29,7 +29,10 @@ package me.lucko.luckperms.api.data; public interface MySQLConfiguration { String getAddress(); + String getDatabase(); + String getUsername(); + String getPassword(); } diff --git a/api/src/main/java/me/lucko/luckperms/api/event/LPEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/LPEvent.java index 6f9ed2cf8..a9cadd4f0 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/LPEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/LPEvent.java @@ -29,15 +29,14 @@ import me.lucko.luckperms.api.LuckPermsApi; */ public abstract class LPEvent { - /** - * A link to the API instance provided for convenience. - */ - private LuckPermsApi api = null; - /** * A friendly name of the event */ private final String eventName; + /** + * A link to the API instance provided for convenience. + */ + private LuckPermsApi api = null; protected LPEvent(String eventName) { this.eventName = eventName; diff --git a/api/src/main/java/me/lucko/luckperms/api/event/TargetedEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/TargetedEvent.java index ae4f5318d..523bbc001 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/TargetedEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/TargetedEvent.java @@ -24,6 +24,7 @@ package me.lucko.luckperms.api.event; /** * Represents an event acting upon a target + * * @param the target type */ public class TargetedEvent extends LPEvent { diff --git a/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionExpireEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionExpireEvent.java index 7569d0a48..8d090ea49 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionExpireEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionExpireEvent.java @@ -27,6 +27,7 @@ import me.lucko.luckperms.api.event.TargetedEvent; /** * Called when a permission expires for an object. + * * @deprecated in favour of {@link PermissionNodeExpireEvent} */ @Deprecated diff --git a/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionNodeExpireEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionNodeExpireEvent.java index 5f64eaf9c..741e7aa15 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionNodeExpireEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionNodeExpireEvent.java @@ -28,6 +28,7 @@ import me.lucko.luckperms.api.event.AbstractPermissionEvent; /** * Called when a temporary permission node expires + * * @since 2.6 */ public class PermissionNodeExpireEvent extends AbstractPermissionEvent { diff --git a/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionNodeSetEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionNodeSetEvent.java index 78688ce60..79091f944 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionNodeSetEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionNodeSetEvent.java @@ -28,6 +28,7 @@ import me.lucko.luckperms.api.event.AbstractPermissionEvent; /** * Called when a permission node is set on a holder + * * @since 2.6 */ public class PermissionNodeSetEvent extends AbstractPermissionEvent { diff --git a/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionNodeUnsetEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionNodeUnsetEvent.java index 9f063a6ba..7cbcfd716 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionNodeUnsetEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionNodeUnsetEvent.java @@ -28,6 +28,7 @@ import me.lucko.luckperms.api.event.AbstractPermissionEvent; /** * Called when a permission node is unset from a holder + * * @since 2.6 */ public class PermissionNodeUnsetEvent extends AbstractPermissionEvent { diff --git a/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionSetEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionSetEvent.java index 44f7678ac..c4f522cc1 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionSetEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionSetEvent.java @@ -30,6 +30,7 @@ import java.util.Map; /** * Called whenever a user or group has a permission set. + * * @deprecated in favour of {@link PermissionNodeSetEvent} */ @Deprecated diff --git a/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionUnsetEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionUnsetEvent.java index 23a50bf74..d009c6c64 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionUnsetEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/events/PermissionUnsetEvent.java @@ -27,6 +27,7 @@ import me.lucko.luckperms.api.event.AbstractPermissionRemoveEvent; /** * Called whenever a user or group has a permission unset. + * * @deprecated in favour of {@link PermissionNodeUnsetEvent} */ @Deprecated diff --git a/api/src/main/java/me/lucko/luckperms/api/event/events/UserFirstLoginEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/events/UserFirstLoginEvent.java index ed7a9febf..00905779a 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/events/UserFirstLoginEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/events/UserFirstLoginEvent.java @@ -27,11 +27,11 @@ import me.lucko.luckperms.api.event.LPEvent; import java.util.UUID; /** - * Called when the user logs into the network for the first time. - * Particularly useful for networks with multiple lobbies, who want to welcome a user when they join for the first time. + * Called when the user logs into the network for the first time. Particularly useful for networks with multiple + * lobbies, who want to welcome a user when they join for the first time. * - *

This event is fired before the player has actually joined the game on the async login / auth event. - * If you want to do something with the user, store the UUID in a set, and then check the set in the PlayerJoinEvent o.e. + *

This event is fired before the player has actually joined the game on the async login / auth event. If you want to + * do something with the user, store the UUID in a set, and then check the set in the PlayerJoinEvent o.e. */ public class UserFirstLoginEvent extends LPEvent { diff --git a/api/src/main/java/me/lucko/luckperms/api/event/events/UserPermissionRefreshEvent.java b/api/src/main/java/me/lucko/luckperms/api/event/events/UserPermissionRefreshEvent.java index 4899aca68..85ff7967a 100644 --- a/api/src/main/java/me/lucko/luckperms/api/event/events/UserPermissionRefreshEvent.java +++ b/api/src/main/java/me/lucko/luckperms/api/event/events/UserPermissionRefreshEvent.java @@ -26,8 +26,8 @@ import me.lucko.luckperms.api.User; import me.lucko.luckperms.api.event.UserEvent; /** - * Called after a user has their permissions refreshed. - * If you cache user permissions within your own plugin, it's a good idea to update said cache whenever this event is called. + * Called after a user has their permissions refreshed. If you cache user permissions within your own plugin, it's a + * good idea to update said cache whenever this event is called. */ public class UserPermissionRefreshEvent extends UserEvent { diff --git a/api/src/main/java/me/lucko/luckperms/exceptions/MembershipException.java b/api/src/main/java/me/lucko/luckperms/exceptions/MembershipException.java index 8aed10fed..197e55319 100644 --- a/api/src/main/java/me/lucko/luckperms/exceptions/MembershipException.java +++ b/api/src/main/java/me/lucko/luckperms/exceptions/MembershipException.java @@ -23,7 +23,9 @@ package me.lucko.luckperms.exceptions; /** - * Thrown when a permission holding object doesn't / already has a permission or isn't / is already is a member of a group + * Thrown when a permission holding object doesn't / already has a permission or isn't / is already is a member of a + * group + * * @since 2.7 */ public abstract class MembershipException extends Exception { diff --git a/bukkit-legacy/pom.xml b/bukkit-legacy/pom.xml index de8702c38..0065b0660 100644 --- a/bukkit-legacy/pom.xml +++ b/bukkit-legacy/pom.xml @@ -1,11 +1,11 @@ - luckperms me.lucko.luckperms - 2.15-SNAPSHOT + 2.16-SNAPSHOT 4.0.0 diff --git a/bukkit-placeholders/pom.xml b/bukkit-placeholders/pom.xml index 53728b095..cd0dd1f8f 100644 --- a/bukkit-placeholders/pom.xml +++ b/bukkit-placeholders/pom.xml @@ -1,11 +1,11 @@ - luckperms me.lucko.luckperms - 2.15-SNAPSHOT + 2.16-SNAPSHOT 4.0.0 diff --git a/bukkit-placeholders/src/main/java/me/lucko/luckperms/api/placeholders/LuckPermsPlaceholderExpansion.java b/bukkit-placeholders/src/main/java/me/lucko/luckperms/api/placeholders/LuckPermsPlaceholderExpansion.java index 2296dfd8c..cdd089f14 100644 --- a/bukkit-placeholders/src/main/java/me/lucko/luckperms/api/placeholders/LuckPermsPlaceholderExpansion.java +++ b/bukkit-placeholders/src/main/java/me/lucko/luckperms/api/placeholders/LuckPermsPlaceholderExpansion.java @@ -25,9 +25,14 @@ package me.lucko.luckperms.api.placeholders; import me.clip.placeholderapi.PlaceholderAPIPlugin; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import me.clip.placeholderapi.util.TimeUtil; -import me.lucko.luckperms.api.*; +import me.lucko.luckperms.api.Contexts; +import me.lucko.luckperms.api.LuckPermsApi; +import me.lucko.luckperms.api.Node; +import me.lucko.luckperms.api.Track; +import me.lucko.luckperms.api.User; import me.lucko.luckperms.api.caching.UserData; import me.lucko.luckperms.api.context.MutableContextSet; + import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -56,6 +61,10 @@ public class LuckPermsPlaceholderExpansion extends PlaceholderExpansion { private static final String PLUGIN_NAME = "LuckPerms"; private static final String AUTHOR = "Luck"; + private static String formatBoolean(boolean b) { + return b ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); + } + private LuckPermsApi api = null; @Override @@ -208,8 +217,4 @@ public class LuckPermsPlaceholderExpansion extends PlaceholderExpansion { public String getAuthor() { return AUTHOR; } - - private static String formatBoolean(boolean b) { - return b ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); - } } diff --git a/bukkit/pom.xml b/bukkit/pom.xml index 1e616e183..c8c372b0c 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -1,11 +1,11 @@ - luckperms me.lucko.luckperms - 2.15-SNAPSHOT + 2.16-SNAPSHOT 4.0.0 diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java index 361383d90..195ed1f4a 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java @@ -22,8 +22,10 @@ package me.lucko.luckperms.bukkit; -import com.google.common.collect.ImmutableList; import lombok.AllArgsConstructor; + +import com.google.common.collect.ImmutableList; + import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.bukkit.calculators.AttachmentProcessor; import me.lucko.luckperms.bukkit.calculators.ChildProcessor; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCommand.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCommand.java index 930024032..a8b01480b 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCommand.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCommand.java @@ -24,9 +24,11 @@ package me.lucko.luckperms.bukkit; import com.google.common.base.Joiner; import com.google.common.base.Splitter; + import me.lucko.luckperms.common.commands.CommandManager; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.constants.Patterns; + import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfig.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfig.java index c17d3d32b..139b8dac2 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfig.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfig.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.bukkit; import me.lucko.luckperms.common.config.AbstractConfiguration; + import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java index ed531f3b2..d481d85bc 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java @@ -27,6 +27,7 @@ import me.lucko.luckperms.bukkit.model.LPPermissible; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.utils.AbstractListener; + import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitSenderFactory.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitSenderFactory.java index 952f7d8c4..7a9ec271c 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitSenderFactory.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitSenderFactory.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.bukkit; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.sender.SenderFactory; import me.lucko.luckperms.common.constants.Constants; + import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java index a29b79ea0..c61df8cdd 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -22,8 +22,10 @@ package me.lucko.luckperms.bukkit; -import com.google.common.collect.ImmutableMap; import lombok.Getter; + +import com.google.common.collect.ImmutableMap; + import me.lucko.luckperms.ApiHandler; import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Logger; @@ -58,7 +60,12 @@ import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.storage.StorageFactory; import me.lucko.luckperms.common.tasks.ExpireTemporaryTask; import me.lucko.luckperms.common.tasks.UpdateTask; -import me.lucko.luckperms.common.utils.*; +import me.lucko.luckperms.common.utils.BufferedRequest; +import me.lucko.luckperms.common.utils.DebugHandler; +import me.lucko.luckperms.common.utils.LocaleManager; +import me.lucko.luckperms.common.utils.LogFactory; +import me.lucko.luckperms.common.utils.PermissionCache; + import org.bukkit.World; import org.bukkit.command.PluginCommand; import org.bukkit.entity.Player; @@ -68,7 +75,13 @@ import org.bukkit.plugin.ServicePriority; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; -import java.util.*; +import java.util.Arrays; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executor; import java.util.concurrent.Executors; @@ -76,11 +89,10 @@ import java.util.stream.Collectors; @Getter public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { + private final Set ignoringLogs = ConcurrentHashMap.newKeySet(); private Executor syncExecutor; private Executor asyncExecutor; private VaultHook vaultHook = null; - - private final Set ignoringLogs = ConcurrentHashMap.newKeySet(); private LPConfiguration configuration; private UserManager userManager; private GroupManager groupManager; @@ -392,7 +404,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { c.addAll(getServer().getWorlds().stream() .map(World::getName) .map(s -> { - MutableContextSet set = new MutableContextSet(); + MutableContextSet set = MutableContextSet.create(); set.add("server", getConfiguration().getServer()); set.add("world", s); return set.makeImmutable(); @@ -406,7 +418,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { c.addAll(getServer().getWorlds().stream() .map(World::getName) .map(s -> { - MutableContextSet set = new MutableContextSet(); + MutableContextSet set = MutableContextSet.create(); set.add("server", getConfiguration().getVaultServer()); set.add("world", s); return set.makeImmutable(); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/WorldCalculator.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/WorldCalculator.java index 1ad58a803..f8b1a5332 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/WorldCalculator.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/WorldCalculator.java @@ -22,12 +22,15 @@ package me.lucko.luckperms.bukkit; -import com.google.common.collect.Maps; import lombok.Getter; import lombok.RequiredArgsConstructor; + +import com.google.common.collect.Maps; + import me.lucko.luckperms.api.context.ContextCalculator; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.common.LuckPermsPlugin; + import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/AttachmentProcessor.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/AttachmentProcessor.java index 636821b5f..1e114ca3d 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/AttachmentProcessor.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/AttachmentProcessor.java @@ -24,8 +24,10 @@ package me.lucko.luckperms.bukkit.calculators; import lombok.AllArgsConstructor; import lombok.Getter; + import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.common.calculators.PermissionProcessor; + import org.bukkit.permissions.PermissionAttachmentInfo; import java.util.Map; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/AutoOPListener.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/AutoOPListener.java index 239632621..e40a1a8b8 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/AutoOPListener.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/AutoOPListener.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.bukkit.calculators; import me.lucko.luckperms.api.context.ContextListener; import me.lucko.luckperms.bukkit.inject.Injector; import me.lucko.luckperms.bukkit.model.LPPermissible; + import org.bukkit.entity.Player; import java.util.Map; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/ChildProcessor.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/ChildProcessor.java index 1eecafd4b..a428c3a59 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/ChildProcessor.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/ChildProcessor.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.bukkit.calculators; import lombok.RequiredArgsConstructor; + import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.bukkit.model.ChildPermissionProvider; import me.lucko.luckperms.common.calculators.PermissionProcessor; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/DefaultsProcessor.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/DefaultsProcessor.java index 5eaf2fdbe..43282b8f7 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/DefaultsProcessor.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/DefaultsProcessor.java @@ -23,9 +23,11 @@ package me.lucko.luckperms.bukkit.calculators; import lombok.AllArgsConstructor; + import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.bukkit.model.DefaultsProvider; import me.lucko.luckperms.common.calculators.PermissionProcessor; + import org.bukkit.Bukkit; import org.bukkit.permissions.Permission; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/Injector.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/Injector.java index 87f709b7b..65e4116f6 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/Injector.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/Injector.java @@ -23,7 +23,9 @@ package me.lucko.luckperms.bukkit.inject; import lombok.experimental.UtilityClass; + import me.lucko.luckperms.bukkit.model.LPPermissible; + import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.permissions.Permissible; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java index 554efa297..2cdb4bb19 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java @@ -22,7 +22,13 @@ package me.lucko.luckperms.bukkit.migration; -import de.bananaco.bpermissions.api.*; +import de.bananaco.bpermissions.api.Calculable; +import de.bananaco.bpermissions.api.CalculableType; +import de.bananaco.bpermissions.api.Group; +import de.bananaco.bpermissions.api.Permission; +import de.bananaco.bpermissions.api.World; +import de.bananaco.bpermissions.api.WorldManager; + import me.lucko.luckperms.api.Logger; import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.common.LuckPermsPlugin; @@ -39,7 +45,11 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.util.*; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; import static me.lucko.luckperms.common.constants.Permission.MIGRATION; @@ -83,98 +93,6 @@ public class MigrationBPermissions extends SubCommand { } } - public MigrationBPermissions() { - super("bpermissions", "Migration from bPermissions", MIGRATION, Predicates.alwaysFalse(), null); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List args, String label) throws CommandException { - final Logger log = plugin.getLog(); - - WorldManager worldManager = WorldManager.getInstance(); - if (worldManager == null) { - log.severe("bPermissions Migration: Error -> bPermissions is not loaded."); - return CommandResult.STATE_ERROR; - } - - log.info("bPermissions Migration: Forcing the plugin to load all data. This could take a while."); - for (World world : worldManager.getAllWorlds()) { - Set users = getUsers(world); - if (users == null) { - log.severe("bPermissions Migration: Couldn't get a list of users."); - return CommandResult.FAILURE; - } - users.forEach(s -> world.loadOne(s, CalculableType.USER)); - } - - // Migrate one world at a time. - log.info("bPermissions Migration: Starting world migration."); - for (World world : worldManager.getAllWorlds()) { - log.info("bPermissions Migration: Migrating world: " + world.getName()); - - // Migrate all groups - log.info("bPermissions Migration: Starting group migration in world " + world.getName() + "."); - int groupCount = 0; - for (Calculable group : world.getAll(CalculableType.GROUP)) { - groupCount++; - String groupName = group.getName().toLowerCase(); - if (group.getName().equalsIgnoreCase(world.getDefaultGroup())) { - groupName = "default"; - } - - // Make a LuckPerms group for the one being migrated. - plugin.getStorage().createAndLoadGroup(groupName).join(); - me.lucko.luckperms.common.core.model.Group lpGroup = plugin.getGroupManager().getIfLoaded(groupName); - try { - LogEntry.build() - .actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName()) - .acted(lpGroup).action("create") - .build().submit(plugin); - } catch (Exception ex) { - ex.printStackTrace(); - } - - migrateHolder(plugin, world, group, lpGroup); - plugin.getStorage().saveGroup(lpGroup); - } - log.info("bPermissions Migration: Migrated " + groupCount + " groups in world " + world.getName() + "."); - - // Migrate all users - log.info("bPermissions Migration: Starting user migration in world " + world.getName() + "."); - int userCount = 0; - for (Calculable user : world.getAll(CalculableType.USER)) { - userCount++; - - // There is no mention of UUIDs in the API. I assume that name = uuid. idk? - UUID uuid; - try { - uuid = UUID.fromString(user.getName()); - } catch (IllegalArgumentException e) { - uuid = plugin.getUUID(user.getName()); - } - - if (uuid == null) { - log.info("bPermissions Migration: Unable to migrate user " + user.getName() + ". Unable to get UUID."); - continue; - } - - // Make a LuckPerms user for the one being migrated. - plugin.getStorage().loadUser(uuid, "null").join(); - User lpUser = plugin.getUserManager().get(uuid); - - migrateHolder(plugin, world, user, lpUser); - - plugin.getStorage().saveUser(lpUser); - plugin.getUserManager().cleanup(lpUser); - } - - log.info("bPermissions Migration: Migrated " + userCount + " users in world " + world.getName() + "."); - } - - log.info("bPermissions Migration: Success! Completed without any errors."); - return CommandResult.SUCCESS; - } - private static void migrateHolder(LuckPermsPlugin plugin, World world, Calculable c, PermissionHolder holder) { // Migrate the groups permissions in this world for (Permission p : c.getPermissions()) { @@ -252,4 +170,96 @@ public class MigrationBPermissions extends SubCommand { } } } + + public MigrationBPermissions() { + super("bpermissions", "Migration from bPermissions", MIGRATION, Predicates.alwaysFalse(), null); + } + + @Override + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List args, String label) throws CommandException { + final Logger log = plugin.getLog(); + + WorldManager worldManager = WorldManager.getInstance(); + if (worldManager == null) { + log.severe("bPermissions Migration: Error -> bPermissions is not loaded."); + return CommandResult.STATE_ERROR; + } + + log.info("bPermissions Migration: Forcing the plugin to load all data. This could take a while."); + for (World world : worldManager.getAllWorlds()) { + Set users = getUsers(world); + if (users == null) { + log.severe("bPermissions Migration: Couldn't get a list of users."); + return CommandResult.FAILURE; + } + users.forEach(s -> world.loadOne(s, CalculableType.USER)); + } + + // Migrate one world at a time. + log.info("bPermissions Migration: Starting world migration."); + for (World world : worldManager.getAllWorlds()) { + log.info("bPermissions Migration: Migrating world: " + world.getName()); + + // Migrate all groups + log.info("bPermissions Migration: Starting group migration in world " + world.getName() + "."); + int groupCount = 0; + for (Calculable group : world.getAll(CalculableType.GROUP)) { + groupCount++; + String groupName = group.getName().toLowerCase(); + if (group.getName().equalsIgnoreCase(world.getDefaultGroup())) { + groupName = "default"; + } + + // Make a LuckPerms group for the one being migrated. + plugin.getStorage().createAndLoadGroup(groupName).join(); + me.lucko.luckperms.common.core.model.Group lpGroup = plugin.getGroupManager().getIfLoaded(groupName); + try { + LogEntry.build() + .actor(Constants.getConsoleUUID()).actorName(Constants.getConsoleName()) + .acted(lpGroup).action("create") + .build().submit(plugin); + } catch (Exception ex) { + ex.printStackTrace(); + } + + migrateHolder(plugin, world, group, lpGroup); + plugin.getStorage().saveGroup(lpGroup); + } + log.info("bPermissions Migration: Migrated " + groupCount + " groups in world " + world.getName() + "."); + + // Migrate all users + log.info("bPermissions Migration: Starting user migration in world " + world.getName() + "."); + int userCount = 0; + for (Calculable user : world.getAll(CalculableType.USER)) { + userCount++; + + // There is no mention of UUIDs in the API. I assume that name = uuid. idk? + UUID uuid; + try { + uuid = UUID.fromString(user.getName()); + } catch (IllegalArgumentException e) { + uuid = plugin.getUUID(user.getName()); + } + + if (uuid == null) { + log.info("bPermissions Migration: Unable to migrate user " + user.getName() + ". Unable to get UUID."); + continue; + } + + // Make a LuckPerms user for the one being migrated. + plugin.getStorage().loadUser(uuid, "null").join(); + User lpUser = plugin.getUserManager().get(uuid); + + migrateHolder(plugin, world, user, lpUser); + + plugin.getStorage().saveUser(lpUser); + plugin.getUserManager().cleanup(lpUser); + } + + log.info("bPermissions Migration: Migrated " + userCount + " users in world " + world.getName() + "."); + } + + log.info("bPermissions Migration: Success! Completed without any errors."); + return CommandResult.SUCCESS; + } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java index aeddc9584..28a67c637 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java @@ -36,6 +36,7 @@ import me.lucko.luckperms.common.data.LogEntry; import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; + import org.anjocaido.groupmanager.GlobalGroups; import org.anjocaido.groupmanager.GroupManager; import org.anjocaido.groupmanager.data.Group; @@ -43,7 +44,11 @@ import org.anjocaido.groupmanager.data.User; import org.anjocaido.groupmanager.dataholder.WorldDataHolder; import org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder; -import java.util.*; +import java.util.AbstractMap; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; import java.util.stream.Collectors; public class MigrationGroupManager extends SubCommand { @@ -161,7 +166,7 @@ public class MigrationGroupManager extends SubCommand { UUID uuid; try { uuid = UUID.fromString(user.getUUID()); - } catch (IllegalArgumentException e){ + } catch (IllegalArgumentException e) { continue; } @@ -272,11 +277,13 @@ public class MigrationGroupManager extends SubCommand { if (primaryGroup != null) { try { user.setPermission("group." + primaryGroup, true); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } user.setPrimaryGroup(primaryGroup); try { user.unsetPermission("group.default"); - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } } plugin.getStorage().saveUser(user); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java index 02644e0c9..43dc68b77 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java @@ -38,17 +38,18 @@ import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.data.LogEntry; import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; -import ru.tehkode.permissions.NativeInterface; -import ru.tehkode.permissions.PermissionGroup; -import ru.tehkode.permissions.PermissionManager; -import ru.tehkode.permissions.PermissionUser; -import ru.tehkode.permissions.bukkit.PermissionsEx; import java.lang.reflect.Field; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; +import ru.tehkode.permissions.NativeInterface; +import ru.tehkode.permissions.PermissionGroup; +import ru.tehkode.permissions.PermissionManager; +import ru.tehkode.permissions.PermissionUser; +import ru.tehkode.permissions.bukkit.PermissionsEx; + public class MigrationPermissionsEx extends SubCommand { public MigrationPermissionsEx() { super("permissionsex", "Migration from PermissionsEx", Permission.MIGRATION, Predicates.alwaysFalse(), @@ -96,7 +97,7 @@ public class MigrationPermissionsEx extends SubCommand { for (PermissionGroup group : manager.getGroupList()) { int groupWeight = group.getWeight() * -1; - groupCount ++; + groupCount++; maxGroupWeight = Math.max(maxGroupWeight, groupWeight); final String name = group.getName().toLowerCase(); @@ -380,7 +381,8 @@ public class MigrationPermissionsEx extends SubCommand { if (primary != null) { try { lpUser.setPermission("group." + primary.toLowerCase(), true); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } lpUser.setPrimaryGroup(primary); } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java index eb014a325..6b9a3fd2e 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java @@ -22,10 +22,17 @@ package me.lucko.luckperms.bukkit.migration; -import com.github.cheesesoftware.PowerfulPermsAPI.*; +import lombok.Cleanup; + +import com.github.cheesesoftware.PowerfulPermsAPI.CachedGroup; +import com.github.cheesesoftware.PowerfulPermsAPI.Group; +import com.github.cheesesoftware.PowerfulPermsAPI.Permission; +import com.github.cheesesoftware.PowerfulPermsAPI.PermissionManager; +import com.github.cheesesoftware.PowerfulPermsAPI.PowerfulPermsPlugin; +import com.github.cheesesoftware.PowerfulPermsAPI.ResultRunnable; import com.google.common.util.concurrent.ListenableFuture; import com.zaxxer.hikari.HikariDataSource; -import lombok.Cleanup; + import me.lucko.luckperms.api.Logger; import me.lucko.luckperms.api.data.Callback; import me.lucko.luckperms.bukkit.migration.utils.LPResultRunnable; @@ -48,7 +55,13 @@ import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.PreparedStatement; import java.sql.ResultSet; -import java.util.*; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; @@ -77,25 +90,29 @@ public class MigrationPowerfulPerms extends SubCommand { try { Class.forName("com.github.cheesesoftware.PowerfulPermsAPI.ResponseRunnable"); legacy = true; - } catch (ClassNotFoundException ignored) {} + } catch (ClassNotFoundException ignored) { + } if (legacy) { try { getPlayerPermissionsMethod = PermissionManager.class.getMethod("getPlayerOwnPermissions", UUID.class, ResultRunnable.class); getPlayerPermissionsMethod.setAccessible(true); - } catch (NoSuchMethodException ignored) {} + } catch (NoSuchMethodException ignored) { + } } else { try { getPlayerPermissionsMethod = PermissionManager.class.getMethod("getPlayerOwnPermissions", UUID.class); getPlayerPermissionsMethod.setAccessible(true); - } catch (NoSuchMethodException ignored) {} + } catch (NoSuchMethodException ignored) { + } } try { getGroupMethod = CachedGroup.class.getMethod("getGroup"); getGroupMethod.setAccessible(true); superLegacy = true; - } catch (NoSuchMethodException ignored) {} + } catch (NoSuchMethodException ignored) { + } if (!legacy) { try { @@ -119,29 +136,6 @@ public class MigrationPowerfulPerms extends SubCommand { } } - - public MigrationPowerfulPerms() { - super("powerfulperms", "Migration from PowerfulPerms", MIGRATION, Predicates.not(5), - Arg.list( - Arg.create("address", true, "the address of the PP database"), - Arg.create("database", true, "the name of the PP database"), - Arg.create("username", true, "the username to log into the DB"), - Arg.create("password", true, "the password to log into the DB"), - Arg.create("db table", true, "the name of the PP table where player data is stored") - ) - ); - } - - @Override - public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List args, String label) throws CommandException { - try { - return run(plugin, args); - } catch (Throwable t) { - t.printStackTrace(); - return CommandResult.FAILURE; - } - } - private static void getPlayerPermissions(PermissionManager manager, UUID uuid, Callback> callback) { if (legacy) { try { @@ -178,6 +172,28 @@ public class MigrationPowerfulPerms extends SubCommand { } } + public MigrationPowerfulPerms() { + super("powerfulperms", "Migration from PowerfulPerms", MIGRATION, Predicates.not(5), + Arg.list( + Arg.create("address", true, "the address of the PP database"), + Arg.create("database", true, "the name of the PP database"), + Arg.create("username", true, "the username to log into the DB"), + Arg.create("password", true, "the password to log into the DB"), + Arg.create("db table", true, "the name of the PP table where player data is stored") + ) + ); + } + + @Override + public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List args, String label) throws CommandException { + try { + return run(plugin, args); + } catch (Throwable t) { + t.printStackTrace(); + return CommandResult.FAILURE; + } + } + private CommandResult run(LuckPermsPlugin plugin, List args) { final Logger log = plugin.getLog(); if (!plugin.isPluginLoaded("PowerfulPerms")) { diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java index 2c7b85da7..95b7af4ac 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java @@ -36,6 +36,7 @@ import me.lucko.luckperms.common.core.model.Track; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; + import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService; import org.tyrannyofheaven.bukkit.zPermissions.dao.PermissionService; import org.tyrannyofheaven.bukkit.zPermissions.model.EntityMetadata; @@ -122,11 +123,13 @@ public class MigrationZPermissions extends SubCommand { if (e.getWorld() != null) { try { group.setPermission(e.getPermission(), true, "global", e.getWorld().getName()); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } } else { try { group.setPermission(e.getPermission(), true); // TODO handle negated. - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } } } @@ -138,7 +141,8 @@ public class MigrationZPermissions extends SubCommand { try { group.setPermission("group." + inheritance.getParent(), true); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } } for (EntityMetadata metadata : entity.getMetadata()) { diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/utils/LPResultRunnable.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/utils/LPResultRunnable.java index 769367599..10366e0a1 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/utils/LPResultRunnable.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/utils/LPResultRunnable.java @@ -26,6 +26,7 @@ import com.github.cheesesoftware.PowerfulPermsAPI.ResultRunnable; /** * Overrides the default ResultRunnable, callbacks will always run in the same thread. (an async one, hopefully.) + * * @param type */ public abstract class LPResultRunnable extends ResultRunnable { diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/ChildPermissionProvider.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/ChildPermissionProvider.java index 1c1b5fc2f..139b34f62 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/ChildPermissionProvider.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/ChildPermissionProvider.java @@ -22,9 +22,11 @@ package me.lucko.luckperms.bukkit.model; +import lombok.Getter; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; -import lombok.Getter; + import org.bukkit.Bukkit; import org.bukkit.permissions.Permission; @@ -34,6 +36,24 @@ import java.util.Map; public class ChildPermissionProvider { + private static void resolveChildren(Map accumulator, Map children, boolean invert) { + for (Map.Entry e : children.entrySet()) { + if (accumulator.containsKey(e.getKey())) { + continue; // Prevent infinite loops + } + + Permission perm = Bukkit.getServer().getPluginManager().getPermission(e.getKey()); + boolean value = e.getValue() ^ invert; + String lName = e.getKey().toLowerCase(); + + accumulator.put(lName, value); + + if (perm != null) { + resolveChildren(accumulator, perm.getChildren(), !value); + } + } + } + @Getter private ImmutableMap, ImmutableMap> permissions = ImmutableMap.of(); @@ -54,22 +74,4 @@ public class ChildPermissionProvider { this.permissions = ImmutableMap.copyOf(permissions); } - - private static void resolveChildren(Map accumulator, Map children, boolean invert) { - for (Map.Entry e : children.entrySet()) { - if (accumulator.containsKey(e.getKey())) { - continue; // Prevent infinite loops - } - - Permission perm = Bukkit.getServer().getPluginManager().getPermission(e.getKey()); - boolean value = e.getValue() ^ invert; - String lName = e.getKey().toLowerCase(); - - accumulator.put(lName, value); - - if (perm != null) { - resolveChildren(accumulator, perm.getChildren(), !value); - } - } - } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/DefaultsProvider.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/DefaultsProvider.java index be5cd59c6..62e3ad734 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/DefaultsProvider.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/DefaultsProvider.java @@ -22,10 +22,13 @@ package me.lucko.luckperms.bukkit.model; -import com.google.common.collect.ImmutableMap; import lombok.AllArgsConstructor; import lombok.Getter; + +import com.google.common.collect.ImmutableMap; + import me.lucko.luckperms.api.Tristate; + import org.bukkit.Bukkit; import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permission; @@ -40,38 +43,6 @@ import java.util.Set; public class DefaultsProvider { - private final DummyPermissible opDummy = new DummyPermissible(this::refreshOp); - private final DummyPermissible nonOpDummy = new DummyPermissible(this::refreshNonOp); - - @Getter - private Map opDefaults = ImmutableMap.of(); - - @Getter - private Map nonOpDefaults = ImmutableMap.of(); - - public void refresh() { - refreshOp(); - refreshNonOp(); - } - - private void refreshOp() { - unregisterDefaults(opDefaults, opDummy); - - Map builder = new HashMap<>(); - calculateDefaults(builder, opDummy, true); - - opDefaults = ImmutableMap.copyOf(builder); - } - - private void refreshNonOp() { - unregisterDefaults(nonOpDefaults, nonOpDummy); - - Map builder = new HashMap<>(); - calculateDefaults(builder, nonOpDummy, false); - - nonOpDefaults = ImmutableMap.copyOf(builder); - } - private static void unregisterDefaults(Map map, DummyPermissible p) { Set perms = map.keySet(); @@ -110,6 +81,36 @@ public class DefaultsProvider { } } + @Getter + private Map opDefaults = ImmutableMap.of(); + private final DummyPermissible opDummy = new DummyPermissible(this::refreshOp); + @Getter + private Map nonOpDefaults = ImmutableMap.of(); + private final DummyPermissible nonOpDummy = new DummyPermissible(this::refreshNonOp); + + public void refresh() { + refreshOp(); + refreshNonOp(); + } + + private void refreshOp() { + unregisterDefaults(opDefaults, opDummy); + + Map builder = new HashMap<>(); + calculateDefaults(builder, opDummy, true); + + opDefaults = ImmutableMap.copyOf(builder); + } + + private void refreshNonOp() { + unregisterDefaults(nonOpDefaults, nonOpDummy); + + Map builder = new HashMap<>(); + calculateDefaults(builder, nonOpDummy, false); + + nonOpDefaults = ImmutableMap.copyOf(builder); + } + public Tristate hasDefault(String permission, boolean isOp) { Map map = isOp ? opDefaults : nonOpDefaults; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java index 1e6e8473d..002fe7664 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java @@ -24,16 +24,27 @@ package me.lucko.luckperms.bukkit.model; import lombok.Getter; import lombok.NonNull; + import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.bukkit.LPBukkitPlugin; import me.lucko.luckperms.common.core.model.User; + import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import org.bukkit.permissions.*; +import org.bukkit.permissions.PermissibleBase; +import org.bukkit.permissions.Permission; +import org.bukkit.permissions.PermissionAttachment; +import org.bukkit.permissions.PermissionAttachmentInfo; +import org.bukkit.permissions.PermissionRemovedExecutor; import org.bukkit.plugin.Plugin; -import java.util.*; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.logging.Level; import java.util.stream.Collectors; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java index b32209042..4fb7f2358 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.bukkit.vault; import lombok.NonNull; + import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.caching.MetaData; @@ -35,6 +36,7 @@ import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.utils.ExtractedContexts; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; + import net.milkbowl.vault.chat.Chat; import java.util.HashMap; @@ -92,7 +94,8 @@ public class VaultChatHook extends Chat { toRemove.forEach(n -> { try { holder.unsetPermission(n); - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } }); Node.Builder metaNode = NodeFactory.makeMetaNode(node, value).setValue(true); @@ -105,7 +108,8 @@ public class VaultChatHook extends Chat { try { holder.setPermission(metaNode.build()); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } perms.save(holder); }); @@ -131,7 +135,8 @@ public class VaultChatHook extends Chat { try { holder.setPermission(node.build()); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } perms.save(holder); }); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultHook.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultHook.java index d26a75d97..ec6dc3062 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultHook.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultHook.java @@ -23,9 +23,12 @@ package me.lucko.luckperms.bukkit.vault; import lombok.Getter; + import me.lucko.luckperms.bukkit.LPBukkitPlugin; + import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.permission.Permission; + import org.bukkit.plugin.ServicePriority; import org.bukkit.plugin.ServicesManager; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java index 4f8468217..082be92b6 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java @@ -26,6 +26,7 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.NonNull; import lombok.Setter; + import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.LocalizedNode; import me.lucko.luckperms.api.Node; @@ -38,6 +39,7 @@ import me.lucko.luckperms.common.core.model.PermissionHolder; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; + import net.milkbowl.vault.permission.Permission; import java.util.HashMap; @@ -92,8 +94,9 @@ public class VaultPermissionHook extends Permission { /** * Generic method to add a permission to a holder - * @param world the world to add in - * @param holder the holder to add the permission to + * + * @param world the world to add in + * @param holder the holder to add the permission to * @param permission the permission to add */ private void add(String world, PermissionHolder holder, String permission) { @@ -103,15 +106,17 @@ public class VaultPermissionHook extends Permission { } else { holder.setPermission(permission, true, server); } - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } save(holder); } /** * Generic method to remove a permission from a holder - * @param world the world to remove in - * @param holder the holder to remove the permission from + * + * @param world the world to remove in + * @param holder the holder to remove the permission from * @param permission the permission to remove */ private void remove(String world, PermissionHolder holder, String permission) { @@ -121,13 +126,15 @@ public class VaultPermissionHook extends Permission { } else { holder.unsetPermission(permission, server); } - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } save(holder); } /** * Utility method for saving a user or group + * * @param holder the holder instance */ void save(PermissionHolder holder) { @@ -263,7 +270,8 @@ public class VaultPermissionHook extends Permission { } else { user.setInheritGroup(group, server); } - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } save(user); }); return true; @@ -287,7 +295,8 @@ public class VaultPermissionHook extends Permission { } else { user.unsetInheritGroup(group, server); } - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } save(user); }); return true; diff --git a/bungee/pom.xml b/bungee/pom.xml index 476a54a6d..2287aee1e 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -1,11 +1,11 @@ - luckperms me.lucko.luckperms - 2.15-SNAPSHOT + 2.16-SNAPSHOT 4.0.0 diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BackendServerCalculator.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BackendServerCalculator.java index 69c57644a..96ffb9393 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BackendServerCalculator.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BackendServerCalculator.java @@ -23,8 +23,10 @@ package me.lucko.luckperms.bungee; import com.google.common.collect.Maps; + import me.lucko.luckperms.api.context.ContextCalculator; import me.lucko.luckperms.api.context.MutableContextSet; + import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.ServerSwitchEvent; import net.md_5.bungee.api.plugin.Listener; @@ -35,6 +37,10 @@ import java.util.Map; public class BackendServerCalculator extends ContextCalculator implements Listener { private static final String WORLD_KEY = "world"; + private static String getServer(ProxiedPlayer player) { + return player.getServer() == null ? null : (player.getServer().getInfo() == null ? null : player.getServer().getInfo().getName()); + } + @Override public MutableContextSet giveApplicableContext(ProxiedPlayer subject, MutableContextSet accumulator) { String server = getServer(subject); @@ -60,8 +66,4 @@ public class BackendServerCalculator extends ContextCalculator im public void onPlayerServerSwitch(ServerSwitchEvent e) { pushUpdate(e.getPlayer(), Maps.immutableEntry("null", "null"), Maps.immutableEntry(WORLD_KEY, getServer(e.getPlayer()))); } - - private static String getServer(ProxiedPlayer player) { - return player.getServer() == null ? null : (player.getServer().getInfo() == null ? null : player.getServer().getInfo().getName()); - } } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCalculatorFactory.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCalculatorFactory.java index d8ca41326..224b1c69f 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCalculatorFactory.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCalculatorFactory.java @@ -22,8 +22,10 @@ package me.lucko.luckperms.bungee; -import com.google.common.collect.ImmutableList; import lombok.AllArgsConstructor; + +import com.google.common.collect.ImmutableList; + import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.common.calculators.AbstractCalculatorFactory; import me.lucko.luckperms.common.calculators.PermissionCalculator; diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCommand.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCommand.java index 4f086b601..609dbad2d 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCommand.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCommand.java @@ -24,9 +24,11 @@ package me.lucko.luckperms.bungee; import com.google.common.base.Joiner; import com.google.common.base.Splitter; + import me.lucko.luckperms.common.commands.CommandManager; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.constants.Patterns; + import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.plugin.Command; import net.md_5.bungee.api.plugin.TabExecutor; diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfig.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfig.java index ec7d1d34d..11fd5ddf1 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfig.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfig.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.bungee; import me.lucko.luckperms.common.config.AbstractConfiguration; + import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.ConfigurationProvider; import net.md_5.bungee.config.YamlConfiguration; diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java index 8661a2f11..d3b007fe7 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java @@ -29,6 +29,7 @@ import me.lucko.luckperms.common.core.UuidCache; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.defaults.Rule; import me.lucko.luckperms.common.utils.AbstractListener; + import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeSenderFactory.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeSenderFactory.java index f3c1858dd..40123ebd2 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeSenderFactory.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeSenderFactory.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.bungee; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.sender.SenderFactory; import me.lucko.luckperms.common.constants.Constants; + import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java index f8de87f8d..eee980e53 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.bungee; import lombok.Getter; + import me.lucko.luckperms.ApiHandler; import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Logger; @@ -52,7 +53,12 @@ import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.storage.StorageFactory; import me.lucko.luckperms.common.tasks.ExpireTemporaryTask; import me.lucko.luckperms.common.tasks.UpdateTask; -import me.lucko.luckperms.common.utils.*; +import me.lucko.luckperms.common.utils.BufferedRequest; +import me.lucko.luckperms.common.utils.DebugHandler; +import me.lucko.luckperms.common.utils.LocaleManager; +import me.lucko.luckperms.common.utils.LogFactory; +import me.lucko.luckperms.common.utils.PermissionCache; + import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Plugin; @@ -69,9 +75,8 @@ import java.util.stream.Collectors; @Getter public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { - private Executor executor; - private final Set ignoringLogs = ConcurrentHashMap.newKeySet(); + private Executor executor; private LPConfiguration configuration; private UserManager userManager; private GroupManager groupManager; @@ -278,7 +283,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { c.addAll(getProxy().getServers().values().stream() .map(ServerInfo::getName) .map(s -> { - MutableContextSet set = new MutableContextSet(); + MutableContextSet set = MutableContextSet.create(); set.add("server", getConfiguration().getServer()); set.add("world", s); return set.makeImmutable(); diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java b/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java index 03374e254..71195b3da 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java @@ -34,7 +34,12 @@ import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.data.LogEntry; import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; -import net.alpenblock.bungeeperms.*; + +import net.alpenblock.bungeeperms.BungeePerms; +import net.alpenblock.bungeeperms.Group; +import net.alpenblock.bungeeperms.Server; +import net.alpenblock.bungeeperms.User; +import net.alpenblock.bungeeperms.World; import java.util.List; import java.util.Map; diff --git a/common/pom.xml b/common/pom.xml index ca9baa2ba..946e8036d 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -1,11 +1,11 @@ - luckperms me.lucko.luckperms - 2.15-SNAPSHOT + 2.16-SNAPSHOT 4.0.0 diff --git a/common/src/main/java/me/lucko/luckperms/common/LuckPermsPlugin.java b/common/src/main/java/me/lucko/luckperms/common/LuckPermsPlugin.java index 2bbbcd57b..9d0d8a699 100644 --- a/common/src/main/java/me/lucko/luckperms/common/LuckPermsPlugin.java +++ b/common/src/main/java/me/lucko/luckperms/common/LuckPermsPlugin.java @@ -47,7 +47,11 @@ import me.lucko.luckperms.common.utils.LocaleManager; import me.lucko.luckperms.common.utils.PermissionCache; import java.io.File; -import java.util.*; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.Executor; /** @@ -59,72 +63,84 @@ public interface LuckPermsPlugin { /** * Gets the user manager instance for the platform + * * @return the user manager */ UserManager getUserManager(); /** * Gets the group manager instance for the platform + * * @return the group manager */ GroupManager getGroupManager(); /** * Gets the track manager instance for the platform + * * @return the track manager */ TrackManager getTrackManager(); /** * Gets the plugin's configuration + * * @return the plugin config */ LPConfiguration getConfiguration(); /** * Gets the primary data storage instance. This is likely to be wrapped with extra layers for caching, etc. + * * @return the storage handler instance */ Storage getStorage(); /** * Gets the redis messaging instance if present. Could return null if redis is not enabled. + * * @return the redis messaging service */ RedisMessaging getRedisMessaging(); /** * Gets a wrapped logger instance for the platform. + * * @return the plugin's logger */ Logger getLog(); /** * Gets the UUID caching store for the platform + * * @return the uuid cache */ UuidCache getUuidCache(); /** * Returns the class implementing the LuckPermsAPI on this platform. + * * @return the api */ ApiProvider getApiProvider(); /** * Gets the importer instance + * * @return the importer */ Importer getImporter(); /** * Gets the consecutive command executor instance + * * @return the consecutive executor */ ConsecutiveExecutor getConsecutiveExecutor(); /** * Gets the instance providing locale translations for the plugin + * * @return the locale manager */ LocaleManager getLocaleManager(); @@ -132,76 +148,89 @@ public interface LuckPermsPlugin { /** * Gets the context manager. * This object handles context accumulation for all players on the platform. + * * @return the context manager */ ContextManager getContextManager(); /** * Gets the class responsible for constructing PermissionCalculators on this platform. + * * @return the permission calculator factory */ CalculatorFactory getCalculatorFactory(); /** * Gets the verbose debug handler instance. + * * @return the debug handler instance */ DebugHandler getDebugHandler(); /** * Gets the permission caching instance for the platform. + * * @return the permission cache instance */ PermissionCache getPermissionCache(); /** * Execute a runnable asynchronously + * * @param r the task to run */ void doAsync(Runnable r); /** * Execute a runnable synchronously + * * @param r the task to run */ void doSync(Runnable r); Executor getSyncExecutor(); + Executor getAsyncExecutor(); /** * Execute a runnable asynchronously on a loop - * @param r the task to run + * + * @param r the task to run * @param interval the time between runs in ticks */ void doAsyncRepeating(Runnable r, long interval); /** * Gets a string of the plugin's version + * * @return the version of the plugin */ String getVersion(); /** * Gets the platform type this instance of LuckPerms is running on. + * * @return the platform type */ PlatformType getType(); /** * Gets the plugins main directory + * * @return the main plugin directory */ File getMainDir(); /** * Gets the plugins main data storage directory + * * @return the platforms data folder */ File getDataFolder(); /** * Returns a colored string indicating the status of a player + * * @param uuid The player's uuid * @return a formatted status string */ @@ -213,6 +242,7 @@ public interface LuckPermsPlugin { /** * Gets a player object linked to this User. The returned object must be the same type * as the instance used in the platforms {@link ContextManager} + * * @param user the user instance * @return a player object, or null, if one couldn't be found. */ @@ -220,6 +250,7 @@ public interface LuckPermsPlugin { /** * Gets a calculated context instance for the user using the rules of the platform. + * * @param user the user instance * @return a contexts object, or null if one couldn't be generated */ @@ -227,24 +258,28 @@ public interface LuckPermsPlugin { /** * Gets the number of users online on the platform + * * @return the number of users */ int getPlayerCount(); /** * Gets the usernames of the users online on the platform + * * @return a {@link List} of usernames */ List getPlayerList(); /** * Gets the UUIDs of the users online on the platform + * * @return a {@link Set} of UUIDs */ Set getOnlinePlayers(); /** * Checks if a user is online + * * @param external the users external uuid * @return true if the user is online */ @@ -252,18 +287,21 @@ public interface LuckPermsPlugin { /** * Gets a list of online Senders on the platform + * * @return a {@link List} of senders online on the platform */ List getSenders(); /** * Gets the console. + * * @return the console sender of the instance */ Sender getConsoleSender(); /** * Gets a set of Contexts that should be pre-processed in advance + * * @param op if the user being processed is op * @return a set of contexts */ @@ -275,6 +313,7 @@ public interface LuckPermsPlugin { /** * Gets a map of extra information to be shown in the info command + * * @return a map of options, or null */ default LinkedHashMap getExtraInfo() { @@ -283,12 +322,14 @@ public interface LuckPermsPlugin { /** * Gets a set of players ignoring logging output + * * @return a {@link Set} of {@link UUID}s */ Set getIgnoringLogs(); /** * Gets a loaded plugins instance from the platform + * * @param name the name of the plugin * @return a plugin instance */ @@ -296,6 +337,7 @@ public interface LuckPermsPlugin { /** * Gets a provided service from the platform. + * * @param clazz the class of the service * @return the service instance, if it is provided for */ @@ -303,6 +345,7 @@ public interface LuckPermsPlugin { /** * Gets the UUID of a player. Used as a backup for migration + * * @param playerName the players name * @return a uuid if found, or null if not */ @@ -310,6 +353,7 @@ public interface LuckPermsPlugin { /** * Checks if a plugin is loaded on the platform + * * @param name the name of the plugin * @return true if the plugin is loaded */ @@ -317,6 +361,7 @@ public interface LuckPermsPlugin { /** * Gets the update task buffer of the platform, used for scheduling and running update tasks. + * * @return the update task buffer instance */ BufferedRequest getUpdateTaskBuffer(); 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 988f6bf9a..821fa1d6f 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 @@ -22,16 +22,37 @@ package me.lucko.luckperms.common.api; -import com.google.common.eventbus.EventBus; import lombok.AllArgsConstructor; import lombok.NonNull; -import me.lucko.luckperms.api.*; + +import com.google.common.eventbus.EventBus; + +import me.lucko.luckperms.api.Contexts; +import me.lucko.luckperms.api.Datastore; +import me.lucko.luckperms.api.Group; +import me.lucko.luckperms.api.LPConfiguration; +import me.lucko.luckperms.api.Logger; +import me.lucko.luckperms.api.LuckPermsApi; +import me.lucko.luckperms.api.MessagingService; +import me.lucko.luckperms.api.Node; +import me.lucko.luckperms.api.PlatformType; +import me.lucko.luckperms.api.Storage; +import me.lucko.luckperms.api.Track; +import me.lucko.luckperms.api.User; +import me.lucko.luckperms.api.UuidCache; import me.lucko.luckperms.api.context.ContextListener; import me.lucko.luckperms.api.context.IContextCalculator; import me.lucko.luckperms.api.event.LPEvent; import me.lucko.luckperms.api.event.LPListener; import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.api.internal.*; +import me.lucko.luckperms.common.api.internal.DatastoreLink; +import me.lucko.luckperms.common.api.internal.GroupLink; +import me.lucko.luckperms.common.api.internal.LPConfigurationLink; +import me.lucko.luckperms.common.api.internal.StorageLink; +import me.lucko.luckperms.common.api.internal.TrackLink; +import me.lucko.luckperms.common.api.internal.UserLink; +import me.lucko.luckperms.common.api.internal.Utils; +import me.lucko.luckperms.common.api.internal.UuidCacheLink; import me.lucko.luckperms.common.core.NodeBuilder; import me.lucko.luckperms.common.core.UserIdentifier; @@ -71,7 +92,7 @@ public class ApiProvider implements LuckPermsApi { @Override public double getApiVersion() { - return 2.15; + return 2.16; } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/DatastoreLink.java b/common/src/main/java/me/lucko/luckperms/common/api/internal/DatastoreLink.java index c962db5fb..9d2919d49 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/DatastoreLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/internal/DatastoreLink.java @@ -24,7 +24,13 @@ package me.lucko.luckperms.common.api.internal; import lombok.AllArgsConstructor; import lombok.NonNull; -import me.lucko.luckperms.api.*; + +import me.lucko.luckperms.api.Datastore; +import me.lucko.luckperms.api.Group; +import me.lucko.luckperms.api.Log; +import me.lucko.luckperms.api.LogEntry; +import me.lucko.luckperms.api.Track; +import me.lucko.luckperms.api.User; import me.lucko.luckperms.api.data.Callback; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.storage.Storage; @@ -33,7 +39,11 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.CompletableFuture; -import static me.lucko.luckperms.common.api.internal.Utils.*; +import static me.lucko.luckperms.common.api.internal.Utils.checkGroup; +import static me.lucko.luckperms.common.api.internal.Utils.checkName; +import static me.lucko.luckperms.common.api.internal.Utils.checkTrack; +import static me.lucko.luckperms.common.api.internal.Utils.checkUser; +import static me.lucko.luckperms.common.api.internal.Utils.checkUsername; /** * Provides a link between {@link Datastore} and {@link Storage} @@ -104,7 +114,7 @@ public class DatastoreLink implements Datastore { @Override public void loadOrCreateUser(@NonNull UUID uuid, @NonNull String username, Callback callback) { - registerCallback(master.force().loadUser(uuid, checkUsername(username)) , callback); + registerCallback(master.force().loadUser(uuid, checkUsername(username)), callback); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/GroupLink.java b/common/src/main/java/me/lucko/luckperms/common/api/internal/GroupLink.java index 16e4c8512..77f878202 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/GroupLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/internal/GroupLink.java @@ -26,13 +26,16 @@ import lombok.AccessLevel; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NonNull; + import me.lucko.luckperms.api.Group; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; import java.util.List; -import static me.lucko.luckperms.common.api.internal.Utils.*; +import static me.lucko.luckperms.common.api.internal.Utils.checkGroup; +import static me.lucko.luckperms.common.api.internal.Utils.checkServer; +import static me.lucko.luckperms.common.api.internal.Utils.checkTime; /** * Provides a link between {@link Group} and {@link me.lucko.luckperms.common.core.model.Group} diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/LPConfigurationLink.java b/common/src/main/java/me/lucko/luckperms/common/api/internal/LPConfigurationLink.java index cc3629758..2003ffa85 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/LPConfigurationLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/internal/LPConfigurationLink.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.api.internal; import lombok.AllArgsConstructor; + import me.lucko.luckperms.api.LPConfiguration; import me.lucko.luckperms.api.data.DatastoreConfiguration; import me.lucko.luckperms.api.data.MySQLConfiguration; diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/LogLink.java b/common/src/main/java/me/lucko/luckperms/common/api/internal/LogLink.java index 45227a0e4..725cf08b9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/LogLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/internal/LogLink.java @@ -24,6 +24,7 @@ package me.lucko.luckperms.common.api.internal; import lombok.AllArgsConstructor; import lombok.NonNull; + import me.lucko.luckperms.api.Log; import me.lucko.luckperms.api.LogEntry; @@ -39,7 +40,7 @@ import static me.lucko.luckperms.common.api.internal.Utils.checkName; @AllArgsConstructor public class LogLink implements Log { private final me.lucko.luckperms.common.data.Log master; - + @Override public SortedSet getContent() { return master.getContent(); diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/PermissionHolderLink.java b/common/src/main/java/me/lucko/luckperms/common/api/internal/PermissionHolderLink.java index 74b345c45..e83f18dda 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/PermissionHolderLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/internal/PermissionHolderLink.java @@ -24,15 +24,28 @@ package me.lucko.luckperms.common.api.internal; import lombok.AllArgsConstructor; import lombok.NonNull; -import me.lucko.luckperms.api.*; + +import me.lucko.luckperms.api.Contexts; +import me.lucko.luckperms.api.LocalizedNode; +import me.lucko.luckperms.api.Node; +import me.lucko.luckperms.api.PermissionHolder; +import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.common.utils.ExtractedContexts; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; -import java.util.*; +import java.util.AbstractMap; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; -import static me.lucko.luckperms.common.api.internal.Utils.*; +import static me.lucko.luckperms.common.api.internal.Utils.checkNode; +import static me.lucko.luckperms.common.api.internal.Utils.checkServer; +import static me.lucko.luckperms.common.api.internal.Utils.checkTime; import static me.lucko.luckperms.common.core.model.PermissionHolder.exportToLegacy; /** diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/StorageLink.java b/common/src/main/java/me/lucko/luckperms/common/api/internal/StorageLink.java index 7dbee6bab..96f5d241d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/StorageLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/internal/StorageLink.java @@ -24,7 +24,13 @@ package me.lucko.luckperms.common.api.internal; import lombok.AllArgsConstructor; import lombok.NonNull; -import me.lucko.luckperms.api.*; + +import me.lucko.luckperms.api.Group; +import me.lucko.luckperms.api.Log; +import me.lucko.luckperms.api.LogEntry; +import me.lucko.luckperms.api.Storage; +import me.lucko.luckperms.api.Track; +import me.lucko.luckperms.api.User; import me.lucko.luckperms.common.LuckPermsPlugin; import java.util.Set; @@ -32,7 +38,11 @@ import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; -import static me.lucko.luckperms.common.api.internal.Utils.*; +import static me.lucko.luckperms.common.api.internal.Utils.checkGroup; +import static me.lucko.luckperms.common.api.internal.Utils.checkName; +import static me.lucko.luckperms.common.api.internal.Utils.checkTrack; +import static me.lucko.luckperms.common.api.internal.Utils.checkUser; +import static me.lucko.luckperms.common.api.internal.Utils.checkUsername; /** * Provides a link between {@link Storage} and {@link me.lucko.luckperms.common.storage.Storage} diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/TrackLink.java b/common/src/main/java/me/lucko/luckperms/common/api/internal/TrackLink.java index c1d5d7004..5ab4589ab 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/TrackLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/internal/TrackLink.java @@ -26,6 +26,7 @@ import lombok.AccessLevel; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NonNull; + import me.lucko.luckperms.api.Group; import me.lucko.luckperms.api.Track; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/UserLink.java b/common/src/main/java/me/lucko/luckperms/common/api/internal/UserLink.java index f99e3a239..1327fafa5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/UserLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/internal/UserLink.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.common.api.internal; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NonNull; + import me.lucko.luckperms.api.Group; import me.lucko.luckperms.api.User; import me.lucko.luckperms.api.caching.UserData; @@ -35,7 +36,9 @@ import java.util.List; import java.util.Optional; import java.util.UUID; -import static me.lucko.luckperms.common.api.internal.Utils.*; +import static me.lucko.luckperms.common.api.internal.Utils.checkGroup; +import static me.lucko.luckperms.common.api.internal.Utils.checkServer; +import static me.lucko.luckperms.common.api.internal.Utils.checkTime; /** * Provides a link between {@link User} and {@link me.lucko.luckperms.common.core.model.User} diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/Utils.java b/common/src/main/java/me/lucko/luckperms/common/api/internal/Utils.java index 37adbf3cd..cfa1a870e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/Utils.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/internal/Utils.java @@ -22,8 +22,10 @@ package me.lucko.luckperms.common.api.internal; -import com.google.common.base.Preconditions; import lombok.experimental.UtilityClass; + +import com.google.common.base.Preconditions; + import me.lucko.luckperms.api.Group; import me.lucko.luckperms.api.Track; import me.lucko.luckperms.api.User; diff --git a/common/src/main/java/me/lucko/luckperms/common/api/internal/UuidCacheLink.java b/common/src/main/java/me/lucko/luckperms/common/api/internal/UuidCacheLink.java index e2419bd9f..8a38080f5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/internal/UuidCacheLink.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/internal/UuidCacheLink.java @@ -24,6 +24,7 @@ package me.lucko.luckperms.common.api.internal; import lombok.AllArgsConstructor; import lombok.NonNull; + import me.lucko.luckperms.api.UuidCache; import java.util.UUID; diff --git a/common/src/main/java/me/lucko/luckperms/common/caching/MetaCache.java b/common/src/main/java/me/lucko/luckperms/common/caching/MetaCache.java index 4c102f576..eda4c37d5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/caching/MetaCache.java +++ b/common/src/main/java/me/lucko/luckperms/common/caching/MetaCache.java @@ -22,10 +22,12 @@ package me.lucko.luckperms.common.caching; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSortedMap; import lombok.Getter; import lombok.NoArgsConstructor; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSortedMap; + import me.lucko.luckperms.api.caching.MetaData; import java.util.Map; diff --git a/common/src/main/java/me/lucko/luckperms/common/caching/MetaHolder.java b/common/src/main/java/me/lucko/luckperms/common/caching/MetaHolder.java index eb42b2287..1c4e0fd01 100644 --- a/common/src/main/java/me/lucko/luckperms/common/caching/MetaHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/caching/MetaHolder.java @@ -24,9 +24,14 @@ package me.lucko.luckperms.common.caching; import lombok.Getter; import lombok.ToString; + import me.lucko.luckperms.api.Node; -import java.util.*; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; /** * Holds temporary mutable meta whilst this object is passed up the inheritance tree to accumulate meta from parents diff --git a/common/src/main/java/me/lucko/luckperms/common/caching/PermissionCache.java b/common/src/main/java/me/lucko/luckperms/common/caching/PermissionCache.java index 7d368fc33..df4490186 100644 --- a/common/src/main/java/me/lucko/luckperms/common/caching/PermissionCache.java +++ b/common/src/main/java/me/lucko/luckperms/common/caching/PermissionCache.java @@ -22,8 +22,10 @@ package me.lucko.luckperms.common.caching; -import com.google.common.collect.ImmutableMap; import lombok.NonNull; + +import com.google.common.collect.ImmutableMap; + import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.caching.PermissionData; diff --git a/common/src/main/java/me/lucko/luckperms/common/caching/UserCache.java b/common/src/main/java/me/lucko/luckperms/common/caching/UserCache.java index 1e0aa2755..a4447f040 100644 --- a/common/src/main/java/me/lucko/luckperms/common/caching/UserCache.java +++ b/common/src/main/java/me/lucko/luckperms/common/caching/UserCache.java @@ -22,14 +22,16 @@ package me.lucko.luckperms.common.caching; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableSet; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; + import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.caching.MetaData; import me.lucko.luckperms.api.caching.PermissionData; diff --git a/common/src/main/java/me/lucko/luckperms/common/calculators/CalculatorFactory.java b/common/src/main/java/me/lucko/luckperms/common/calculators/CalculatorFactory.java index 95358bbd6..b05bdbdee 100644 --- a/common/src/main/java/me/lucko/luckperms/common/calculators/CalculatorFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/calculators/CalculatorFactory.java @@ -32,8 +32,9 @@ public interface CalculatorFactory { /** * Builds a PermissionCalculator for the user in the given context + * * @param contexts the contexts to build the calculator in - * @param user the user to build for + * @param user the user to build for * @return a permission calculator instance */ PermissionCalculator build(Contexts contexts, User user); diff --git a/common/src/main/java/me/lucko/luckperms/common/calculators/PermissionCalculator.java b/common/src/main/java/me/lucko/luckperms/common/calculators/PermissionCalculator.java index 0bc51bce0..c79e19c3c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/calculators/PermissionCalculator.java +++ b/common/src/main/java/me/lucko/luckperms/common/calculators/PermissionCalculator.java @@ -22,10 +22,12 @@ package me.lucko.luckperms.common.calculators; +import lombok.RequiredArgsConstructor; + import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; -import lombok.RequiredArgsConstructor; + import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.common.LuckPermsPlugin; @@ -55,7 +57,7 @@ public class PermissionCalculator { public Tristate getPermissionValue(String permission) { permission = permission.toLowerCase(); - Tristate t = cache.getUnchecked(permission); + Tristate t = cache.getUnchecked(permission); plugin.getDebugHandler().offer(objectName, permission, t); plugin.getPermissionCache().offer(permission); return t; diff --git a/common/src/main/java/me/lucko/luckperms/common/calculators/PermissionProcessor.java b/common/src/main/java/me/lucko/luckperms/common/calculators/PermissionProcessor.java index f6bc48655..a47b6e536 100644 --- a/common/src/main/java/me/lucko/luckperms/common/calculators/PermissionProcessor.java +++ b/common/src/main/java/me/lucko/luckperms/common/calculators/PermissionProcessor.java @@ -29,6 +29,7 @@ import java.util.Map; public interface PermissionProcessor { Tristate hasPermission(String permission); + void updateBacking(Map map); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/Arg.java b/common/src/main/java/me/lucko/luckperms/common/commands/Arg.java index 68281aceb..348bac9a5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/Arg.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/Arg.java @@ -22,11 +22,12 @@ package me.lucko.luckperms.common.commands; -import com.google.common.collect.ImmutableList; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; +import com.google.common.collect.ImmutableList; + @Getter @AllArgsConstructor(access = AccessLevel.PRIVATE) public class Arg { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/Command.java b/common/src/main/java/me/lucko/luckperms/common/commands/Command.java index 600eb86ff..b8d075e19 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/Command.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/Command.java @@ -22,8 +22,10 @@ package me.lucko.luckperms.common.commands; -import com.google.common.collect.ImmutableList; import lombok.Getter; + +import com.google.common.collect.ImmutableList; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.constants.Permission; @@ -77,6 +79,7 @@ public abstract class Command { } public abstract void sendUsage(Sender sender, String label); + public abstract void sendDetailedUsage(Sender sender, String label); public boolean isAuthorized(Sender sender) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/CommandManager.java b/common/src/main/java/me/lucko/luckperms/common/commands/CommandManager.java index 47f6ff72b..08029c036 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/CommandManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/CommandManager.java @@ -22,8 +22,10 @@ package me.lucko.luckperms.common.commands; -import com.google.common.collect.ImmutableList; import lombok.Getter; + +import com.google.common.collect.ImmutableList; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.group.CreateGroup; import me.lucko.luckperms.common.commands.group.DeleteGroup; @@ -31,7 +33,13 @@ import me.lucko.luckperms.common.commands.group.GroupMainCommand; import me.lucko.luckperms.common.commands.group.ListGroups; import me.lucko.luckperms.common.commands.log.LogMainCommand; import me.lucko.luckperms.common.commands.migration.MigrationMainCommand; -import me.lucko.luckperms.common.commands.misc.*; +import me.lucko.luckperms.common.commands.misc.ExportCommand; +import me.lucko.luckperms.common.commands.misc.ImportCommand; +import me.lucko.luckperms.common.commands.misc.InfoCommand; +import me.lucko.luckperms.common.commands.misc.NetworkSyncCommand; +import me.lucko.luckperms.common.commands.misc.QueueCommand; +import me.lucko.luckperms.common.commands.misc.SyncCommand; +import me.lucko.luckperms.common.commands.misc.VerboseCommand; import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.track.CreateTrack; import me.lucko.luckperms.common.commands.track.DeleteTrack; @@ -51,115 +59,6 @@ import java.util.function.Consumer; import java.util.stream.Collectors; public class CommandManager { - @Getter - private final LuckPermsPlugin plugin; - - @Getter - private final List mainCommands; - - public CommandManager(LuckPermsPlugin plugin) { - this.plugin = plugin; - - ImmutableList.Builder l = ImmutableList.builder(); - l.add(new UserMainCommand()) - .add(new GroupMainCommand()) - .add(new TrackMainCommand()) - .addAll(plugin.getExtraCommands()) - .add(new LogMainCommand()) - .add(new SyncCommand()) - .add(new NetworkSyncCommand()) - .add(new InfoCommand()) - .add(new VerboseCommand()) - .add(new ImportCommand()) - .add(new ExportCommand()) - .add(new QueueCommand()) - .add(new MigrationMainCommand()) - .add(new UsersBulkEditMainCommand()) - .add(new CreateGroup()) - .add(new DeleteGroup()) - .add(new ListGroups()) - .add(new CreateTrack()) - .add(new DeleteTrack()) - .add(new ListTracks()); - - mainCommands = l.build(); - } - - /** - * Generic on command method to be called from the command executor object of the platform - * Unlike {@link #onCommand(Sender, String, List)}, this method is called in a new thread - * @param sender who sent the command - * @param label the command label used - * @param args the arguments provided - * @param result the callback to be called when the command has fully executed - */ - public void onCommand(Sender sender, String label, List args, Consumer result) { - plugin.doAsync(() -> { - CommandResult r = onCommand(sender, label, args); - if (result != null) { - plugin.doSync(() -> result.accept(r)); - } - }); - } - - /** - * Generic on command method to be called from the command executor object of the platform - * @param sender who sent the command - * @param label the command label used - * @param args the arguments provided - * @return if the command was successful - */ - @SuppressWarnings("unchecked") - public CommandResult onCommand(Sender sender, String label, List args) { - // Handle no arguments - if (args.size() == 0) { - sendCommandUsage(sender, label); - return CommandResult.INVALID_ARGS; - } - - // Look for the main command. - Optional o = mainCommands.stream() - .filter(m -> m.getName().equalsIgnoreCase(args.get(0))) - .limit(1) - .findAny(); - - // Main command not found - if (!o.isPresent()) { - sendCommandUsage(sender, label); - return CommandResult.INVALID_ARGS; - } - - // Check the Sender has permission to use the main command. - final Command main = o.get(); - if (!main.isAuthorized(sender)) { - sendCommandUsage(sender, label); - return CommandResult.NO_PERMISSION; - } - - List arguments = new ArrayList<>(args); - handleRewrites(arguments); - arguments.remove(0); // remove the main command arg. - - // Check the correct number of args were given for the main command - if (main.getArgumentCheck().test(arguments.size())) { - main.sendUsage(sender, label); - return CommandResult.INVALID_ARGS; - } - - // Try to execute the command. - CommandResult result; - try { - result = main.execute(plugin, sender, null, arguments, label); - } catch (CommandException e) { - result = handleException(e, sender, label, main); - } catch (Exception e) { - e.printStackTrace(); - result = CommandResult.FAILURE; - } - - return result; - } - public static CommandResult handleException(CommandException e, Sender sender, String label, Command command) { if (e instanceof ArgumentUtils.ArgumentException) { if (e instanceof ArgumentUtils.DetailedUsageException) { @@ -198,56 +97,6 @@ public class CommandManager { return CommandResult.FAILURE; } - /** - * Generic tab complete method to be called from the command executor object of the platform - * @param sender who is tab completing - * @param args the arguments provided so far - * @return a list of suggestions - */ - @SuppressWarnings("unchecked") - public List onTabComplete(Sender sender, List args) { - final List mains = mainCommands.stream() - .filter(m -> m.isAuthorized(sender)) - .collect(Collectors.toList()); - - // Not yet past the point of entering a main command - if (args.size() <= 1) { - - // Nothing yet entered - if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) { - return mains.stream() - .map(m -> m.getName().toLowerCase()) - .collect(Collectors.toList()); - } - - // Started typing a main command - return mains.stream() - .map(m -> m.getName().toLowerCase()) - .filter(s -> s.startsWith(args.get(0).toLowerCase())) - .collect(Collectors.toList()); - } - - // Find a main command matching the first arg - Optional o = mains.stream() - .filter(m -> m.getName().equalsIgnoreCase(args.get(0))) - .limit(1) - .findAny(); - - if (!o.isPresent()) { - return Collections.emptyList(); - } - - // Pass the processing onto the main command - return o.get().tabComplete(plugin, sender, args.subList(1, args.size())); - } - - private void sendCommandUsage(Sender sender, String label) { - Util.sendPluginMessage(sender, "&2Running &bLuckPerms v" + plugin.getVersion() + "&2."); - mainCommands.stream() - .filter(c -> c.isAuthorized(sender)) - .forEach(c -> Util.sendPluginMessage(sender, "&3> &a" + String.format(c.getUsage(), label))); - } - private static void handleRewrites(List args) { if (args.size() >= 3) { if (!args.get(0).equalsIgnoreCase("user") && !args.get(0).equalsIgnoreCase("group")) { @@ -362,9 +211,9 @@ public class CommandManager { // Provide lazy set rewrite boolean lazySet = ( args.size() >= 6 && - args.get(2).equalsIgnoreCase("permission") && - args.get(3).toLowerCase().startsWith("set") && - (args.get(5).equalsIgnoreCase("none") || args.get(5).equalsIgnoreCase("0")) + args.get(2).equalsIgnoreCase("permission") && + args.get(3).toLowerCase().startsWith("set") && + (args.get(5).equalsIgnoreCase("none") || args.get(5).equalsIgnoreCase("0")) ); if (lazySet) { @@ -374,4 +223,165 @@ public class CommandManager { } } } + + @Getter + private final LuckPermsPlugin plugin; + @Getter + private final List mainCommands; + + public CommandManager(LuckPermsPlugin plugin) { + this.plugin = plugin; + + ImmutableList.Builder l = ImmutableList.builder(); + l.add(new UserMainCommand()) + .add(new GroupMainCommand()) + .add(new TrackMainCommand()) + .addAll(plugin.getExtraCommands()) + .add(new LogMainCommand()) + .add(new SyncCommand()) + .add(new NetworkSyncCommand()) + .add(new InfoCommand()) + .add(new VerboseCommand()) + .add(new ImportCommand()) + .add(new ExportCommand()) + .add(new QueueCommand()) + .add(new MigrationMainCommand()) + .add(new UsersBulkEditMainCommand()) + .add(new CreateGroup()) + .add(new DeleteGroup()) + .add(new ListGroups()) + .add(new CreateTrack()) + .add(new DeleteTrack()) + .add(new ListTracks()); + + mainCommands = l.build(); + } + + /** + * Generic on command method to be called from the command executor object of the platform + * Unlike {@link #onCommand(Sender, String, List)}, this method is called in a new thread + * + * @param sender who sent the command + * @param label the command label used + * @param args the arguments provided + * @param result the callback to be called when the command has fully executed + */ + public void onCommand(Sender sender, String label, List args, Consumer result) { + plugin.doAsync(() -> { + CommandResult r = onCommand(sender, label, args); + if (result != null) { + plugin.doSync(() -> result.accept(r)); + } + }); + } + + /** + * Generic on command method to be called from the command executor object of the platform + * + * @param sender who sent the command + * @param label the command label used + * @param args the arguments provided + * @return if the command was successful + */ + @SuppressWarnings("unchecked") + public CommandResult onCommand(Sender sender, String label, List args) { + // Handle no arguments + if (args.size() == 0) { + sendCommandUsage(sender, label); + return CommandResult.INVALID_ARGS; + } + + // Look for the main command. + Optional o = mainCommands.stream() + .filter(m -> m.getName().equalsIgnoreCase(args.get(0))) + .limit(1) + .findAny(); + + // Main command not found + if (!o.isPresent()) { + sendCommandUsage(sender, label); + return CommandResult.INVALID_ARGS; + } + + // Check the Sender has permission to use the main command. + final Command main = o.get(); + if (!main.isAuthorized(sender)) { + sendCommandUsage(sender, label); + return CommandResult.NO_PERMISSION; + } + + List arguments = new ArrayList<>(args); + handleRewrites(arguments); + arguments.remove(0); // remove the main command arg. + + // Check the correct number of args were given for the main command + if (main.getArgumentCheck().test(arguments.size())) { + main.sendUsage(sender, label); + return CommandResult.INVALID_ARGS; + } + + // Try to execute the command. + CommandResult result; + try { + result = main.execute(plugin, sender, null, arguments, label); + } catch (CommandException e) { + result = handleException(e, sender, label, main); + } catch (Exception e) { + e.printStackTrace(); + result = CommandResult.FAILURE; + } + + return result; + } + + /** + * Generic tab complete method to be called from the command executor object of the platform + * + * @param sender who is tab completing + * @param args the arguments provided so far + * @return a list of suggestions + */ + @SuppressWarnings("unchecked") + public List onTabComplete(Sender sender, List args) { + final List mains = mainCommands.stream() + .filter(m -> m.isAuthorized(sender)) + .collect(Collectors.toList()); + + // Not yet past the point of entering a main command + if (args.size() <= 1) { + + // Nothing yet entered + if (args.isEmpty() || args.get(0).equalsIgnoreCase("")) { + return mains.stream() + .map(m -> m.getName().toLowerCase()) + .collect(Collectors.toList()); + } + + // Started typing a main command + return mains.stream() + .map(m -> m.getName().toLowerCase()) + .filter(s -> s.startsWith(args.get(0).toLowerCase())) + .collect(Collectors.toList()); + } + + // Find a main command matching the first arg + Optional o = mains.stream() + .filter(m -> m.getName().equalsIgnoreCase(args.get(0))) + .limit(1) + .findAny(); + + if (!o.isPresent()) { + return Collections.emptyList(); + } + + // Pass the processing onto the main command + return o.get().tabComplete(plugin, sender, args.subList(1, args.size())); + } + + private void sendCommandUsage(Sender sender, String label) { + Util.sendPluginMessage(sender, "&2Running &bLuckPerms v" + plugin.getVersion() + "&2."); + mainCommands.stream() + .filter(c -> c.isAuthorized(sender)) + .forEach(c -> Util.sendPluginMessage(sender, "&3> &a" + String.format(c.getUsage(), label))); + } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/CommandResult.java b/common/src/main/java/me/lucko/luckperms/common/commands/CommandResult.java index 9ff085796..673bc8b7b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/CommandResult.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/CommandResult.java @@ -34,14 +34,14 @@ public enum CommandResult { INVALID_ARGS(false), NO_PERMISSION(false); + public static CommandResult of(boolean b) { + return b ? SUCCESS : FAILURE; + } + private boolean value; public boolean asBoolean() { return value; } - public static CommandResult of(boolean b) { - return b ? SUCCESS : FAILURE; - } - } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/ConsecutiveExecutor.java b/common/src/main/java/me/lucko/luckperms/common/commands/ConsecutiveExecutor.java index ae6a35025..2a6bc7f4c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/ConsecutiveExecutor.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/ConsecutiveExecutor.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.common.commands; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.RequiredArgsConstructor; + import me.lucko.luckperms.common.commands.sender.Sender; import java.util.ArrayList; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/MainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/MainCommand.java index 39b833c5e..bfff56edb 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/MainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/MainCommand.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.commands; import lombok.Getter; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.utils.Util; @@ -141,7 +142,9 @@ public abstract class MainCommand extends BaseCommand { } protected abstract List getTargets(LuckPermsPlugin plugin); + protected abstract T getTarget(String target, LuckPermsPlugin plugin, Sender sender); + protected abstract void cleanup(T t, LuckPermsPlugin plugin); @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/SingleCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/SingleCommand.java index f18fd9ed4..f9204443c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/SingleCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/SingleCommand.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.commands; import lombok.Getter; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.utils.Util; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/SubCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/SubCommand.java index ae43809bd..a91a7fa41 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/SubCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/SubCommand.java @@ -22,8 +22,10 @@ package me.lucko.luckperms.common.commands; -import com.google.common.base.Splitter; import lombok.Getter; + +import com.google.common.base.Splitter; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.utils.Util; @@ -34,7 +36,11 @@ import me.lucko.luckperms.common.core.model.Track; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.utils.PermissionCache; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -44,46 +50,6 @@ import java.util.stream.Collectors; @Getter public abstract class SubCommand extends Command { - public SubCommand(String name, String description, Permission permission, Predicate argumentCheck, List args) { - super(name, description, permission, argumentCheck, args); - } - - /** - * Send the command usage to a sender - * @param sender the sender to send the usage to - */ - @Override - public void sendUsage(Sender sender, String label) { - StringBuilder sb = new StringBuilder(); - if (getArgs().isPresent()) { - sb.append("&3 - &7"); - for (Arg arg : getArgs().get()) { - sb.append(arg.asPrettyString()).append(" "); - } - } - - Util.sendPluginMessage(sender, "&3> &a" + getName().toLowerCase() + sb.toString()); - } - - @Override - public void sendDetailedUsage(Sender sender, String label) { - Util.sendPluginMessage(sender, "&3&lCommand Usage &3- &b" + getName()); - Util.sendPluginMessage(sender, "&b> &7" + getDescription()); - if (getArgs().isPresent()) { - Util.sendPluginMessage(sender, "&3Arguments:"); - for (Arg arg : getArgs().get()) { - Util.sendPluginMessage(sender, "&b- " + arg.asPrettyString() + "&3 -> &7" + arg.getDescription()); - } - } - } - - - /* - * ---------------------------------------------------------------------------------- - * Utility methods used by #tabComplete and #execute implementations in sub classes - * ---------------------------------------------------------------------------------- - */ - public static List getGroupTabComplete(List args, LuckPermsPlugin plugin) { return getTabComplete(new ArrayList<>(plugin.getGroupManager().getAll().keySet()), args); } @@ -100,6 +66,13 @@ public abstract class SubCommand extends Command { } } + + /* + * ---------------------------------------------------------------------------------- + * Utility methods used by #tabComplete and #execute implementations in sub classes + * ---------------------------------------------------------------------------------- + */ + public static List getPermissionTabComplete(List args, PermissionCache cache) { if (args.size() <= 1) { if (args.isEmpty() || args.get(0).equals("")) { @@ -193,4 +166,38 @@ public abstract class SubCommand extends Command { Message.TRACK_SAVE_ERROR.send(sender); } } + + public SubCommand(String name, String description, Permission permission, Predicate argumentCheck, List args) { + super(name, description, permission, argumentCheck, args); + } + + /** + * Send the command usage to a sender + * + * @param sender the sender to send the usage to + */ + @Override + public void sendUsage(Sender sender, String label) { + StringBuilder sb = new StringBuilder(); + if (getArgs().isPresent()) { + sb.append("&3 - &7"); + for (Arg arg : getArgs().get()) { + sb.append(arg.asPrettyString()).append(" "); + } + } + + Util.sendPluginMessage(sender, "&3> &a" + getName().toLowerCase() + sb.toString()); + } + + @Override + public void sendDetailedUsage(Sender sender, String label) { + Util.sendPluginMessage(sender, "&3&lCommand Usage &3- &b" + getName()); + Util.sendPluginMessage(sender, "&b> &7" + getDescription()); + if (getArgs().isPresent()) { + Util.sendPluginMessage(sender, "&3Arguments:"); + for (Arg arg : getArgs().get()) { + Util.sendPluginMessage(sender, "&b- " + arg.asPrettyString() + "&3 -> &7" + arg.getDescription()); + } + } + } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/SharedMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/SharedMainCommand.java index 8b3b8606a..cf78a5e4f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/SharedMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/SharedMainCommand.java @@ -40,8 +40,46 @@ import java.util.Optional; import java.util.stream.Collectors; public class SharedMainCommand extends SubCommand { - private boolean user; + private static CommandResult handleException(CommandException e, Sender sender, SharedSubCommand command) { + if (e instanceof ArgumentUtils.ArgumentException) { + if (e instanceof ArgumentUtils.DetailedUsageException) { + command.sendDetailedUsage(sender); + return CommandResult.INVALID_ARGS; + } + + if (e instanceof ArgumentUtils.UseInheritException) { + Message.USE_INHERIT_COMMAND.send(sender); + return CommandResult.INVALID_ARGS; + } + + if (e instanceof ArgumentUtils.InvalidServerException) { + Message.SERVER_INVALID_ENTRY.send(sender); + return CommandResult.INVALID_ARGS; + } + + if (e instanceof ArgumentUtils.PastDateException) { + Message.PAST_DATE_ERROR.send(sender); + return CommandResult.INVALID_ARGS; + } + + if (e instanceof ArgumentUtils.InvalidDateException) { + Message.ILLEGAL_DATE_ERROR.send(sender, ((ArgumentUtils.InvalidDateException) e).getInvalidDate()); + return CommandResult.INVALID_ARGS; + } + + if (e instanceof ArgumentUtils.InvalidPriorityException) { + Message.META_INVALID_PRIORITY.send(sender, ((ArgumentUtils.InvalidPriorityException) e).getInvalidPriority()); + return CommandResult.INVALID_ARGS; + } + } + + // Not something we can catch. + e.printStackTrace(); + return CommandResult.FAILURE; + } + private final List secondaryCommands; + private boolean user; public SharedMainCommand(String name, String description, boolean user, List secondaryCommands) { super(name, description, null, Predicates.alwaysFalse(), null); @@ -91,44 +129,6 @@ public class SharedMainCommand extends SubCommand return result; } - private static CommandResult handleException(CommandException e, Sender sender, SharedSubCommand command) { - if (e instanceof ArgumentUtils.ArgumentException) { - if (e instanceof ArgumentUtils.DetailedUsageException) { - command.sendDetailedUsage(sender); - return CommandResult.INVALID_ARGS; - } - - if (e instanceof ArgumentUtils.UseInheritException) { - Message.USE_INHERIT_COMMAND.send(sender); - return CommandResult.INVALID_ARGS; - } - - if (e instanceof ArgumentUtils.InvalidServerException) { - Message.SERVER_INVALID_ENTRY.send(sender); - return CommandResult.INVALID_ARGS; - } - - if (e instanceof ArgumentUtils.PastDateException) { - Message.PAST_DATE_ERROR.send(sender); - return CommandResult.INVALID_ARGS; - } - - if (e instanceof ArgumentUtils.InvalidDateException) { - Message.ILLEGAL_DATE_ERROR.send(sender, ((ArgumentUtils.InvalidDateException) e).getInvalidDate()); - return CommandResult.INVALID_ARGS; - } - - if (e instanceof ArgumentUtils.InvalidPriorityException) { - Message.META_INVALID_PRIORITY.send(sender, ((ArgumentUtils.InvalidPriorityException) e).getInvalidPriority()); - return CommandResult.INVALID_ARGS; - } - } - - // Not something we can catch. - e.printStackTrace(); - return CommandResult.FAILURE; - } - @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List args) { final List subs = secondaryCommands.stream() diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/SharedSubCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/SharedSubCommand.java index 66a3cb405..daf3e97c5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/SharedSubCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/SharedSubCommand.java @@ -22,9 +22,11 @@ package me.lucko.luckperms.common.commands.generic; -import com.google.common.collect.ImmutableList; import lombok.AllArgsConstructor; import lombok.Getter; + +import com.google.common.collect.ImmutableList; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.CommandException; @@ -45,27 +47,39 @@ import java.util.function.Predicate; @AllArgsConstructor public abstract class SharedSubCommand { + protected static void save(PermissionHolder holder, Sender sender, LuckPermsPlugin plugin) { + if (holder instanceof User) { + User user = ((User) holder); + SubCommand.save(user, sender, plugin); + return; + } + + if (holder instanceof Group) { + Group group = ((Group) holder); + SubCommand.save(group, sender, plugin); + return; + } + + throw new IllegalArgumentException(); + } + /** * The name of the sub command */ private final String name; - /** * A brief description of what the sub command does */ private final String description; - /** * The permission needed to use this command */ private final Permission userPermission; private final Permission groupPermission; - /** * Predicate to test if the argument length given is invalid */ private final Predicate isArgumentInvalid; - private final ImmutableList args; public abstract CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args) throws CommandException; @@ -101,20 +115,4 @@ public abstract class SharedSubCommand { return user ? userPermission.isAuthorized(sender) : groupPermission.isAuthorized(sender); } - protected static void save(PermissionHolder holder, Sender sender, LuckPermsPlugin plugin) { - if (holder instanceof User) { - User user = ((User) holder); - SubCommand.save(user, sender, plugin); - return; - } - - if (holder instanceof Group) { - Group group = ((Group) holder); - SubCommand.save(group, sender, plugin); - return; - } - - throw new IllegalArgumentException(); - } - } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java index 7e931b6fe..d7465627d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/CommandMeta.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.commands.generic.meta; import com.google.common.collect.ImmutableList; + import me.lucko.luckperms.common.commands.generic.SharedMainCommand; import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.core.model.PermissionHolder; @@ -30,20 +31,20 @@ import me.lucko.luckperms.common.core.model.PermissionHolder; public class CommandMeta extends SharedMainCommand { public CommandMeta(boolean user) { super("Meta", "Edit metadata values", user, ImmutableList.builder() - .add(new MetaInfo()) - .add(new MetaSet()) - .add(new MetaUnset()) - .add(new MetaSetTemp()) - .add(new MetaUnsetTemp()) - .add(new MetaAddPrefix()) - .add(new MetaAddSuffix()) - .add(new MetaRemovePrefix()) - .add(new MetaRemoveSuffix()) - .add(new MetaAddTempPrefix()) - .add(new MetaAddTempSuffix()) - .add(new MetaRemoveTempPrefix()) - .add(new MetaRemoveTempSuffix()) - .add(new MetaClear()) - .build()); + .add(new MetaInfo()) + .add(new MetaSet()) + .add(new MetaUnset()) + .add(new MetaSetTemp()) + .add(new MetaUnsetTemp()) + .add(new MetaAddPrefix()) + .add(new MetaAddSuffix()) + .add(new MetaRemovePrefix()) + .add(new MetaRemoveSuffix()) + .add(new MetaAddTempPrefix()) + .add(new MetaAddTempSuffix()) + .add(new MetaRemoveTempPrefix()) + .add(new MetaRemoveTempSuffix()) + .add(new MetaClear()) + .build()); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddPrefix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddPrefix.java index b229d1d9e..4b5791d26 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddPrefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddPrefix.java @@ -43,7 +43,7 @@ import java.util.stream.Collectors; public class MetaAddPrefix extends SharedSubCommand { public MetaAddPrefix() { - super("addprefix", "Adds a prefix", Permission.USER_META_ADDPREFIX, Permission.GROUP_META_ADDPREFIX, + super("addprefix", "Adds a prefix", Permission.USER_META_ADDPREFIX, Permission.GROUP_META_ADDPREFIX, Predicates.notInRange(2, 4), Arg.list( Arg.create("priority", true, "the priority to add the prefix at"), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddSuffix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddSuffix.java index 59727e3dc..8f4c6458c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddSuffix.java @@ -43,7 +43,7 @@ import java.util.stream.Collectors; public class MetaAddSuffix extends SharedSubCommand { public MetaAddSuffix() { - super("addsuffix", "Adds a suffix", Permission.USER_META_ADDSUFFIX, Permission.GROUP_META_ADDSUFFIX, + super("addsuffix", "Adds a suffix", Permission.USER_META_ADDSUFFIX, Permission.GROUP_META_ADDSUFFIX, Predicates.notInRange(2, 4), Arg.list( Arg.create("priority", true, "the priority to add the suffix at"), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempPrefix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempPrefix.java index f1e381bc5..0c4819028 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempPrefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempPrefix.java @@ -44,7 +44,7 @@ import java.util.stream.Collectors; public class MetaAddTempPrefix extends SharedSubCommand { public MetaAddTempPrefix() { - super("addtempprefix", "Adds a prefix temporarily", Permission.USER_META_ADDTEMP_PREFIX, + super("addtempprefix", "Adds a prefix temporarily", Permission.USER_META_ADDTEMP_PREFIX, Permission.GROUP_META_ADDTEMP_PREFIX, Predicates.notInRange(3, 5), Arg.list( Arg.create("priority", true, "the priority to add the prefix at"), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempSuffix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempSuffix.java index 569f8bb7d..1faeab0e4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempSuffix.java @@ -44,7 +44,7 @@ import java.util.stream.Collectors; public class MetaAddTempSuffix extends SharedSubCommand { public MetaAddTempSuffix() { - super("addtempsuffix", "Adds a suffix temporarily", Permission.USER_META_ADDTEMP_SUFFIX, + super("addtempsuffix", "Adds a suffix temporarily", Permission.USER_META_ADDTEMP_SUFFIX, Permission.GROUP_META_ADDTEMP_SUFFIX, Predicates.notInRange(3, 5), Arg.list( Arg.create("priority", true, "the priority to add the suffix at"), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java index 74546922f..0ba49ec84 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaClear.java @@ -41,7 +41,7 @@ import java.util.stream.Collectors; public class MetaClear extends SharedSubCommand { public MetaClear() { - super("clear", "Clears all chat meta", Permission.USER_META_CLEAR, Permission.GROUP_META_CLEAR, Predicates.notInRange(0, 2), + super("clear", "Clears all chat meta", Permission.USER_META_CLEAR, Permission.GROUP_META_CLEAR, Predicates.notInRange(0, 2), Arg.list( Arg.create("server", false, "the server name to filter by"), Arg.create("world", false, "the world name to filter by") diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java index 3a6d32b8a..76614a2db 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaInfo.java @@ -36,11 +36,21 @@ import me.lucko.luckperms.common.core.model.PermissionHolder; import me.lucko.luckperms.common.utils.ExtractedContexts; import me.lucko.luckperms.common.utils.Predicates; -import java.util.*; +import java.util.AbstractMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; public class MetaInfo extends SharedSubCommand { + private static String processLocation(LocalizedNode node, PermissionHolder holder) { + return node.getLocation().equalsIgnoreCase(holder.getObjectName()) ? "self" : node.getLocation(); + } + public MetaInfo() { - super("info", "Shows all chat meta", Permission.USER_META_INFO, Permission.GROUP_META_INFO, Predicates.alwaysFalse(), null); + super("info", "Shows all chat meta", Permission.USER_META_INFO, Permission.GROUP_META_INFO, Predicates.alwaysFalse(), null); } @Override @@ -111,8 +121,4 @@ public class MetaInfo extends SharedSubCommand { return CommandResult.SUCCESS; } - - private static String processLocation(LocalizedNode node, PermissionHolder holder) { - return node.getLocation().equalsIgnoreCase(holder.getObjectName()) ? "self" : node.getLocation(); - } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java index b2afec15c..d21ae39dc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemovePrefix.java @@ -45,7 +45,7 @@ import java.util.stream.Collectors; public class MetaRemovePrefix extends SharedSubCommand { public MetaRemovePrefix() { - super("removeprefix", "Removes a prefix", Permission.USER_META_REMOVEPREFIX, Permission.GROUP_META_REMOVEPREFIX, + super("removeprefix", "Removes a prefix", Permission.USER_META_REMOVEPREFIX, Permission.GROUP_META_REMOVEPREFIX, Predicates.notInRange(2, 4), Arg.list( Arg.create("priority", true, "the priority to add the prefix at"), @@ -91,7 +91,8 @@ public class MetaRemovePrefix extends SharedSubCommand { toRemove.forEach(n -> { try { holder.unsetPermission(n); - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } }); Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java index e63dd7856..251061b3f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveSuffix.java @@ -45,7 +45,7 @@ import java.util.stream.Collectors; public class MetaRemoveSuffix extends SharedSubCommand { public MetaRemoveSuffix() { - super("removesuffix", "Removes a suffix", Permission.USER_META_REMOVESUFFIX, Permission.GROUP_META_REMOVESUFFIX, + super("removesuffix", "Removes a suffix", Permission.USER_META_REMOVESUFFIX, Permission.GROUP_META_REMOVESUFFIX, Predicates.notInRange(2, 4), Arg.list( Arg.create("priority", true, "the priority to add the suffix at"), @@ -91,7 +91,8 @@ public class MetaRemoveSuffix extends SharedSubCommand { toRemove.forEach(n -> { try { holder.unsetPermission(n); - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } }); Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java index 34a34ed0e..69e3b1d7d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempPrefix.java @@ -45,7 +45,7 @@ import java.util.stream.Collectors; public class MetaRemoveTempPrefix extends SharedSubCommand { public MetaRemoveTempPrefix() { - super("removetempprefix", "Removes a temporary prefix", Permission.USER_META_REMOVETEMP_PREFIX, Permission.GROUP_META_REMOVETEMP_PREFIX, Predicates.notInRange(2, 4), + super("removetempprefix", "Removes a temporary prefix", Permission.USER_META_REMOVETEMP_PREFIX, Permission.GROUP_META_REMOVETEMP_PREFIX, Predicates.notInRange(2, 4), Arg.list( Arg.create("priority", true, "the priority to add the prefix at"), Arg.create("prefix", true, "the prefix string"), @@ -90,7 +90,8 @@ public class MetaRemoveTempPrefix extends SharedSubCommand { toRemove.forEach(n -> { try { holder.unsetPermission(n); - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } }); Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java index b458cd8a2..e5c0f1d1d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempSuffix.java @@ -45,7 +45,7 @@ import java.util.stream.Collectors; public class MetaRemoveTempSuffix extends SharedSubCommand { public MetaRemoveTempSuffix() { - super("removetempsuffix", "Removes a temporary suffix", Permission.USER_META_REMOVETEMP_SUFFIX, Permission.GROUP_META_REMOVETEMP_SUFFIX, Predicates.notInRange(2, 4), + super("removetempsuffix", "Removes a temporary suffix", Permission.USER_META_REMOVETEMP_SUFFIX, Permission.GROUP_META_REMOVETEMP_SUFFIX, Predicates.notInRange(2, 4), Arg.list( Arg.create("priority", true, "the priority to add the suffix at"), Arg.create("suffix", true, "the suffix string"), @@ -90,7 +90,8 @@ public class MetaRemoveTempSuffix extends SharedSubCommand { toRemove.forEach(n -> { try { holder.unsetPermission(n); - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } }); Message.BULK_CHANGE_SUCCESS.send(sender, toRemove.size()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java index 3c54d6952..91218b5f1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSet.java @@ -44,7 +44,7 @@ import java.util.stream.Collectors; public class MetaSet extends SharedSubCommand { public MetaSet() { - super("set", "Sets a meta value", Permission.USER_META_SET, Permission.GROUP_META_SET, Predicates.notInRange(2, 4), + super("set", "Sets a meta value", Permission.USER_META_SET, Permission.GROUP_META_SET, Predicates.notInRange(2, 4), Arg.list( Arg.create("key", true, "the key to set"), Arg.create("value", true, "the value to set"), @@ -73,7 +73,8 @@ public class MetaSet extends SharedSubCommand { try { holder.setPermission(n); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } switch (ContextHelper.determine(server, world)) { case NONE: diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java index 4cb25d4ce..183139a2d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTemp.java @@ -45,7 +45,7 @@ import java.util.stream.Collectors; public class MetaSetTemp extends SharedSubCommand { public MetaSetTemp() { - super("settemp", "Sets a meta value temporarily", Permission.USER_META_SETTEMP, Permission.GROUP_META_SETTEMP, Predicates.notInRange(3, 5), + super("settemp", "Sets a meta value temporarily", Permission.USER_META_SETTEMP, Permission.GROUP_META_SETTEMP, Predicates.notInRange(3, 5), Arg.list( Arg.create("key", true, "the key to set"), Arg.create("value", true, "the value to set"), @@ -75,7 +75,8 @@ public class MetaSetTemp extends SharedSubCommand { try { holder.setPermission(n); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } switch (ContextHelper.determine(server, world)) { case NONE: diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java index 6028ba260..79a0eece2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnset.java @@ -41,7 +41,7 @@ import java.util.stream.Collectors; public class MetaUnset extends SharedSubCommand { public MetaUnset() { - super("unset", "Unsets a meta value", Permission.USER_META_UNSET, Permission.GROUP_META_UNSET, + super("unset", "Unsets a meta value", Permission.USER_META_UNSET, Permission.GROUP_META_UNSET, Predicates.notInRange(1, 3), Arg.list( Arg.create("key", true, "the key to unset"), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java index 06e40e08c..7e87f95a5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaUnsetTemp.java @@ -41,7 +41,7 @@ import java.util.stream.Collectors; public class MetaUnsetTemp extends SharedSubCommand { public MetaUnsetTemp() { - super("unsettemp", "Unsets a temporary meta value", Permission.USER_META_UNSETTEMP, Permission.GROUP_META_UNSETTEMP, + super("unsettemp", "Unsets a temporary meta value", Permission.USER_META_UNSETTEMP, Permission.GROUP_META_UNSETTEMP, Predicates.notInRange(1, 3), Arg.list( Arg.create("key", true, "the key to unset"), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/CommandParent.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/CommandParent.java index 881ca7eba..75e55321e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/CommandParent.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/CommandParent.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.commands.generic.parent; import com.google.common.collect.ImmutableList; + import me.lucko.luckperms.common.commands.generic.SharedMainCommand; import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.core.model.PermissionHolder; @@ -30,12 +31,12 @@ import me.lucko.luckperms.common.core.model.PermissionHolder; public class CommandParent extends SharedMainCommand { public CommandParent(boolean user) { super("Parent", "Edit inheritances", user, ImmutableList.builder() - .add(new ParentInfo()) - .add(new ParentSet()) - .add(new ParentAdd()) - .add(new ParentRemove()) - .add(new ParentAddTemp()) - .add(new ParentRemoveTemp()) - .build()); + .add(new ParentInfo()) + .add(new ParentSet()) + .add(new ParentAdd()) + .add(new ParentRemove()) + .add(new ParentAddTemp()) + .add(new ParentRemoveTemp()) + .build()); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java index 9ede9eb83..4e4b618bf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentSet.java @@ -79,7 +79,8 @@ public class ParentSet extends SharedSubCommand { try { holder.setInheritGroup(group); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } if (holder instanceof User) { ((User) holder).setPrimaryGroup(group.getName()); @@ -92,7 +93,8 @@ public class ParentSet extends SharedSubCommand { try { holder.setInheritGroup(group, server); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } if (server.equalsIgnoreCase("global") && holder instanceof User) { ((User) holder).setPrimaryGroup(group.getName()); @@ -105,7 +107,8 @@ public class ParentSet extends SharedSubCommand { try { holder.setInheritGroup(group, server, world); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } Message.SET_PARENT_SERVER_WORLD_SUCCESS.send(sender, holder.getFriendlyName(), group.getDisplayName(), server, world); break; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java index 01fb72e52..b2b2e5a2a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/permission/CommandPermission.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.commands.generic.permission; import com.google.common.collect.ImmutableList; + import me.lucko.luckperms.common.commands.generic.SharedMainCommand; import me.lucko.luckperms.common.commands.generic.SharedSubCommand; import me.lucko.luckperms.common.core.model.PermissionHolder; @@ -30,13 +31,13 @@ import me.lucko.luckperms.common.core.model.PermissionHolder; public class CommandPermission extends SharedMainCommand { public CommandPermission(boolean user) { super("Permission", "Edit permissions", user, ImmutableList.builder() - .add(new PermissionInfo()) - .add(new PermissionSet()) - .add(new PermissionUnset()) - .add(new PermissionSetTemp()) - .add(new PermissionUnsetTemp()) - .add(new PermissionCheck()) - .add(new PermissionCheckInherits()) - .build()); + .add(new PermissionInfo()) + .add(new PermissionSet()) + .add(new PermissionUnset()) + .add(new PermissionSetTemp()) + .add(new PermissionUnsetTemp()) + .add(new PermissionCheck()) + .add(new PermissionCheckInherits()) + .build()); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupBulkChange.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupBulkChange.java index c43230c8b..0d5dee6ae 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupBulkChange.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupBulkChange.java @@ -98,13 +98,15 @@ public class GroupBulkChange extends SubCommand { toRemove.forEach(n -> { try { group.unsetPermission(n); - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } }); toAdd.forEach(n -> { try { group.setPermission(n); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } }); save(group, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java index 974ad4b82..fe56abef9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupMainCommand.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.commands.group; import com.google.common.collect.ImmutableList; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.Command; import me.lucko.luckperms.common.commands.MainCommand; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogMainCommand.java index 17bc584f1..79ced85b1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/log/LogMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/log/LogMainCommand.java @@ -23,10 +23,17 @@ package me.lucko.luckperms.common.commands.log; import com.google.common.collect.ImmutableList; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.Command; import me.lucko.luckperms.common.commands.MainCommand; -import me.lucko.luckperms.common.commands.log.subcommands.*; +import me.lucko.luckperms.common.commands.log.subcommands.LogExport; +import me.lucko.luckperms.common.commands.log.subcommands.LogGroupHistory; +import me.lucko.luckperms.common.commands.log.subcommands.LogNotify; +import me.lucko.luckperms.common.commands.log.subcommands.LogRecent; +import me.lucko.luckperms.common.commands.log.subcommands.LogSearch; +import me.lucko.luckperms.common.commands.log.subcommands.LogTrackHistory; +import me.lucko.luckperms.common.commands.log.subcommands.LogUserHistory; import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.data.Log; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogRecent.java b/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogRecent.java index f0610b397..ee62b9155 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogRecent.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogRecent.java @@ -43,6 +43,32 @@ import java.util.SortedMap; import java.util.UUID; public class LogRecent extends SubCommand { + private static CommandResult showLog(int page, UUID filter, Sender sender, Log log) { + int maxPage = (filter != null) ? log.getRecentMaxPages(filter) : log.getRecentMaxPages(); + if (maxPage == 0) { + Message.LOG_NO_ENTRIES.send(sender); + return CommandResult.STATE_ERROR; + } + + if (page < 1 || page > maxPage) { + Message.LOG_INVALID_PAGE_RANGE.send(sender, maxPage); + return CommandResult.INVALID_ARGS; + } + + SortedMap entries = (filter != null) ? log.getRecent(page, filter) : log.getRecent(page); + if (filter != null) { + String name = entries.values().stream().findAny().get().getActorName(); + Message.LOG_RECENT_BY_HEADER.send(sender, name, page, maxPage); + } else { + Message.LOG_RECENT_HEADER.send(sender, page, maxPage); + } + + for (Map.Entry e : entries.entrySet()) { + Message.LOG_ENTRY.send(sender, e.getKey(), DateUtil.formatDateDiff(e.getValue().getTimestamp()), e.getValue().getFormatted()); + } + return CommandResult.SUCCESS; + } + public LogRecent() { super("recent", "View recent actions", Permission.LOG_RECENT, Predicates.notInRange(0, 2), Arg.list( @@ -65,7 +91,8 @@ public class LogRecent extends SubCommand { int p = Integer.parseInt(args.get(0)); // page return showLog(p, null, sender, log); - } catch (NumberFormatException ignored) {} + } catch (NumberFormatException ignored) { + } } // User and possibly page @@ -120,30 +147,4 @@ public class LogRecent extends SubCommand { } } } - - private static CommandResult showLog(int page, UUID filter, Sender sender, Log log) { - int maxPage = (filter != null) ? log.getRecentMaxPages(filter) : log.getRecentMaxPages(); - if (maxPage == 0) { - Message.LOG_NO_ENTRIES.send(sender); - return CommandResult.STATE_ERROR; - } - - if (page < 1 || page > maxPage) { - Message.LOG_INVALID_PAGE_RANGE.send(sender, maxPage); - return CommandResult.INVALID_ARGS; - } - - SortedMap entries = (filter != null) ? log.getRecent(page, filter) : log.getRecent(page); - if (filter != null) { - String name = entries.values().stream().findAny().get().getActorName(); - Message.LOG_RECENT_BY_HEADER.send(sender, name, page, maxPage); - } else { - Message.LOG_RECENT_HEADER.send(sender, page, maxPage); - } - - for (Map.Entry e : entries.entrySet()) { - Message.LOG_ENTRY.send(sender, e.getKey(), DateUtil.formatDateDiff(e.getValue().getTimestamp()), e.getValue().getFormatted()); - } - return CommandResult.SUCCESS; - } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogSearch.java b/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogSearch.java index f33bfc009..1f7fb5a86 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogSearch.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogSearch.java @@ -57,7 +57,8 @@ public class LogSearch extends SubCommand { try { page = Integer.parseInt(args.get(args.size() - 1)); args.remove(args.size() - 1); - } catch (NumberFormatException ignored) {} + } catch (NumberFormatException ignored) { + } } final String query = args.stream().collect(Collectors.joining(" ")); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogUserHistory.java b/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogUserHistory.java index 75d47c491..92a475010 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogUserHistory.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/log/subcommands/LogUserHistory.java @@ -43,6 +43,29 @@ import java.util.SortedMap; import java.util.UUID; public class LogUserHistory extends SubCommand { + private static CommandResult showLog(int page, UUID user, Sender sender, Log log) { + int maxPage = log.getUserHistoryMaxPages(user); + if (maxPage == 0) { + Message.LOG_NO_ENTRIES.send(sender); + return CommandResult.STATE_ERROR; + } + + if (page < 1 || page > maxPage) { + Message.LOG_INVALID_PAGE_RANGE.send(sender, maxPage); + return CommandResult.INVALID_ARGS; + } + + SortedMap entries = log.getUserHistory(page, user); + String name = entries.values().stream().findAny().get().getActedName(); + Message.LOG_HISTORY_USER_HEADER.send(sender, name, page, maxPage); + + for (Map.Entry e : entries.entrySet()) { + Message.LOG_ENTRY.send(sender, e.getKey(), DateUtil.formatDateDiff(e.getValue().getTimestamp()), e.getValue().getFormatted()); + } + + return CommandResult.SUCCESS; + } + public LogUserHistory() { super("userhistory", "View a user's history", Permission.LOG_USER_HISTORY, Predicates.notInRange(1, 2), Arg.list( @@ -99,27 +122,4 @@ public class LogUserHistory extends SubCommand { Message.USER_INVALID_ENTRY.send(sender, user); return CommandResult.INVALID_ARGS; } - - private static CommandResult showLog(int page, UUID user, Sender sender, Log log) { - int maxPage = log.getUserHistoryMaxPages(user); - if (maxPage == 0) { - Message.LOG_NO_ENTRIES.send(sender); - return CommandResult.STATE_ERROR; - } - - if (page < 1 || page > maxPage) { - Message.LOG_INVALID_PAGE_RANGE.send(sender, maxPage); - return CommandResult.INVALID_ARGS; - } - - SortedMap entries = log.getUserHistory(page, user); - String name = entries.values().stream().findAny().get().getActedName(); - Message.LOG_HISTORY_USER_HEADER.send(sender, name, page, maxPage); - - for (Map.Entry e : entries.entrySet()) { - Message.LOG_ENTRY.send(sender, e.getKey(), DateUtil.formatDateDiff(e.getValue().getTimestamp()), e.getValue().getFormatted()); - } - - return CommandResult.SUCCESS; - } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationMainCommand.java index a378b55c2..9b2325ee2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/migration/MigrationMainCommand.java @@ -23,7 +23,11 @@ package me.lucko.luckperms.common.commands.migration; import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.commands.*; +import me.lucko.luckperms.common.commands.Command; +import me.lucko.luckperms.common.commands.CommandException; +import me.lucko.luckperms.common.commands.CommandResult; +import me.lucko.luckperms.common.commands.MainCommand; +import me.lucko.luckperms.common.commands.SubCommand; import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.constants.Constants; import me.lucko.luckperms.common.constants.Message; @@ -35,12 +39,6 @@ import java.util.Optional; import java.util.stream.Collectors; public class MigrationMainCommand extends MainCommand { - private List> commands = null; - - public MigrationMainCommand() { - super("Migration", "Migration commands", "/%s migration", 1, null); - } - @SuppressWarnings("unchecked") private static List> getAvailableCommands() { List> l = new ArrayList<>(); @@ -48,46 +46,60 @@ public class MigrationMainCommand extends MainCommand { try { Class.forName("org.anjocaido.groupmanager.GroupManager"); l.add((SubCommand) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationGroupManager").newInstance()); - } catch (Throwable ignored) {} + } catch (Throwable ignored) { + } try { Class.forName("ru.tehkode.permissions.bukkit.PermissionsEx"); l.add((SubCommand) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationPermissionsEx").newInstance()); - } catch (Throwable ignored) {} + } catch (Throwable ignored) { + } try { Class.forName("com.github.cheesesoftware.PowerfulPermsAPI.PowerfulPermsPlugin"); l.add((SubCommand) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationPowerfulPerms").newInstance()); - } catch (Throwable ignored) {} + } catch (Throwable ignored) { + } try { Class.forName("org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService"); l.add((SubCommand) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationZPermissions").newInstance()); - } catch (Throwable ignored) {} + } catch (Throwable ignored) { + } try { Class.forName("net.alpenblock.bungeeperms.BungeePerms"); l.add((SubCommand) Class.forName("me.lucko.luckperms.bungee.migration.MigrationBungeePerms").newInstance()); - } catch (Throwable ignored) {} + } catch (Throwable ignored) { + } try { Class.forName("de.bananaco.bpermissions.api.WorldManager"); l.add((SubCommand) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationBPermissions").newInstance()); - } catch (Throwable ignored) {} + } catch (Throwable ignored) { + } try { Class.forName("ninja.leaping.permissionsex.sponge.PermissionsExPlugin"); l.add((SubCommand) Class.forName("me.lucko.luckperms.sponge.migration.MigrationPermissionsEx").newInstance()); - } catch (Throwable ignored) {} + } catch (Throwable ignored) { + } try { Class.forName("io.github.djxy.permissionmanager.PermissionManager"); l.add((SubCommand) Class.forName("me.lucko.luckperms.sponge.migration.MigrationPermissionManager").newInstance()); - } catch (Throwable ignored) {} + } catch (Throwable ignored) { + } return l.stream().collect(Collectors.toList()); } + private List> commands = null; + + public MigrationMainCommand() { + super("Migration", "Migration commands", "/%s migration", 1, null); + } + @SuppressWarnings("deprecation") @Deprecated @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java index 4e9482fdd..99758bf9a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/ExportCommand.java @@ -48,6 +48,59 @@ import java.util.Set; import java.util.UUID; public class ExportCommand extends SingleCommand { + private static void write(BufferedWriter writer, String s) { + try { + writer.write(s); + writer.newLine(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static String nodeToString(Node node, String id, boolean group) { + StringBuilder sb = new StringBuilder(); + sb.append("/luckperms ").append(group ? "group " : "user ").append(id).append(" "); + + if (node.isGroupNode()) { + if (node.isTemporary()) { + sb.append("parent addtemp "); + sb.append(node.getGroupName()); + sb.append(" ").append(node.getExpiryUnixTime()); + } else { + sb.append("parent add "); + sb.append(node.getGroupName()); + } + + if (node.isWorldSpecific()) { + sb.append(" ").append(node.getServer().get()).append(" ").append(node.getWorld().get()); + } else if (node.isServerSpecific()) { + sb.append(" ").append(node.getServer().get()); + } + + return sb.toString(); + } + + sb.append(node.isTemporary() ? "permission settemp " : "permission set "); + if (node.getPermission().contains(" ")) { + sb.append("\"").append(node.getPermission()).append("\""); + } else { + sb.append(node.getPermission()); + } + sb.append(" ").append(node.getValue()); + + if (node.isTemporary()) { + sb.append(" ").append(node.getExpiryUnixTime()); + } + + if (node.isWorldSpecific()) { + sb.append(" ").append(node.getServer().get()).append(" ").append(node.getWorld().get()); + } else if (node.isServerSpecific()) { + sb.append(" ").append(node.getServer().get()); + } + + return sb.toString(); + } + public ExportCommand() { super("Export", "Export data to a file", "/%s export ", Permission.MIGRATION, Predicates.not(1), Arg.list( @@ -174,57 +227,4 @@ public class ExportCommand extends SingleCommand { return sender.getUuid().equals(Constants.getConsoleUUID()); } - private static void write(BufferedWriter writer, String s) { - try { - writer.write(s); - writer.newLine(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - private static String nodeToString(Node node, String id, boolean group) { - StringBuilder sb = new StringBuilder(); - sb.append("/luckperms ").append(group ? "group " : "user ").append(id).append(" "); - - if (node.isGroupNode()) { - if (node.isTemporary()) { - sb.append("parent addtemp "); - sb.append(node.getGroupName()); - sb.append(" ").append(node.getExpiryUnixTime()); - } else { - sb.append("parent add "); - sb.append(node.getGroupName()); - } - - if (node.isWorldSpecific()) { - sb.append(" ").append(node.getServer().get()).append(" ").append(node.getWorld().get()); - } else if (node.isServerSpecific()) { - sb.append(" ").append(node.getServer().get()); - } - - return sb.toString(); - } - - sb.append(node.isTemporary() ? "permission settemp " : "permission set "); - if (node.getPermission().contains(" ")) { - sb.append("\"").append(node.getPermission()).append("\""); - } else { - sb.append(node.getPermission()); - } - sb.append(" ").append(node.getValue()); - - if (node.isTemporary()) { - sb.append(" ").append(node.getExpiryUnixTime()); - } - - if (node.isWorldSpecific()) { - sb.append(" ").append(node.getServer().get()).append(" ").append(node.getWorld().get()); - } else if (node.isServerSpecific()) { - sb.append(" ").append(node.getServer().get()); - } - - return sb.toString(); - } - } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java index b6e0af2f3..ce91902c0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java @@ -39,6 +39,20 @@ import java.util.Map; import static me.lucko.luckperms.common.commands.utils.Util.formatBoolean; public class InfoCommand extends SingleCommand { + private static String formatValue(String value) { + if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) { + return Util.formatBoolean(Boolean.parseBoolean(value)); + } + + try { + int i = Integer.parseInt(value); + return "&a" + i; + } catch (NumberFormatException ignored) { + } + + return "&f" + value; + } + public InfoCommand() { super("Info", "Print general plugin info", "/%s info", Permission.INFO, Predicates.alwaysFalse(), null); } @@ -84,17 +98,4 @@ public class InfoCommand extends SingleCommand { return CommandResult.SUCCESS; } - - private static String formatValue(String value) { - if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) { - return Util.formatBoolean(Boolean.parseBoolean(value)); - } - - try { - int i = Integer.parseInt(value); - return "&a" + i; - } catch (NumberFormatException ignored) {} - - return "&f" + value; - } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/QueueCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/QueueCommand.java index 23c369529..333615226 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/QueueCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/QueueCommand.java @@ -36,7 +36,7 @@ import java.util.List; public class QueueCommand extends SingleCommand { public QueueCommand() { - super("QueueCommand", "Queue a command for execution", "/%s queuecommand ", Permission.MIGRATION, Predicates.not(1), + super("QueueCommand", "Queue a command for execution", "/%s queuecommand ", Permission.MIGRATION, Predicates.not(1), Arg.list( Arg.create("command args...", true, "the command's arguments") ) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/sender/AbstractSender.java b/common/src/main/java/me/lucko/luckperms/common/commands/sender/AbstractSender.java index 10cae502f..1b7ed220a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/sender/AbstractSender.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/sender/AbstractSender.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.commands.sender; import lombok.Getter; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.constants.Constants; import me.lucko.luckperms.common.constants.Permission; @@ -32,6 +33,7 @@ import java.util.UUID; /** * Simple implementation of {@link Sender} using a {@link SenderFactory} + * * @param the command sender type */ @Getter diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/sender/Sender.java b/common/src/main/java/me/lucko/luckperms/common/commands/sender/Sender.java index 9ae242a3e..d8c3aaedf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/sender/Sender.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/sender/Sender.java @@ -35,30 +35,35 @@ public interface Sender { /** * Gets the platform where the sender is from. + * * @return the plugin */ LuckPermsPlugin getPlatform(); /** * Gets the sender's username + * * @return a friendly username for the sender */ String getName(); /** * Gets the sender's unique id. See {@link Constants#getConsoleUUID()} for the console's UUID representation. + * * @return the sender's uuid */ UUID getUuid(); /** * Send a message back to the Sender + * * @param s the message to send. Supports '§' for message formatting. */ void sendMessage(String s); /** * Check if the Sender has a permission. + * * @param permission the permission to check for * @return true if the sender has the permission */ diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/sender/SenderFactory.java b/common/src/main/java/me/lucko/luckperms/common/commands/sender/SenderFactory.java index da7ee6485..2c899360d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/sender/SenderFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/sender/SenderFactory.java @@ -23,12 +23,14 @@ package me.lucko.luckperms.common.commands.sender; import lombok.RequiredArgsConstructor; + import me.lucko.luckperms.common.LuckPermsPlugin; import java.util.UUID; /** * Factory class to make a thread-safe sender instance + * * @param the command sender type */ @RequiredArgsConstructor @@ -36,8 +38,11 @@ public abstract class SenderFactory { private final LuckPermsPlugin plugin; protected abstract String getName(T t); + protected abstract UUID getUuid(T t); + protected abstract void sendMessage(T t, String s); + protected abstract boolean hasPermission(T t, String node); public final Sender wrap(T t) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackMainCommand.java index ffede87bf..8115418cd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/track/TrackMainCommand.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.commands.track; import com.google.common.collect.ImmutableList; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.Command; import me.lucko.luckperms.common.commands.MainCommand; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserBulkChange.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserBulkChange.java index 2902cfc6e..1243d9fc7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserBulkChange.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserBulkChange.java @@ -108,13 +108,15 @@ public class UserBulkChange extends SubCommand { toRemove.forEach(n -> { try { user.unsetPermission(n); - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } }); toAdd.forEach(n -> { try { user.setPermission(n); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } }); save(user, sender, plugin); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java index 9b03d013e..94139f1db 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserDemote.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.commands.user; import com.google.common.base.Objects; + import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.event.events.UserDemoteEvent; import me.lucko.luckperms.common.LuckPermsPlugin; @@ -160,10 +161,12 @@ public class UserDemote extends SubCommand { try { user.unsetPermission(nodes.stream().findAny().get()); - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } try { user.setPermission(NodeFactory.newBuilder("group." + previousGroup.getName()).setServer(server).setWorld(world).build()); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } if (server == null && world == null) { user.setPrimaryGroup(previousGroup.getName()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java index efe11e584..a379a310d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.commands.user; import com.google.common.collect.ImmutableList; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.Command; import me.lucko.luckperms.common.commands.MainCommand; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java index f57a02e83..e67108e8f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserPromote.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.commands.user; import com.google.common.base.Objects; + import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.event.events.UserPromoteEvent; import me.lucko.luckperms.common.LuckPermsPlugin; @@ -160,10 +161,12 @@ public class UserPromote extends SubCommand { try { user.unsetPermission(nodes.stream().findAny().get()); - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } try { user.setPermission(NodeFactory.newBuilder("group." + nextGroup.getName()).setServer(server).setWorld(world).build()); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } if (server == null && world == null) { user.setPrimaryGroup(nextGroup.getName()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserSwitchPrimaryGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserSwitchPrimaryGroup.java index 826cc41d4..6b5f1a827 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserSwitchPrimaryGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserSwitchPrimaryGroup.java @@ -62,7 +62,8 @@ public class UserSwitchPrimaryGroup extends SubCommand { Message.USER_PRIMARYGROUP_ERROR_NOTMEMBER.send(sender, user.getName(), group.getName()); try { user.setInheritGroup(group); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } } user.setPrimaryGroup(group.getName()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/BulkEditGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/BulkEditGroup.java index 720580f89..204b0930a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/BulkEditGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/BulkEditGroup.java @@ -38,7 +38,11 @@ import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; -import java.util.*; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.UUID; public class BulkEditGroup extends SubCommand { public BulkEditGroup() { @@ -134,13 +138,15 @@ public class BulkEditGroup extends SubCommand { toRemove.forEach(n -> { try { user.unsetPermission(n); - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } }); toAdd.forEach(n -> { try { user.setPermission(n); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } }); plugin.getStorage().saveUser(user); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/BulkEditPermission.java b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/BulkEditPermission.java index a50a851ff..fef02fab4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/BulkEditPermission.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/BulkEditPermission.java @@ -38,7 +38,11 @@ import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; -import java.util.*; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.UUID; public class BulkEditPermission extends SubCommand { public BulkEditPermission() { @@ -124,13 +128,15 @@ public class BulkEditPermission extends SubCommand { toRemove.forEach(n -> { try { user.unsetPermission(n); - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } }); toAdd.forEach(n -> { try { user.setPermission(n); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } }); plugin.getStorage().saveUser(user); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/UsersBulkEditMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/UsersBulkEditMainCommand.java index 0bc62e151..28bb16a40 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/UsersBulkEditMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/usersbulkedit/UsersBulkEditMainCommand.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.commands.usersbulkedit; import com.google.common.collect.ImmutableList; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.Command; import me.lucko.luckperms.common.commands.MainCommand; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java b/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java index ef0f20ccb..0fba34296 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java @@ -24,6 +24,7 @@ package me.lucko.luckperms.common.commands.utils; import lombok.AllArgsConstructor; import lombok.Getter; + import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.common.commands.CommandException; @@ -119,7 +120,7 @@ public class ArgumentUtils { return ContextSet.empty(); } - MutableContextSet contextSet = new MutableContextSet(); + MutableContextSet contextSet = MutableContextSet.create(); List toQuery = args.subList(fromIndex, args.size()); for (String s : toQuery) { int index = s.indexOf('='); @@ -141,11 +142,20 @@ public class ArgumentUtils { return contextSet.makeImmutable(); } - public static abstract class ArgumentException extends CommandException {} - public static class DetailedUsageException extends ArgumentException {} - public static class UseInheritException extends ArgumentException {} - public static class InvalidServerException extends ArgumentException {} - public static class PastDateException extends ArgumentException {} + public static abstract class ArgumentException extends CommandException { + } + + public static class DetailedUsageException extends ArgumentException { + } + + public static class UseInheritException extends ArgumentException { + } + + public static class InvalidServerException extends ArgumentException { + } + + public static class PastDateException extends ArgumentException { + } @Getter @AllArgsConstructor diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/utils/ContextHelper.java b/common/src/main/java/me/lucko/luckperms/common/commands/utils/ContextHelper.java index 241eb8825..00b173edd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/utils/ContextHelper.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/utils/ContextHelper.java @@ -27,12 +27,12 @@ package me.lucko.luckperms.common.commands.utils; */ public class ContextHelper { - public enum CommandContext { - NONE, SERVER, SERVER_AND_WORLD - } - public static CommandContext determine(String server, String world) { return server == null ? CommandContext.NONE : (world == null ? CommandContext.SERVER : CommandContext.SERVER_AND_WORLD); } + public enum CommandContext { + NONE, SERVER, SERVER_AND_WORLD + } + } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/utils/Util.java b/common/src/main/java/me/lucko/luckperms/common/commands/utils/Util.java index b5b1fef7f..eb38ab596 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/utils/Util.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/utils/Util.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.commands.utils; import lombok.experimental.UtilityClass; + import me.lucko.luckperms.api.LocalizedNode; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.Tristate; @@ -31,11 +32,19 @@ import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Patterns; import me.lucko.luckperms.common.utils.DateUtil; -import java.util.*; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.SortedSet; +import java.util.UUID; @UtilityClass public class Util { + public static final MetaComparator META_COMPARATOR = new MetaComparator(); + public static void sendPluginMessage(Sender sender, String message) { String prefix = sender.getPlatform().getLocaleManager().getTranslation(Message.PREFIX); if (prefix == null) { @@ -239,7 +248,6 @@ public class Util { return sb.delete(sb.length() - 6, sb.length()).toString(); } - public static final MetaComparator META_COMPARATOR = new MetaComparator(); public class MetaComparator implements Comparator> { @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java b/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java index 4c05ea096..4c6205b66 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java @@ -22,10 +22,12 @@ package me.lucko.luckperms.common.config; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import lombok.AccessLevel; import lombok.Getter; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.constants.Patterns; import me.lucko.luckperms.common.defaults.Rule; @@ -38,6 +40,7 @@ import java.util.Map; /** * A thread-safe config abstraction + * * @param the plugin type */ @Getter @@ -90,13 +93,19 @@ public abstract class AbstractConfiguration implement } protected abstract void init(); + protected abstract String getString(String path, String def); + protected abstract int getInt(String path, int def); + protected abstract boolean getBoolean(String path, boolean def); + protected abstract List getList(String path, List def); + protected abstract List getObjectList(String path, List def); + protected abstract Map getMap(String path, Map def); - + public void load(String defaultServerName, boolean defaultIncludeGlobal, String defaultStorage) { server = getString("server", defaultServerName); syncTime = getInt("data.sync-minutes", 3); @@ -115,7 +124,8 @@ public abstract class AbstractConfiguration implement for (Map.Entry e : weights.entrySet()) { try { mb.put(e.getKey().toLowerCase(), Integer.parseInt(e.getValue())); - } catch (NumberFormatException ignored) {} + } catch (NumberFormatException ignored) { + } } groupWeights = mb.build(); logNotify = getBoolean("log-notify", true); @@ -166,7 +176,7 @@ public abstract class AbstractConfiguration implement redisEnabled = getBoolean("redis.enabled", false); redisAddress = getString("redis.address", null); redisPassword = getString("redis.password", ""); - + if (Patterns.NON_ALPHA_NUMERIC.matcher(getServer()).find()) { plugin.getLog().severe("Server name defined in config.yml contains invalid characters. Server names can " + "only contain alphanumeric characters.\nDefined server name '" + getServer() + "' will be replaced with '" + diff --git a/common/src/main/java/me/lucko/luckperms/common/config/LPConfiguration.java b/common/src/main/java/me/lucko/luckperms/common/config/LPConfiguration.java index fa395aee7..d05449b3f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/LPConfiguration.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/LPConfiguration.java @@ -36,12 +36,14 @@ public interface LPConfiguration { /** * As of 2.6, this value is a constant + * * @return the default group node */ String getDefaultGroupNode(); /** * As of 2.6, this value is a constant + * * @return the name of the default group */ String getDefaultGroupName(); diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java index 287b4ac14..11caca891 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java @@ -24,6 +24,7 @@ package me.lucko.luckperms.common.constants; import lombok.AllArgsConstructor; import lombok.Getter; + import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.utils.Util; @@ -51,7 +52,6 @@ public enum Message { DOES_NOT_HAVE_TEMP_PERMISSION("{0} does not have this permission set temporarily.", true), - /* * Loading / Saving */ @@ -69,7 +69,6 @@ public enum Message { TRACK_SAVE_ERROR("There was an error whilst saving the track.", true), - /* * Command Syntax */ @@ -86,7 +85,7 @@ public enum Message { VERBOSE_ON("&bVerbose checking output set to &aTRUE &bfor all permissions.", true), VERBOSE_ON_QUERY("&bVerbose checking output set to &aTRUE &bfor permissions matching the following filters: &f{0}", true), VERBOSE_OFF("&bVerbose checking output set to &cFALSE&b.", true), - + CREATE_SUCCESS("&b{0}&a was successfully created.", true), DELETE_SUCCESS("&b{0}&a was successfully deleted.", true), RENAME_SUCCESS("&b{0}&a was successfully renamed to &b{1}&a.", true), @@ -119,31 +118,31 @@ public enum Message { UPDATE_TASK_PUSH_FAILURE("&cError whilst pushing changes to other servers. Is Redis enabled?", true), INFO( "{PREFIX}&2Running &bLuckPerms v{0}&2 by &bLuck&2." + "\n" + - "{PREFIX}&f- &3Platform: &f{1}" + "\n" + - "{PREFIX}&f- &3Storage Method: &f{2}" + "\n" + - "{PREFIX}&f- &3Server Name: &f{3}" + "\n" + - "{PREFIX}&f- &3Sync Interval: &a{4} &fminutes" + "\n" + - "{PREFIX}&f- &bCounts:" + "\n" + - "{PREFIX}&f- &3Online Players: &a{5}" + "\n" + - "{PREFIX}&f- &3Loaded Users: &a{6}" + "\n" + - "{PREFIX}&f- &3Loaded Groups: &a{7}" + "\n" + - "{PREFIX}&f- &3Loaded Tracks: &a{8}" + "\n" + - "{PREFIX}&f- &3Log size: &a{9}" + "\n" + - "{PREFIX}&f- &3UUID Cache size: &a{10}" + "\n" + - "{PREFIX}&f- &3Translations loaded: &a{11}" + "\n" + - "{PREFIX}&f- &3Pre-process contexts: &a{12}" + "\n" + - "{PREFIX}&f- &3Context Calculators: &a{13}" + "\n" + - "{PREFIX}&f- &bConfiguration:" + "\n" + - "{PREFIX}&f- &3Online Mode: {14}" + "\n" + - "{PREFIX}&f- &3Redis Enabled: {15}" + "\n" + - "{PREFIX}&f- &bPermission Calculation:" + "\n" + - "{PREFIX}&f- &3Including Global: {16}" + "\n" + - "{PREFIX}&f- &3Including Global World: {17}" + "\n" + - "{PREFIX}&f- &3Applying Global Groups: {18}" + "\n" + - "{PREFIX}&f- &3Applying Global World Groups: {19}" + "\n" + - "{PREFIX}&f- &3Applying Wildcards: {20}" + "\n" + - "{PREFIX}&f- &3Applying Regex: {21}" + "\n" + - "{PREFIX}&f- &3Applying Shorthand: {22}", + "{PREFIX}&f- &3Platform: &f{1}" + "\n" + + "{PREFIX}&f- &3Storage Method: &f{2}" + "\n" + + "{PREFIX}&f- &3Server Name: &f{3}" + "\n" + + "{PREFIX}&f- &3Sync Interval: &a{4} &fminutes" + "\n" + + "{PREFIX}&f- &bCounts:" + "\n" + + "{PREFIX}&f- &3Online Players: &a{5}" + "\n" + + "{PREFIX}&f- &3Loaded Users: &a{6}" + "\n" + + "{PREFIX}&f- &3Loaded Groups: &a{7}" + "\n" + + "{PREFIX}&f- &3Loaded Tracks: &a{8}" + "\n" + + "{PREFIX}&f- &3Log size: &a{9}" + "\n" + + "{PREFIX}&f- &3UUID Cache size: &a{10}" + "\n" + + "{PREFIX}&f- &3Translations loaded: &a{11}" + "\n" + + "{PREFIX}&f- &3Pre-process contexts: &a{12}" + "\n" + + "{PREFIX}&f- &3Context Calculators: &a{13}" + "\n" + + "{PREFIX}&f- &bConfiguration:" + "\n" + + "{PREFIX}&f- &3Online Mode: {14}" + "\n" + + "{PREFIX}&f- &3Redis Enabled: {15}" + "\n" + + "{PREFIX}&f- &bPermission Calculation:" + "\n" + + "{PREFIX}&f- &3Including Global: {16}" + "\n" + + "{PREFIX}&f- &3Including Global World: {17}" + "\n" + + "{PREFIX}&f- &3Applying Global Groups: {18}" + "\n" + + "{PREFIX}&f- &3Applying Global World Groups: {19}" + "\n" + + "{PREFIX}&f- &3Applying Wildcards: {20}" + "\n" + + "{PREFIX}&f- &3Applying Regex: {21}" + "\n" + + "{PREFIX}&f- &3Applying Shorthand: {22}", false ), CREATE_GROUP_ERROR("There was an error whilst creating the group.", true), @@ -260,30 +259,30 @@ public enum Message { UNSET_META_TEMP_SUCCESS("&aUnset temporary meta value with key &f\"{0}&f\"&a for &b{1}&a.", true), UNSET_META_TEMP_SERVER_SUCCESS("&aUnset temporary meta value with key &f\"{0}&f\"&a for &b{1}&a on server &b{2}&a.", true), UNSET_META_TEMP_SERVER_WORLD_SUCCESS("&aUnset temporary meta value with key &f\"{0}&f\"&a for &b{1}&a on server &b{2}&a, world &b{3}&a.", true), - + BULK_CHANGE_TYPE_ERROR("Invalid type. Was expecting 'server' or 'world'.", true), BULK_CHANGE_SUCCESS("&aApplied bulk change successfully. {0} records were changed.", true), USER_INFO_GENERAL( "{PREFIX}&b&l> &bUser Info: &f{0}" + "\n" + - "{PREFIX}&f- &3UUID: &f{1}" + "\n" + - "{PREFIX}&f- &3Status: {2}" + "\n" + - "{PREFIX}&f- &3Primary Group: &f{3}" + "\n" + - "{PREFIX}&f- &aCounts:" + "\n" + - "{PREFIX}&f- &3Permissions: &a{4}" + "\n" + - "{PREFIX}&f- &3Temporary Permissions: &a{5}" + "\n" + - "{PREFIX}&f- &3Prefixes: &a{6}" + "\n" + - "{PREFIX}&f- &3Suffixes: &a{7}" + "\n" + - "{PREFIX}&f- &3Meta: &a{8}", + "{PREFIX}&f- &3UUID: &f{1}" + "\n" + + "{PREFIX}&f- &3Status: {2}" + "\n" + + "{PREFIX}&f- &3Primary Group: &f{3}" + "\n" + + "{PREFIX}&f- &aCounts:" + "\n" + + "{PREFIX}&f- &3Permissions: &a{4}" + "\n" + + "{PREFIX}&f- &3Temporary Permissions: &a{5}" + "\n" + + "{PREFIX}&f- &3Prefixes: &a{6}" + "\n" + + "{PREFIX}&f- &3Suffixes: &a{7}" + "\n" + + "{PREFIX}&f- &3Meta: &a{8}", false ), USER_INFO_DATA( "{PREFIX}&f- &aCached Data:" + "\n" + - "{PREFIX}&f- &3Is Loaded: {0}" + "\n" + - "{PREFIX}&f- &3Current Contexts: {1}" + "\n" + - "{PREFIX}&f- &3Current Prefix: {2}" + "\n" + - "{PREFIX}&f- &3Current Suffix: {3}", + "{PREFIX}&f- &3Is Loaded: {0}" + "\n" + + "{PREFIX}&f- &3Current Contexts: {1}" + "\n" + + "{PREFIX}&f- &3Current Prefix: {2}" + "\n" + + "{PREFIX}&f- &3Current Suffix: {3}", false ), @@ -301,7 +300,7 @@ public enum Message { USER_PROMOTE_ERROR_ENDOFTRACK("The end of track &4{0}&c was reached. Unable to promote user.", true), USER_PROMOTE_ERROR_MALFORMED( "{PREFIX}The next group on the track, {0}, no longer exists. Unable to promote user." + "\n" + - "{PREFIX}Either create the group, or remove it from the track and try again.", + "{PREFIX}Either create the group, or remove it from the track and try again.", false ), USER_DEMOTE_SUCCESS("&aDemoting user along track &b{0}&a from &b{1}&a to &b{2}&a.", true), @@ -310,22 +309,22 @@ public enum Message { USER_DEMOTE_ERROR_ENDOFTRACK("The end of track &4{0}&c was reached. Unable to demote user.", true), USER_DEMOTE_ERROR_MALFORMED( "{PREFIX}The previous group on the track, {0}, no longer exists. Unable to demote user." + "\n" + - "{PREFIX}Either create the group, or remove it from the track and try again.", + "{PREFIX}Either create the group, or remove it from the track and try again.", false ), USER_SHOWPOS("&aShowing &b{0}&a's position on track &b{1}&a.\n{2}", true), GROUP_INFO( "{PREFIX}&b&l> &bGroup Info: &f{0}" + "\n" + - "{PREFIX}&f- &3Permissions: &f{1}" + "\n" + - "{PREFIX}&f- &3Temporary Permissions: &f{2}" + "\n" + - "{PREFIX}&f- &3Use &b/{3} group {4} permission info &3to see all permissions.", + "{PREFIX}&f- &3Permissions: &f{1}" + "\n" + + "{PREFIX}&f- &3Temporary Permissions: &f{2}" + "\n" + + "{PREFIX}&f- &3Use &b/{3} group {4} permission info &3to see all permissions.", false ), TRACK_INFO( "{PREFIX}&b&l> &bShowing Track: &f{0}" + "\n" + - "{PREFIX}&f- &7Path: &f{1}", + "{PREFIX}&f- &7Path: &f{1}", false ), TRACK_CLEAR("&b{0}&a's groups track was cleared.", true), @@ -376,10 +375,10 @@ public enum Message { IMPORT_END_COMPLETE_ERR_SIN("&b(Import) &a&lCOMPLETED &7- took &b{0} &7seconds - &c{1} error.", true), IMPORT_END_ERROR_HEADER( "{PREFIX}&b(Import) &7------------> &fShowing Error #&b{0} &7<------------" + "\n" + - "{PREFIX}&b(Import) &fWhilst executing: &3Command #{1}" + "\n" + - "{PREFIX}&b(Import) &fCommand: &7{2}" + "\n" + - "{PREFIX}&b(Import) &fType: &3{3}" + "\n" + - "{PREFIX}&b(Import) &fOutput:", + "{PREFIX}&b(Import) &fWhilst executing: &3Command #{1}" + "\n" + + "{PREFIX}&b(Import) &fCommand: &7{2}" + "\n" + + "{PREFIX}&b(Import) &fType: &3{3}" + "\n" + + "{PREFIX}&b(Import) &fOutput:", false ), @@ -388,6 +387,14 @@ public enum Message { MIGRATION_NOT_CONSOLE("Migration must be performed from the Console.", true); + private static String format(String s, Object... objects) { + for (int i = 0, objsLength = objects.length; i < objsLength; i++) { + Object o = objects[i]; + s = s.replace("{" + i + "}", o.toString()); + } + return s; + } + @Getter private String message; private boolean showPrefix; @@ -416,12 +423,4 @@ public enum Message { sender.sendMessage(Util.color(format(s, objects))); } } - - private static String format(String s, Object... objects) { - for (int i = 0, objsLength = objects.length; i < objsLength; i++) { - Object o = objects[i]; - s = s.replace("{" + i + "}", o.toString()); - } - return s; - } } diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/Patterns.java b/common/src/main/java/me/lucko/luckperms/common/constants/Patterns.java index 76dd9d222..c35ccd35e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/Patterns.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/Patterns.java @@ -22,19 +22,26 @@ package me.lucko.luckperms.common.constants; +import lombok.experimental.UtilityClass; + import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.UncheckedExecutionException; -import lombok.experimental.UtilityClass; import java.util.concurrent.ExecutionException; import java.util.regex.Pattern; @UtilityClass public class Patterns { + public static final Pattern COMMAND_SEPARATOR = Pattern.compile(" (?=([^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)"); + public static final Pattern NON_ALPHA_NUMERIC = Pattern.compile("[\\/\\$\\.\\- ]"); + public static final Pattern NON_USERNAME = Pattern.compile("[^A-Za-z0-9_ ]"); + public static final Pattern SHORTHAND_NODE = Pattern.compile("\\.\\([^.]+\\)"); + public static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('§') + "[0-9A-FK-OR]"); + public static final Pattern NODE_CONTEXTS = Pattern.compile("\\(.+\\).*"); private static final LoadingCache CACHE = CacheBuilder.newBuilder() .build(new CacheLoader() { @Override @@ -48,13 +55,6 @@ public class Patterns { } }); - public static final Pattern COMMAND_SEPARATOR = Pattern.compile(" (?=([^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)"); - public static final Pattern NON_ALPHA_NUMERIC = Pattern.compile("[\\/\\$\\.\\- ]"); - public static final Pattern NON_USERNAME = Pattern.compile("[^A-Za-z0-9_ ]"); - public static final Pattern SHORTHAND_NODE = Pattern.compile("\\.\\([^.]+\\)"); - public static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('§') + "[0-9A-FK-OR]"); - public static final Pattern NODE_CONTEXTS = Pattern.compile("\\(.+\\).*"); - public static Pattern compile(String regex) { try { return CACHE.get(regex); diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/Permission.java b/common/src/main/java/me/lucko/luckperms/common/constants/Permission.java index b9a05fc4a..0b3bf6d99 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/Permission.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/Permission.java @@ -22,9 +22,11 @@ package me.lucko.luckperms.common.constants; -import com.google.common.collect.Sets; import lombok.AllArgsConstructor; import lombok.Getter; + +import com.google.common.collect.Sets; + import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.utils.ImmutableCollectors; @@ -149,6 +151,10 @@ public enum Permission { private static final String IDENTIFIER = "luckperms."; + private static Set set(String... args) { + return Sets.newHashSet(args); + } + private Set nodes; private Type type; @@ -166,21 +172,17 @@ public enum Permission { return sender.hasPermission(this); } - private static Set set(String... args) { - return Sets.newHashSet(args); - } - @Getter @AllArgsConstructor public enum Type { - + NONE(null), USER("user"), GROUP("group"), TRACK("track"), LOG("log"), SPONGE("sponge"); - + private final String tag; } diff --git a/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java b/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java index cf33d2602..d6475380f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.common.contexts; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; + import me.lucko.luckperms.api.context.ContextListener; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.context.IContextCalculator; @@ -45,7 +46,7 @@ public class ContextManager { .build(new CacheLoader() { @Override public ContextSet load(T t) { - return calculateApplicableContext(t, MutableContextSet.empty()).makeImmutable(); + return calculateApplicableContext(t, MutableContextSet.create()).makeImmutable(); } }); diff --git a/common/src/main/java/me/lucko/luckperms/common/contexts/ServerCalculator.java b/common/src/main/java/me/lucko/luckperms/common/contexts/ServerCalculator.java index 728b2d758..244b33519 100644 --- a/common/src/main/java/me/lucko/luckperms/common/contexts/ServerCalculator.java +++ b/common/src/main/java/me/lucko/luckperms/common/contexts/ServerCalculator.java @@ -22,8 +22,10 @@ package me.lucko.luckperms.common.contexts; -import com.google.common.collect.Maps; import lombok.AllArgsConstructor; + +import com.google.common.collect.Maps; + import me.lucko.luckperms.api.context.ContextCalculator; import me.lucko.luckperms.api.context.MutableContextSet; diff --git a/common/src/main/java/me/lucko/luckperms/common/core/InheritanceInfo.java b/common/src/main/java/me/lucko/luckperms/common/core/InheritanceInfo.java index 9cdae4ade..dbca7e0a0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/InheritanceInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/InheritanceInfo.java @@ -22,7 +22,13 @@ package me.lucko.luckperms.common.core; -import lombok.*; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.ToString; + import me.lucko.luckperms.api.LocalizedNode; import me.lucko.luckperms.api.Tristate; diff --git a/common/src/main/java/me/lucko/luckperms/common/core/NodeBuilder.java b/common/src/main/java/me/lucko/luckperms/common/core/NodeBuilder.java index 67f72eb0b..a21625416 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/NodeBuilder.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/NodeBuilder.java @@ -22,9 +22,11 @@ package me.lucko.luckperms.common.core; -import com.google.common.base.Splitter; import lombok.NonNull; import lombok.RequiredArgsConstructor; + +import com.google.common.base.Splitter; + import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.context.MutableContextSet; @@ -42,12 +44,12 @@ import java.util.Set; @RequiredArgsConstructor public class NodeBuilder implements Node.Builder { private final String permission; + private final MutableContextSet extraContexts = MutableContextSet.create(); private Boolean value = true; private boolean override = false; private String server = null; private String world = null; private long expireAt = 0L; - private final MutableContextSet extraContexts = new MutableContextSet(); NodeBuilder(String permission, boolean shouldConvertContexts) { if (!shouldConvertContexts) { diff --git a/common/src/main/java/me/lucko/luckperms/common/core/NodeFactory.java b/common/src/main/java/me/lucko/luckperms/common/core/NodeFactory.java index 763691d09..3c569eed6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/NodeFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/NodeFactory.java @@ -22,12 +22,14 @@ package me.lucko.luckperms.common.core; +import lombok.experimental.UtilityClass; + import com.google.common.base.Splitter; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.util.concurrent.UncheckedExecutionException; -import lombok.experimental.UtilityClass; + import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.api.Node; diff --git a/common/src/main/java/me/lucko/luckperms/common/core/PriorityComparator.java b/common/src/main/java/me/lucko/luckperms/common/core/PriorityComparator.java index 2521f5f53..0fc15bcee 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/PriorityComparator.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/PriorityComparator.java @@ -24,6 +24,7 @@ package me.lucko.luckperms.common.core; import lombok.AccessLevel; import lombok.NoArgsConstructor; + import me.lucko.luckperms.api.LocalizedNode; import me.lucko.luckperms.api.Node; diff --git a/common/src/main/java/me/lucko/luckperms/common/core/UserIdentifier.java b/common/src/main/java/me/lucko/luckperms/common/core/UserIdentifier.java index d009207ca..5a1b80e23 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/UserIdentifier.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/UserIdentifier.java @@ -22,7 +22,12 @@ package me.lucko.luckperms.common.core; -import lombok.*; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; + import me.lucko.luckperms.common.utils.Identifiable; import java.util.UUID; diff --git a/common/src/main/java/me/lucko/luckperms/common/core/UuidCache.java b/common/src/main/java/me/lucko/luckperms/common/core/UuidCache.java index c0fae0e4a..ec7181c4b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/UuidCache.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/UuidCache.java @@ -22,10 +22,11 @@ package me.lucko.luckperms.common.core; +import lombok.Getter; + import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.Maps; -import lombok.Getter; import java.util.UUID; @@ -34,11 +35,10 @@ import java.util.UUID; */ public class UuidCache { - // External UUID --> Internal UUID - private BiMap cache; - @Getter private final boolean onlineMode; + // External UUID --> Internal UUID + private BiMap cache; public UuidCache(boolean onlineMode) { this.onlineMode = onlineMode; diff --git a/common/src/main/java/me/lucko/luckperms/common/core/model/Group.java b/common/src/main/java/me/lucko/luckperms/common/core/model/Group.java index cfdbbb63b..adb6a3d46 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/model/Group.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/model/Group.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.common.core.model; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.utils.Identifiable; diff --git a/common/src/main/java/me/lucko/luckperms/common/core/model/ImmutableNode.java b/common/src/main/java/me/lucko/luckperms/common/core/model/ImmutableNode.java index eb21cc4a3..3f2d333d3 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/model/ImmutableNode.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/model/ImmutableNode.java @@ -22,13 +22,15 @@ package me.lucko.luckperms.common.core.model; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; + import com.google.common.base.Preconditions; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; + import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.Tristate; @@ -36,7 +38,13 @@ import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.common.constants.Patterns; import me.lucko.luckperms.common.utils.ShorthandParser; -import java.util.*; +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -51,6 +59,54 @@ public class ImmutableNode implements Node { private static final Pattern SUFFIX_PATTERN = Pattern.compile("(?i)suffix\\.-?\\d+\\..*"); private static final Pattern META_PATTERN = Pattern.compile("meta\\..*\\..*"); + private static boolean shouldApply(String str, boolean applyRegex, String thisStr) { + if (str.toLowerCase().startsWith("r=") && applyRegex) { + Pattern p = Patterns.compile(str.substring(2)); + if (p == null) { + return false; + } + return p.matcher(thisStr).matches(); + } + + if (str.startsWith("(") && str.endsWith(")") && str.contains("|")) { + final String bits = str.substring(1, str.length() - 1); + Iterable parts = Splitter.on('|').split(bits); + + for (String s : parts) { + if (s.equalsIgnoreCase(thisStr)) { + return true; + } + } + + return false; + } + + return thisStr.equalsIgnoreCase(str); + } + + @SuppressWarnings("ResultOfMethodCallIgnored") + private static boolean isInt(String a, String b) { + try { + Integer.parseInt(a); + Integer.parseInt(b); + return true; + } catch (NumberFormatException e) { + return false; + } + } + + private static boolean isChar(String a, String b) { + return a.length() == 1 && b.length() == 1; + } + + private static Set getCharRange(char a, char b) { + Set s = new HashSet<>(); + for (char c = a; c <= b; c++) { + s.add(Character.toString(c)); + } + return s; + } + @Getter private final String permission; @@ -90,12 +146,13 @@ public class ImmutableNode implements Node { /** * Make an immutable node instance + * * @param permission the actual permission node - * @param value the value (if it's *not* negated) - * @param expireAt the time when the node will expire - * @param server the server this node applies on - * @param world the world this node applies on - * @param contexts any additional contexts applying to this node + * @param value the value (if it's *not* negated) + * @param expireAt the time when the node will expire + * @param server the server this node applies on + * @param world the world this node applies on + * @param contexts any additional contexts applying to this node */ public ImmutableNode(String permission, boolean value, boolean override, long expireAt, String server, String world, ContextSet contexts) { if (permission == null || permission.equals("")) { @@ -196,7 +253,7 @@ public class ImmutableNode implements Node { } @Override - public long getExpiryUnixTime(){ + public long getExpiryUnixTime() { Preconditions.checkState(isTemporary(), "Node does not have an expiry time."); return expireAt; } @@ -290,31 +347,6 @@ public class ImmutableNode implements Node { return isWorldSpecific() ? shouldApply(world, applyRegex, this.world) : includeGlobal; } - private static boolean shouldApply(String str, boolean applyRegex, String thisStr) { - if (str.toLowerCase().startsWith("r=") && applyRegex) { - Pattern p = Patterns.compile(str.substring(2)); - if (p == null) { - return false; - } - return p.matcher(thisStr).matches(); - } - - if (str.startsWith("(") && str.endsWith(")") && str.contains("|")) { - final String bits = str.substring(1, str.length() - 1); - Iterable parts = Splitter.on('|').split(bits); - - for (String s : parts) { - if (s.equalsIgnoreCase(thisStr)) { - return true; - } - } - - return false; - } - - return thisStr.equalsIgnoreCase(str); - } - @Override public boolean shouldApplyWithContext(ContextSet context, boolean worldAndServer) { if (contexts.isEmpty() && !isServerSpecific() && !isWorldSpecific()) { @@ -381,29 +413,6 @@ public class ImmutableNode implements Node { return possibleNodes.stream().filter(pn -> pn.startsWith(match)).collect(Collectors.toList()); } - @SuppressWarnings("ResultOfMethodCallIgnored") - private static boolean isInt(String a, String b) { - try { - Integer.parseInt(a); - Integer.parseInt(b); - return true; - } catch (NumberFormatException e) { - return false; - } - } - - private static boolean isChar(String a, String b) { - return a.length() == 1 && b.length() == 1; - } - - private static Set getCharRange(char a, char b) { - Set s = new HashSet<>(); - for (char c = a; c <= b; c++) { - s.add(Character.toString(c)); - } - return s; - } - @Override public List resolveShorthand() { return resolvedShorthand; diff --git a/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java index 94710f2d5..8024996c9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java @@ -22,18 +22,24 @@ package me.lucko.luckperms.common.core.model; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Maps; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.RequiredArgsConstructor; + import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.LocalizedNode; import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.Tristate; -import me.lucko.luckperms.api.event.events.*; +import me.lucko.luckperms.api.event.events.GroupAddEvent; +import me.lucko.luckperms.api.event.events.GroupRemoveEvent; +import me.lucko.luckperms.api.event.events.PermissionNodeExpireEvent; +import me.lucko.luckperms.api.event.events.PermissionNodeSetEvent; +import me.lucko.luckperms.api.event.events.PermissionNodeUnsetEvent; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.api.internal.GroupLink; import me.lucko.luckperms.common.api.internal.PermissionHolderLink; @@ -49,7 +55,16 @@ import me.lucko.luckperms.common.utils.ImmutableLocalizedNode; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -62,6 +77,26 @@ import java.util.stream.Collectors; @RequiredArgsConstructor(access = AccessLevel.PROTECTED) public abstract class PermissionHolder { + public static Map exportToLegacy(Set nodes) { + Map m = new HashMap<>(); + for (Node node : nodes) { + m.put(node.toSerializedNode(), node.getValue()); + } + return m; + } + + private static Node.Builder buildNode(String permission) { + return new NodeBuilder(permission); + } + + private static ImmutableLocalizedNode makeLocal(Node node, String location) { + return ImmutableLocalizedNode.of(node, location); + } + + private static Node makeNode(String s, Boolean b) { + return NodeFactory.fromSerialisedNode(s, b); + } + /** * The UUID of the user / name of the group. * Used to prevent circular inheritance issues @@ -78,6 +113,9 @@ public abstract class PermissionHolder { private final Set nodes = new HashSet<>(); private final Set transientNodes = new HashSet<>(); + @Getter + private final Lock ioLock = new ReentrantLock(); + private Cache> enduringCache = new Cache<>(() -> { synchronized (nodes) { return ImmutableSet.copyOf(nodes); @@ -158,19 +196,48 @@ public abstract class PermissionHolder { return ImmutableSortedSet.copyOfSorted(combined); }); - @Getter - private final Lock ioLock = new ReentrantLock(); - public abstract String getFriendlyName(); public Set getNodes() { return enduringCache.get(); } + public void setNodes(Map nodes) { + Set set = nodes.entrySet().stream() + .map(e -> makeNode(e.getKey(), e.getValue())) + .collect(Collectors.toSet()); + + setNodes(set); + } + + public void setNodes(Set set) { + synchronized (nodes) { + if (nodes.equals(set)) { + return; + } + + nodes.clear(); + nodes.addAll(set); + } + invalidateCache(true); + } + public Set getTransientNodes() { return transientCache.get(); } + public void setTransientNodes(Set set) { + synchronized (transientNodes) { + if (transientNodes.equals(set)) { + return; + } + + transientNodes.clear(); + transientNodes.addAll(set); + } + invalidateCache(false); + } + private void invalidateCache(boolean enduring) { if (enduring) { enduringCache.invalidate(); @@ -183,6 +250,7 @@ public abstract class PermissionHolder { /** * Combines and returns this holders nodes in a priority order. + * * @return the holders transient and permanent nodes */ public SortedSet getPermissions(boolean mergeTemp) { @@ -191,6 +259,7 @@ public abstract class PermissionHolder { /** * Removes temporary permissions that have expired + * * @return true if permissions had expired and were removed */ public boolean auditTemporaryPermissions() { @@ -244,8 +313,9 @@ public abstract class PermissionHolder { /** * Resolves inherited nodes and returns them + * * @param excludedGroups a list of groups to exclude - * @param contexts context to decide if groups should be applied + * @param contexts context to decide if groups should be applied * @return a set of nodes */ public SortedSet getAllNodes(List excludedGroups, ExtractedContexts contexts) { @@ -269,8 +339,8 @@ public abstract class PermissionHolder { parents.removeIf(node -> !node.shouldApplyOnServer(server, context.isApplyGlobalGroups(), plugin.getConfiguration().isApplyingRegex()) || - !node.shouldApplyOnWorld(world, context.isApplyGlobalWorldGroups(), plugin.getConfiguration().isApplyingRegex()) || - !node.shouldApplyWithContext(contexts.getContextSet(), false) + !node.shouldApplyOnWorld(world, context.isApplyGlobalWorldGroups(), plugin.getConfiguration().isApplyingRegex()) || + !node.shouldApplyWithContext(contexts.getContextSet(), false) ); TreeSet> sortedParents = new TreeSet<>(Util.META_COMPARATOR.reversed()); @@ -345,8 +415,8 @@ public abstract class PermissionHolder { parents.removeIf(node -> !node.shouldApplyOnServer(server, context.isApplyGlobalGroups(), plugin.getConfiguration().isApplyingRegex()) || - !node.shouldApplyOnWorld(world, context.isApplyGlobalWorldGroups(), plugin.getConfiguration().isApplyingRegex()) || - !node.shouldApplyWithContext(contexts.getContextSet(), false) + !node.shouldApplyOnWorld(world, context.isApplyGlobalWorldGroups(), plugin.getConfiguration().isApplyingRegex()) || + !node.shouldApplyWithContext(contexts.getContextSet(), false) ); TreeSet> sortedParents = new TreeSet<>(Util.META_COMPARATOR.reversed()); @@ -378,6 +448,7 @@ public abstract class PermissionHolder { /** * Gets all of the nodes that this holder has (and inherits), given the context + * * @param contexts the context for this request * @return a map of permissions */ @@ -396,8 +467,8 @@ public abstract class PermissionHolder { allNodes.removeIf(node -> !node.shouldApplyOnServer(server, context.isIncludeGlobal(), plugin.getConfiguration().isApplyingRegex()) || - !node.shouldApplyOnWorld(world, context.isIncludeGlobalWorld(), plugin.getConfiguration().isApplyingRegex()) || - !node.shouldApplyWithContext(contexts.getContextSet(), false) + !node.shouldApplyOnWorld(world, context.isIncludeGlobalWorld(), plugin.getConfiguration().isApplyingRegex()) || + !node.shouldApplyWithContext(contexts.getContextSet(), false) ); Set perms = ConcurrentHashMap.newKeySet(); @@ -419,6 +490,7 @@ public abstract class PermissionHolder { /** * Converts the output of {@link #getAllNodesFiltered(ExtractedContexts)}, and expands shorthand perms + * * @param context the context for this request * @return a map of permissions */ @@ -443,42 +515,11 @@ public abstract class PermissionHolder { return ImmutableMap.copyOf(perms); } - public void setNodes(Set set) { - synchronized (nodes) { - if (nodes.equals(set)) { - return; - } - - nodes.clear(); - nodes.addAll(set); - } - invalidateCache(true); - } - - public void setTransientNodes(Set set) { - synchronized (transientNodes) { - if (transientNodes.equals(set)) { - return; - } - - transientNodes.clear(); - transientNodes.addAll(set); - } - invalidateCache(false); - } - - public void setNodes(Map nodes) { - Set set = nodes.entrySet().stream() - .map(e -> makeNode(e.getKey(), e.getValue())) - .collect(Collectors.toSet()); - - setNodes(set); - } - /** * Check if the holder has a permission node + * * @param node the node to check - * @param t whether to check transient nodes + * @param t whether to check transient nodes * @return a tristate */ public Tristate hasPermission(Node node, boolean t) { @@ -521,6 +562,7 @@ public abstract class PermissionHolder { /** * Check if the holder inherits a node + * * @param node the node to check * @return the result of the lookup */ @@ -536,6 +578,7 @@ public abstract class PermissionHolder { /** * Check if the holder inherits a node + * * @param node the node to check * @return the Tristate result */ @@ -569,6 +612,7 @@ public abstract class PermissionHolder { /** * Sets a permission node + * * @param node the node to set * @throws ObjectAlreadyHasException if the holder has this permission already */ @@ -587,6 +631,7 @@ public abstract class PermissionHolder { /** * Sets a transient permission node + * * @param node the node to set * @throws ObjectAlreadyHasException if the holder has this permission already */ @@ -629,6 +674,7 @@ public abstract class PermissionHolder { /** * Unsets a permission node + * * @param node the node to unset * @throws ObjectLacksException if the holder doesn't have this node already */ @@ -652,6 +698,7 @@ public abstract class PermissionHolder { /** * Unsets a transient permission node + * * @param node the node to unset * @throws ObjectLacksException if the holder doesn't have this node already */ @@ -829,7 +876,7 @@ public abstract class PermissionHolder { synchronized (nodes) { boolean b = nodes.removeIf(n -> - n.isGroupNode() && + n.isGroupNode() && n.getServer().orElse("global").equalsIgnoreCase(finalServer) && n.getWorld().orElse("null").equalsIgnoreCase(finalWorld) ); @@ -934,6 +981,7 @@ public abstract class PermissionHolder { /** * Get a {@link List} of all of the groups the holder inherits, on all servers + * * @return a {@link List} of group names */ public List getGroupNames() { @@ -945,8 +993,9 @@ public abstract class PermissionHolder { /** * Get a {@link List} of the groups the holder inherits on a specific server and world + * * @param server the server to check - * @param world the world to check + * @param world the world to check * @return a {@link List} of group names */ public List getLocalGroups(String server, String world) { @@ -969,6 +1018,7 @@ public abstract class PermissionHolder { /** * Get a {@link List} of the groups the holder inherits on a specific server + * * @param server the server to check * @return a {@link List} of group names */ @@ -979,24 +1029,4 @@ public abstract class PermissionHolder { .map(Node::getGroupName) .collect(Collectors.toList()); } - - public static Map exportToLegacy(Set nodes) { - Map m = new HashMap<>(); - for (Node node : nodes) { - m.put(node.toSerializedNode(), node.getValue()); - } - return m; - } - - private static Node.Builder buildNode(String permission) { - return new NodeBuilder(permission); - } - - private static ImmutableLocalizedNode makeLocal(Node node, String location) { - return ImmutableLocalizedNode.of(node, location); - } - - private static Node makeNode(String s, Boolean b) { - return NodeFactory.fromSerialisedNode(s, b); - } } diff --git a/common/src/main/java/me/lucko/luckperms/common/core/model/Track.java b/common/src/main/java/me/lucko/luckperms/common/core/model/Track.java index d0a82610b..d913af616 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/model/Track.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/model/Track.java @@ -22,11 +22,13 @@ package me.lucko.luckperms.common.core.model; -import com.google.common.collect.ImmutableList; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.ToString; + +import com.google.common.collect.ImmutableList; + import me.lucko.luckperms.common.utils.Identifiable; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; @@ -47,15 +49,13 @@ public class Track implements Identifiable { */ @Getter private final String name; - + @Getter + private final Lock ioLock = new ReentrantLock(); /** * The groups within this track */ private List groups = Collections.synchronizedList(new ArrayList<>()); - @Getter - private final Lock ioLock = new ReentrantLock(); - @Override public String getId() { return name.toLowerCase(); @@ -63,6 +63,7 @@ public class Track implements Identifiable { /** * Gets an ordered list of the groups on this track + * * @return am ordered {@link List} of the groups on this track */ public List getGroups() { @@ -76,6 +77,7 @@ public class Track implements Identifiable { /** * Gets the number of groups on this track + * * @return the number of groups on this track */ public int getSize() { @@ -84,6 +86,7 @@ public class Track implements Identifiable { /** * Gets the next group on the track, after the one provided + * * @param current the group before the group being requested * @return the group name, or null if the end of the track has been reached * @throws ObjectLacksException if the track does not contain the group given @@ -94,6 +97,7 @@ public class Track implements Identifiable { /** * Gets the group before the group provided + * * @param current the group after the group being requested * @return the group name, or null if the start of the track has been reached * @throws ObjectLacksException if the track does not contain the group given @@ -104,6 +108,7 @@ public class Track implements Identifiable { /** * Gets the next group on the track, after the one provided + * * @param current the group before the group being requested * @return the group name, or null if the end of the track has been reached * @throws ObjectLacksException if the track does not contain the group given @@ -120,6 +125,7 @@ public class Track implements Identifiable { /** * Gets the group before the group provided + * * @param current the group after the group being requested * @return the group name, or null if the start of the track has been reached * @throws ObjectLacksException if the track does not contain the group given @@ -136,6 +142,7 @@ public class Track implements Identifiable { /** * Appends a group to the end of this track + * * @param group the group to append * @throws ObjectAlreadyHasException if the group is already on this track somewhere */ @@ -146,7 +153,8 @@ public class Track implements Identifiable { /** * Inserts a group at a certain position on this track - * @param group the group to be inserted + * + * @param group the group to be inserted * @param position the index position (a value of 0 inserts at the start) * @throws ObjectAlreadyHasException if the group is already on this track somewhere * @throws IndexOutOfBoundsException if the position is less than 0 or greater than the size of the track @@ -158,6 +166,7 @@ public class Track implements Identifiable { /** * Removes a group from this track + * * @param group the group to remove * @throws ObjectLacksException if the group is not on this track */ @@ -167,6 +176,7 @@ public class Track implements Identifiable { /** * Removes a group from this track + * * @param group the group to remove * @throws ObjectLacksException if the group is not on this track */ @@ -177,6 +187,7 @@ public class Track implements Identifiable { /** * Checks if a group features on this track + * * @param group the group to check * @return true if the group is on this track */ @@ -186,6 +197,7 @@ public class Track implements Identifiable { /** * Checks if a group features on this track + * * @param group the group to check * @return true if the group is on this track */ diff --git a/common/src/main/java/me/lucko/luckperms/common/core/model/User.java b/common/src/main/java/me/lucko/luckperms/common/core/model/User.java index a4f0d563e..f92b1cdd7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/model/User.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/model/User.java @@ -26,6 +26,7 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import lombok.ToString; + import me.lucko.luckperms.api.caching.UserData; import me.lucko.luckperms.api.event.events.UserPermissionRefreshEvent; import me.lucko.luckperms.common.LuckPermsPlugin; diff --git a/common/src/main/java/me/lucko/luckperms/common/data/Importer.java b/common/src/main/java/me/lucko/luckperms/common/data/Importer.java index 82653f666..86a8d51cb 100644 --- a/common/src/main/java/me/lucko/luckperms/common/data/Importer.java +++ b/common/src/main/java/me/lucko/luckperms/common/data/Importer.java @@ -22,10 +22,12 @@ package me.lucko.luckperms.common.data; -import com.google.common.base.Splitter; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; + +import com.google.common.base.Splitter; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.CommandManager; import me.lucko.luckperms.common.commands.CommandResult; @@ -35,7 +37,11 @@ import me.lucko.luckperms.common.constants.Constants; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Permission; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; import java.util.stream.Collectors; /** @@ -213,13 +219,11 @@ public class Importer { } private static class Result { + @Getter + private final List output = new ArrayList<>(); @Getter @Setter private String command; - - @Getter - private final List output = new ArrayList<>(); - @Getter @Setter private CommandResult result = CommandResult.FAILURE; diff --git a/common/src/main/java/me/lucko/luckperms/common/data/Log.java b/common/src/main/java/me/lucko/luckperms/common/data/Log.java index 307520539..d714381d0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/data/Log.java +++ b/common/src/main/java/me/lucko/luckperms/common/data/Log.java @@ -22,19 +22,62 @@ package me.lucko.luckperms.common.data; -import com.google.common.collect.ImmutableSortedSet; import lombok.Getter; + +import com.google.common.collect.ImmutableSortedSet; + import me.lucko.luckperms.api.LogEntry; -import java.util.*; +import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.UUID; import java.util.stream.Collectors; public class Log { + private static final int PAGE_ENTRIES = 5; + public static Builder builder() { return new Builder(); } - private static final int PAGE_ENTRIES = 5; + private static SortedMap getPage(Set set, int pageNo, int entries) { + if (pageNo < 1) { + throw new IllegalArgumentException("pageNo cannot be less than 1: " + pageNo); + } + + int minimumEntries = ((pageNo * 5) - entries) + 1; + if (set.size() < minimumEntries) { + throw new IllegalStateException("Log does not contain that many entries. " + + "Requested: " + minimumEntries + ", Log Count: " + set.size()); + } + + final SortedMap out = new TreeMap<>(); + + final int max = minimumEntries + entries - 1; + int index = 0; + for (LogEntry e : set) { + index++; + if (index >= minimumEntries) { + out.put(index, e); + } + if (index == max) { + break; + } + } + + return out; + } + + private static int getMaxPages(int size, int entries) { + return (int) Math.ceil((double) size / entries); + } + + private static int getMaxPages(long size, int entries) { + return (int) Math.ceil((double) size / entries); + } @Getter private final SortedSet content; @@ -141,42 +184,6 @@ public class Log { .count(), PAGE_ENTRIES); } - private static SortedMap getPage(Set set, int pageNo, int entries) { - if (pageNo < 1) { - throw new IllegalArgumentException("pageNo cannot be less than 1: " + pageNo); - } - - int minimumEntries = ((pageNo * 5) - entries) + 1; - if (set.size() < minimumEntries) { - throw new IllegalStateException("Log does not contain that many entries. " + - "Requested: " + minimumEntries + ", Log Count: " + set.size()); - } - - final SortedMap out = new TreeMap<>(); - - final int max = minimumEntries + entries - 1; - int index = 0; - for (LogEntry e : set) { - index++; - if (index >= minimumEntries) { - out.put(index, e); - } - if (index == max) { - break; - } - } - - return out; - } - - private static int getMaxPages(int size, int entries) { - return (int) Math.ceil((double) size / entries); - } - - private static int getMaxPages(long size, int entries) { - return (int) Math.ceil((double) size / entries); - } - @SuppressWarnings("WeakerAccess") public static class Builder { private final SortedSet content = new TreeSet<>(); diff --git a/common/src/main/java/me/lucko/luckperms/common/data/LogEntry.java b/common/src/main/java/me/lucko/luckperms/common/data/LogEntry.java index 8925f7597..cd1c5b740 100644 --- a/common/src/main/java/me/lucko/luckperms/common/data/LogEntry.java +++ b/common/src/main/java/me/lucko/luckperms/common/data/LogEntry.java @@ -73,7 +73,7 @@ public class LogEntry extends me.lucko.luckperms.api.LogEntry { .forEach(s -> Message.LOG.send(s, msg)); } } - + public static class LogEntryBuilder extends AbstractLogEntryBuilder { @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/defaults/LogicParser.java b/common/src/main/java/me/lucko/luckperms/common/defaults/LogicParser.java index 69b11f8ac..0ffa19bf5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/defaults/LogicParser.java +++ b/common/src/main/java/me/lucko/luckperms/common/defaults/LogicParser.java @@ -26,11 +26,12 @@ import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.common.core.NodeFactory; import me.lucko.luckperms.common.core.model.PermissionHolder; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; import java.util.function.Function; import java.util.regex.Pattern; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; + public class LogicParser { private static final ScriptEngine SCRIPT_ENGINE = new ScriptEngineManager().getEngineByName("nashorn"); diff --git a/common/src/main/java/me/lucko/luckperms/common/defaults/Rule.java b/common/src/main/java/me/lucko/luckperms/common/defaults/Rule.java index 6794da952..a9755ec34 100644 --- a/common/src/main/java/me/lucko/luckperms/common/defaults/Rule.java +++ b/common/src/main/java/me/lucko/luckperms/common/defaults/Rule.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.common.defaults; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.ToString; + import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.common.core.NodeFactory; import me.lucko.luckperms.common.core.model.User; @@ -92,13 +93,15 @@ public class Rule { for (String s : toTake) { try { user.unsetPermission(NodeFactory.fromSerialisedNode(s, true)); - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } } for (String s : toGive) { try { user.setPermission(NodeFactory.fromSerialisedNode(s, true)); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } } if (setPrimaryGroup != null) { diff --git a/common/src/main/java/me/lucko/luckperms/common/managers/AbstractManager.java b/common/src/main/java/me/lucko/luckperms/common/managers/AbstractManager.java index fe0a89733..97d4f0b23 100644 --- a/common/src/main/java/me/lucko/luckperms/common/managers/AbstractManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/managers/AbstractManager.java @@ -28,12 +28,14 @@ import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; + import me.lucko.luckperms.common.utils.Identifiable; import java.util.Map; /** * An abstract manager class + * * @param the class used to identify each object held in this manager * @param the class this manager is "managing" */ diff --git a/common/src/main/java/me/lucko/luckperms/common/managers/Manager.java b/common/src/main/java/me/lucko/luckperms/common/managers/Manager.java index bbb7f79fd..d1d5d8b6e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/managers/Manager.java +++ b/common/src/main/java/me/lucko/luckperms/common/managers/Manager.java @@ -29,6 +29,7 @@ import java.util.function.Function; /** * A class which manages instances of a class + * * @param the class used to identify each object held in this manager * @param the class this manager is "managing" */ @@ -36,12 +37,14 @@ public interface Manager> extends Function { /** * Gets a map containing all cached instances held by this manager. + * * @return all instances held in this manager */ Map getAll(); /** * Gets or creates an object by id + * * @param id The id to search by * @return a {@link T} object if the object is loaded or makes and returns a new object */ @@ -49,6 +52,7 @@ public interface Manager> extends Function { /** * Get an object by id + * * @param id The id to search by * @return a {@link T} object if the object is loaded, returns null if the object is not loaded */ @@ -56,6 +60,7 @@ public interface Manager> extends Function { /** * Check to see if a object is loaded or not + * * @param id The id of the object * @return true if the object is loaded */ @@ -63,6 +68,7 @@ public interface Manager> extends Function { /** * Removes and unloads the object from the manager + * * @param t The object to unload */ void unload(T t); diff --git a/common/src/main/java/me/lucko/luckperms/common/managers/UserManager.java b/common/src/main/java/me/lucko/luckperms/common/managers/UserManager.java index 487d0a713..cc391b6e7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/managers/UserManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/managers/UserManager.java @@ -32,6 +32,7 @@ public interface UserManager extends Manager { /** * Get a user object by name + * * @param name The name to search by * @return a {@link User} object if the user is loaded, returns null if the user is not loaded */ @@ -39,6 +40,7 @@ public interface UserManager extends Manager { /** * Get a user object by uuid + * * @param uuid The uuid to search by * @return a {@link User} object if the user is loaded, returns null if the user is not loaded */ @@ -46,12 +48,14 @@ public interface UserManager extends Manager { /** * Gives the user the default group if necessary. + * * @param user the user to give to */ boolean giveDefaultIfNeeded(User user, boolean save); /** * Checks to see if the user is online, and if they are not, runs {@link #unload(Identifiable)} + * * @param user The user to be cleaned up */ void cleanup(User user); diff --git a/common/src/main/java/me/lucko/luckperms/common/managers/impl/GenericGroupManager.java b/common/src/main/java/me/lucko/luckperms/common/managers/impl/GenericGroupManager.java index 32abec3b0..72fb19e2c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/managers/impl/GenericGroupManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/managers/impl/GenericGroupManager.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.managers.impl; import lombok.RequiredArgsConstructor; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.managers.AbstractManager; diff --git a/common/src/main/java/me/lucko/luckperms/common/managers/impl/GenericUserManager.java b/common/src/main/java/me/lucko/luckperms/common/managers/impl/GenericUserManager.java index 8e6b67b20..fc8b70e5d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/managers/impl/GenericUserManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/managers/impl/GenericUserManager.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.managers.impl; import lombok.RequiredArgsConstructor; + import me.lucko.luckperms.api.Node; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.core.UserIdentifier; @@ -36,6 +37,69 @@ import java.util.UUID; @RequiredArgsConstructor public class GenericUserManager extends AbstractManager implements UserManager { + public static boolean giveDefaultIfNeeded(User user, boolean save, LuckPermsPlugin plugin) { + boolean hasGroup = false; + + if (user.getPrimaryGroup() != null && !user.getPrimaryGroup().isEmpty()) { + for (Node node : user.getPermissions(false)) { + if (node.isGroupNode()) { + hasGroup = true; + break; + } + } + } + + if (hasGroup) { + return false; + } + + user.setPrimaryGroup("default"); + try { + user.setPermission("group.default", true); + } catch (ObjectAlreadyHasException ignored) { + } + + if (save) { + plugin.getStorage().saveUser(user); + } + + return true; + } + + /** + * Check whether the user's state indicates that they should be persisted to storage. + * + * @param user the user to check + * @return true if the user should be saved + */ + public static boolean shouldSave(User user) { + if (user.getNodes().size() != 1) { + return true; + } + + for (Node node : user.getNodes()) { + // There's only one. + if (!node.isGroupNode()) { + return true; + } + + if (node.isTemporary() || node.isServerSpecific() || node.isWorldSpecific()) { + return true; + } + + if (!node.getGroupName().equalsIgnoreCase("default")) { + // The user's only node is not the default group one. + return true; + } + } + + if (!user.getPrimaryGroup().equalsIgnoreCase("default")) { + return true; // Not in the default primary group + } + + return false; + } + private final LuckPermsPlugin plugin; @Override @@ -84,65 +148,4 @@ public class GenericUserManager extends AbstractManager im }); }); } - - public static boolean giveDefaultIfNeeded(User user, boolean save, LuckPermsPlugin plugin) { - boolean hasGroup = false; - - if (user.getPrimaryGroup() != null && !user.getPrimaryGroup().isEmpty()) { - for (Node node : user.getPermissions(false)) { - if (node.isGroupNode()) { - hasGroup = true; - break; - } - } - } - - if (hasGroup) { - return false; - } - - user.setPrimaryGroup("default"); - try { - user.setPermission("group.default", true); - } catch (ObjectAlreadyHasException ignored) {} - - if (save) { - plugin.getStorage().saveUser(user); - } - - return true; - } - - /** - * Check whether the user's state indicates that they should be persisted to storage. - * @param user the user to check - * @return true if the user should be saved - */ - public static boolean shouldSave(User user) { - if (user.getNodes().size() != 1) { - return true; - } - - for (Node node : user.getNodes()) { - // There's only one. - if (!node.isGroupNode()) { - return true; - } - - if (node.isTemporary() || node.isServerSpecific() || node.isWorldSpecific()) { - return true; - } - - if (!node.getGroupName().equalsIgnoreCase("default")) { - // The user's only node is not the default group one. - return true; - } - } - - if (!user.getPrimaryGroup().equalsIgnoreCase("default")) { - return true; // Not in the default primary group - } - - return false; - } } diff --git a/common/src/main/java/me/lucko/luckperms/common/messaging/RedisMessaging.java b/common/src/main/java/me/lucko/luckperms/common/messaging/RedisMessaging.java index 7893b7464..2b94cbee0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/messaging/RedisMessaging.java +++ b/common/src/main/java/me/lucko/luckperms/common/messaging/RedisMessaging.java @@ -23,18 +23,20 @@ package me.lucko.luckperms.common.messaging; import lombok.RequiredArgsConstructor; + import me.lucko.luckperms.api.MessagingService; import me.lucko.luckperms.common.LuckPermsPlugin; -import redis.clients.jedis.Jedis; -import redis.clients.jedis.JedisPool; -import redis.clients.jedis.JedisPoolConfig; -import redis.clients.jedis.JedisPubSub; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.UUID; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPoolConfig; +import redis.clients.jedis.JedisPubSub; + /** * Uses Redis to push/receive changes to/from other servers */ diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java index 9c2568f9c..a0931749e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.common.storage; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import lombok.experimental.Delegate; + import me.lucko.luckperms.api.LogEntry; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.core.model.Group; @@ -160,9 +161,13 @@ public class AbstractStorage implements Storage { private interface Delegated { String getName(); + boolean isAcceptingLogins(); + void setAcceptingLogins(boolean b); + void init(); + void shutdown(); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/SplitBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/SplitBacking.java index 7f2e64840..165db75c0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/SplitBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/SplitBacking.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.storage; import com.google.common.collect.ImmutableMap; + import me.lucko.luckperms.api.LogEntry; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.core.model.Group; diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/Storage.java b/common/src/main/java/me/lucko/luckperms/common/storage/Storage.java index 12cbbb367..b4f87c1c1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/Storage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/Storage.java @@ -36,31 +36,54 @@ import java.util.concurrent.CompletableFuture; * Main interface for all Storage providers. */ public interface Storage { - + String getName(); + boolean isAcceptingLogins(); + void setAcceptingLogins(boolean acceptingLogins); + Storage force(); void init(); + void shutdown(); + CompletableFuture logAction(LogEntry entry); + CompletableFuture getLog(); + CompletableFuture loadUser(UUID uuid, String username); + CompletableFuture saveUser(User user); + CompletableFuture cleanupUsers(); + CompletableFuture> getUniqueUsers(); + CompletableFuture createAndLoadGroup(String name); + CompletableFuture loadGroup(String name); + CompletableFuture loadAllGroups(); + CompletableFuture saveGroup(Group group); + CompletableFuture deleteGroup(Group group); + CompletableFuture createAndLoadTrack(String name); + CompletableFuture loadTrack(String name); + CompletableFuture loadAllTracks(); + CompletableFuture saveTrack(Track track); + CompletableFuture deleteTrack(Track track); + CompletableFuture saveUUIDData(String username, UUID uuid); + CompletableFuture getUUID(String username); + CompletableFuture getName(UUID uuid); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java index 6ff3fe80d..d59efcbad 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java @@ -22,10 +22,18 @@ package me.lucko.luckperms.common.storage; -import com.google.common.collect.ImmutableSet; import lombok.experimental.UtilityClass; + +import com.google.common.collect.ImmutableSet; + import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.storage.backing.*; +import me.lucko.luckperms.common.storage.backing.AbstractBacking; +import me.lucko.luckperms.common.storage.backing.H2Backing; +import me.lucko.luckperms.common.storage.backing.JSONBacking; +import me.lucko.luckperms.common.storage.backing.MongoDBBacking; +import me.lucko.luckperms.common.storage.backing.MySQLBacking; +import me.lucko.luckperms.common.storage.backing.SQLiteBacking; +import me.lucko.luckperms.common.storage.backing.YAMLBacking; import java.io.File; import java.util.HashMap; @@ -80,7 +88,7 @@ public class StorageFactory { storage.init(); return storage; } - + private static Storage fromString(String storageMethod, LuckPermsPlugin plugin) { return AbstractStorage.wrap(plugin, backingFromString(storageMethod, plugin)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/AbstractBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/AbstractBacking.java index a64f437da..65f4237e0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/AbstractBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/AbstractBacking.java @@ -26,6 +26,7 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; + import me.lucko.luckperms.api.LogEntry; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.core.model.Group; @@ -50,25 +51,45 @@ public abstract class AbstractBacking { private boolean acceptingLogins = false; public abstract void init(); + public abstract void shutdown(); + public abstract boolean logAction(LogEntry entry); + public abstract Log getLog(); + public abstract boolean loadUser(UUID uuid, String username); + public abstract boolean saveUser(User user); + public abstract boolean cleanupUsers(); + public abstract Set getUniqueUsers(); + public abstract boolean createAndLoadGroup(String name); + public abstract boolean loadGroup(String name); + public abstract boolean loadAllGroups(); + public abstract boolean saveGroup(Group group); + public abstract boolean deleteGroup(Group group); + public abstract boolean createAndLoadTrack(String name); + public abstract boolean loadTrack(String name); + public abstract boolean loadAllTracks(); + public abstract boolean saveTrack(Track track); + public abstract boolean deleteTrack(Track track); + public abstract boolean saveUUIDData(String username, UUID uuid); + public abstract UUID getUUID(String username); + public abstract String getName(UUID uuid); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/FlatfileBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/FlatfileBacking.java index 4e5de670a..f53c1d342 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/FlatfileBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/FlatfileBacking.java @@ -23,29 +23,41 @@ package me.lucko.luckperms.common.storage.backing; import lombok.Cleanup; + import me.lucko.luckperms.api.LogEntry; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.constants.Constants; import me.lucko.luckperms.common.data.Log; -import java.io.*; -import java.util.*; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.*; +import java.util.logging.FileHandler; import java.util.logging.Formatter; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; abstract class FlatfileBacking extends AbstractBacking { private static final String LOG_FORMAT = "%s(%s): [%s] %s(%s) --> %s"; private final Logger actionLogger = Logger.getLogger("lp_actions"); - private Map uuidCache = new ConcurrentHashMap<>(); - private final File pluginDir; - private File uuidData; - private File actionLog; File usersDir; File groupsDir; File tracksDir; + private Map uuidCache = new ConcurrentHashMap<>(); + private File uuidData; + private File actionLog; FlatfileBacking(LuckPermsPlugin plugin, String name, File pluginDir) { super(plugin, name); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/H2Backing.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/H2Backing.java index 579b8c1d9..a11792c76 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/H2Backing.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/H2Backing.java @@ -25,7 +25,11 @@ package me.lucko.luckperms.common.storage.backing; import me.lucko.luckperms.common.LuckPermsPlugin; import java.io.File; -import java.sql.*; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; public class H2Backing extends SQLBacking { @@ -36,8 +40,8 @@ public class H2Backing extends SQLBacking { private static final String CREATETABLE_ACTION = "CREATE TABLE IF NOT EXISTS `lp_actions` (`id` INT AUTO_INCREMENT NOT NULL, `time` BIGINT NOT NULL, `actor_uuid` VARCHAR(36) NOT NULL, `actor_name` VARCHAR(16) NOT NULL, `type` CHAR(1) NOT NULL, `acted_uuid` VARCHAR(36) NOT NULL, `acted_name` VARCHAR(36) NOT NULL, `action` VARCHAR(256) NOT NULL, PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8;"; private final File file; - private Connection connection = null; private final Object connectionLock = new Object(); + private Connection connection = null; public H2Backing(LuckPermsPlugin plugin, File file) { super(plugin, "H2"); @@ -123,7 +127,8 @@ public class H2Backing extends SQLBacking { if (connection == null || connection.isClosed()) { try { Class.forName("org.h2.Driver"); - } catch (ClassNotFoundException ignored) {} + } catch (ClassNotFoundException ignored) { + } connection = DriverManager.getConnection("jdbc:h2:" + file.getAbsolutePath()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/JSONBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/JSONBacking.java index 7ff6a849a..e142d8c7f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/JSONBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/JSONBacking.java @@ -22,9 +22,11 @@ package me.lucko.luckperms.common.storage.backing; +import lombok.Cleanup; + import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; -import lombok.Cleanup; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.core.UserIdentifier; import me.lucko.luckperms.common.core.model.Group; @@ -34,8 +36,19 @@ import me.lucko.luckperms.common.managers.GroupManager; import me.lucko.luckperms.common.managers.TrackManager; import me.lucko.luckperms.common.managers.impl.GenericUserManager; -import java.io.*; -import java.util.*; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.Callable; import java.util.stream.Collectors; @@ -43,6 +56,15 @@ import static me.lucko.luckperms.common.core.model.PermissionHolder.exportToLega @SuppressWarnings("ResultOfMethodCallIgnored") public class JSONBacking extends FlatfileBacking { + private static T call(Callable c, T def) { + try { + return c.call(); + } catch (Exception e) { + e.printStackTrace(); + return def; + } + } + public JSONBacking(LuckPermsPlugin plugin, File pluginDir) { super(plugin, "JSON", pluginDir); } @@ -537,15 +559,6 @@ public class JSONBacking extends FlatfileBacking { } } - private static T call(Callable c, T def) { - try { - return c.call(); - } catch (Exception e) { - e.printStackTrace(); - return def; - } - } - interface WriteOperation { boolean onRun(JsonWriter writer) throws IOException; } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/MongoDBBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/MongoDBBacking.java index c57e94185..33b035186 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/MongoDBBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/MongoDBBacking.java @@ -29,6 +29,7 @@ import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoCursor; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.InsertOneOptions; + import me.lucko.luckperms.api.LogEntry; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.core.UserIdentifier; @@ -40,9 +41,16 @@ import me.lucko.luckperms.common.managers.GroupManager; import me.lucko.luckperms.common.managers.TrackManager; import me.lucko.luckperms.common.managers.impl.GenericUserManager; import me.lucko.luckperms.common.storage.DatastoreConfiguration; + import org.bson.Document; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.Callable; import java.util.stream.Collectors; @@ -51,6 +59,58 @@ import static me.lucko.luckperms.common.core.model.PermissionHolder.exportToLega @SuppressWarnings("unchecked") public class MongoDBBacking extends AbstractBacking { + private static T call(Callable c, T def) { + try { + return c.call(); + } catch (Exception e) { + e.printStackTrace(); + return def; + } + } + + /* MongoDB does not allow '.' or '$' in key names. + See: https://docs.mongodb.com/manual/reference/limits/#Restrictions-on-Field-Names + The following two methods convert the node maps so they can be stored. */ + private static Map convert(Map map) { + return map.entrySet().stream() + .collect(Collectors.toMap(e -> e.getKey().replace(".", "[**DOT**]").replace("$", "[**DOLLAR**]"), Map.Entry::getValue)); + } + + private static Map revert(Map map) { + return map.entrySet().stream() + .collect(Collectors.toMap(e -> e.getKey().replace("[**DOT**]", ".").replace("[**DOLLAR**]", "$"), Map.Entry::getValue)); + } + + private static Document fromUser(User user) { + Document main = new Document("_id", user.getUuid()) + .append("name", user.getName()) + .append("primaryGroup", user.getPrimaryGroup()); + + Document perms = new Document(); + for (Map.Entry e : convert(exportToLegacy(user.getNodes())).entrySet()) { + perms.append(e.getKey(), e.getValue()); + } + + main.append("perms", perms); + return main; + } + + private static Document fromGroup(Group group) { + Document main = new Document("_id", group.getName()); + + Document perms = new Document(); + for (Map.Entry e : convert(exportToLegacy(group.getNodes())).entrySet()) { + perms.append(e.getKey(), e.getValue()); + } + + main.append("perms", perms); + return main; + } + + private static Document fromTrack(Track track) { + return new Document("_id", track.getName()).append("groups", track.getGroups()); + } + private final DatastoreConfiguration configuration; private MongoClient mongoClient; private MongoDatabase database; @@ -490,56 +550,4 @@ public class MongoDBBacking extends AbstractBacking { return null; }, null); } - - private static T call(Callable c, T def) { - try { - return c.call(); - } catch (Exception e) { - e.printStackTrace(); - return def; - } - } - - /* MongoDB does not allow '.' or '$' in key names. - See: https://docs.mongodb.com/manual/reference/limits/#Restrictions-on-Field-Names - The following two methods convert the node maps so they can be stored. */ - private static Map convert(Map map) { - return map.entrySet().stream() - .collect(Collectors.toMap(e -> e.getKey().replace(".", "[**DOT**]").replace("$", "[**DOLLAR**]"), Map.Entry::getValue)); - } - - private static Map revert(Map map) { - return map.entrySet().stream() - .collect(Collectors.toMap(e -> e.getKey().replace("[**DOT**]", ".").replace("[**DOLLAR**]", "$"), Map.Entry::getValue)); - } - - private static Document fromUser(User user) { - Document main = new Document("_id", user.getUuid()) - .append("name", user.getName()) - .append("primaryGroup", user.getPrimaryGroup()); - - Document perms = new Document(); - for (Map.Entry e : convert(exportToLegacy(user.getNodes())).entrySet()) { - perms.append(e.getKey(), e.getValue()); - } - - main.append("perms", perms); - return main; - } - - private static Document fromGroup(Group group) { - Document main = new Document("_id", group.getName()); - - Document perms = new Document(); - for (Map.Entry e : convert(exportToLegacy(group.getNodes())).entrySet()) { - perms.append(e.getKey(), e.getValue()); - } - - main.append("perms", perms); - return main; - } - - private static Document fromTrack(Track track) { - return new Document("_id", track.getName()).append("groups", track.getGroups()); - } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/MySQLBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/MySQLBacking.java index 03707b2f8..4932ec6ac 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/MySQLBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/MySQLBacking.java @@ -24,6 +24,7 @@ package me.lucko.luckperms.common.storage.backing; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.storage.DatastoreConfiguration; @@ -56,7 +57,7 @@ public class MySQLBacking extends SQLBacking { final String database = configuration.getDatabase(); final String username = configuration.getUsername(); final String password = configuration.getPassword(); - + config.setMaximumPoolSize(configuration.getPoolSize()); config.setPoolName("luckperms"); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLBacking.java index dc4913fc2..581986fdf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLBacking.java @@ -24,6 +24,7 @@ package me.lucko.luckperms.common.storage.backing; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; + import me.lucko.luckperms.api.LogEntry; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.core.UserIdentifier; @@ -40,15 +41,23 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; import static me.lucko.luckperms.common.core.model.PermissionHolder.exportToLegacy; abstract class SQLBacking extends AbstractBacking { - private static final QueryPS EMPTY_PS = preparedStatement -> {}; + private static final QueryPS EMPTY_PS = preparedStatement -> { + }; - private static final Type NM_TYPE = new TypeToken>(){}.getType(); - private static final Type T_TYPE = new TypeToken>(){}.getType(); + private static final Type NM_TYPE = new TypeToken>() { + }.getType(); + private static final Type T_TYPE = new TypeToken>() { + }.getType(); private static final String USER_INSERT = "INSERT INTO lp_users VALUES(?, ?, ?, ?)"; private static final String USER_SELECT = "SELECT * FROM lp_users WHERE uuid=?"; @@ -77,6 +86,15 @@ abstract class SQLBacking extends AbstractBacking { private static final String ACTION_INSERT = "INSERT INTO lp_actions(`time`, `actor_uuid`, `actor_name`, `type`, `acted_uuid`, `acted_name`, `action`) VALUES(?, ?, ?, ?, ?, ?, ?)"; private static final String ACTION_SELECT_ALL = "SELECT * FROM lp_actions"; + protected static void close(AutoCloseable closeable) { + if (closeable != null) { + try { + closeable.close(); + } catch (Exception ignored) { + } + } + } + private final Gson gson; SQLBacking(LuckPermsPlugin plugin, String name) { @@ -86,15 +104,8 @@ abstract class SQLBacking extends AbstractBacking { abstract Connection getConnection() throws SQLException; - protected static void close(AutoCloseable closeable) { - if (closeable != null) { - try { - closeable.close(); - } catch (Exception ignored) {} - } - } - abstract boolean runQuery(String query, QueryPS queryPS); + abstract boolean runQuery(String query, QueryPS queryPS, QueryRS queryRS); boolean runQuery(String query) { diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLiteBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLiteBacking.java index c25158fdb..f28757423 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLiteBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLiteBacking.java @@ -25,7 +25,11 @@ package me.lucko.luckperms.common.storage.backing; import me.lucko.luckperms.common.LuckPermsPlugin; import java.io.File; -import java.sql.*; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; public class SQLiteBacking extends SQLBacking { @@ -36,8 +40,8 @@ public class SQLiteBacking extends SQLBacking { private static final String CREATETABLE_ACTION = "CREATE TABLE IF NOT EXISTS `lp_actions` (`id` INTEGER PRIMARY KEY NOT NULL, `time` BIG INT NOT NULL, `actor_uuid` VARCHAR(36) NOT NULL, `actor_name` VARCHAR(16) NOT NULL, `type` CHAR(1) NOT NULL, `acted_uuid` VARCHAR(36) NOT NULL, `acted_name` VARCHAR(36) NOT NULL, `action` VARCHAR(256) NOT NULL);"; private final File file; - private Connection connection = null; private final Object connectionLock = new Object(); + private Connection connection = null; public SQLiteBacking(LuckPermsPlugin plugin, File file) { super(plugin, "SQLite"); @@ -123,7 +127,8 @@ public class SQLiteBacking extends SQLBacking { if (connection == null || connection.isClosed()) { try { Class.forName("org.sqlite.JDBC"); - } catch (ClassNotFoundException ignored) {} + } catch (ClassNotFoundException ignored) { + } connection = DriverManager.getConnection("jdbc:sqlite:" + file.getAbsolutePath()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/YAMLBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/YAMLBacking.java index ae46178a6..78b72179b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/YAMLBacking.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/YAMLBacking.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.storage.backing; import lombok.Cleanup; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.core.UserIdentifier; import me.lucko.luckperms.common.core.model.Group; @@ -31,11 +32,22 @@ import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.managers.GroupManager; import me.lucko.luckperms.common.managers.TrackManager; import me.lucko.luckperms.common.managers.impl.GenericUserManager; + import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; -import java.io.*; -import java.util.*; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.Callable; import java.util.stream.Collectors; @@ -43,16 +55,25 @@ import static me.lucko.luckperms.common.core.model.PermissionHolder.exportToLega @SuppressWarnings({"unchecked", "ResultOfMethodCallIgnored"}) public class YAMLBacking extends FlatfileBacking { - public YAMLBacking(LuckPermsPlugin plugin, File pluginDir) { - super(plugin, "YAML", pluginDir); - } - private static Yaml getYaml() { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); return new Yaml(options); } + private static T call(Callable c, T def) { + try { + return c.call(); + } catch (Exception e) { + e.printStackTrace(); + return def; + } + } + + public YAMLBacking(LuckPermsPlugin plugin, File pluginDir) { + super(plugin, "YAML", pluginDir); + } + private boolean doRead(File file, ReadOperation readOperation) { boolean success = false; try { @@ -418,15 +439,6 @@ public class YAMLBacking extends FlatfileBacking { } } - private static T call(Callable c, T def) { - try { - return c.call(); - } catch (Exception e) { - e.printStackTrace(); - return def; - } - } - interface ReadOperation { boolean onRun(Map values); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/BufferedOutputStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/BufferedOutputStorage.java index d65933af1..3757baa44 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/BufferedOutputStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/BufferedOutputStorage.java @@ -26,6 +26,7 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.experimental.Delegate; + import me.lucko.luckperms.common.core.UserIdentifier; import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.Track; @@ -125,10 +126,15 @@ public class BufferedOutputStorage implements Storage, Runnable { private interface Exclude { Storage force(); + CompletableFuture shutdown(); + CompletableFuture saveUser(User user); + CompletableFuture saveGroup(Group group); + CompletableFuture saveTrack(Track track); + CompletableFuture saveUUIDData(String username, UUID uuid); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/TolerantStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/TolerantStorage.java index 6da2144a5..72b5737e1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/TolerantStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/TolerantStorage.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.common.storage.wrappings; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import lombok.experimental.Delegate; + import me.lucko.luckperms.api.LogEntry; import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.Track; @@ -262,8 +263,11 @@ public class TolerantStorage implements Storage { private interface Delegated { String getName(); + boolean isAcceptingLogins(); + void setAcceptingLogins(boolean b); + void init(); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/tasks/ExpireTemporaryTask.java b/common/src/main/java/me/lucko/luckperms/common/tasks/ExpireTemporaryTask.java index bef08af9f..95daf4100 100644 --- a/common/src/main/java/me/lucko/luckperms/common/tasks/ExpireTemporaryTask.java +++ b/common/src/main/java/me/lucko/luckperms/common/tasks/ExpireTemporaryTask.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.tasks; import lombok.AllArgsConstructor; + import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.User; diff --git a/common/src/main/java/me/lucko/luckperms/common/tasks/UpdateTask.java b/common/src/main/java/me/lucko/luckperms/common/tasks/UpdateTask.java index 0246998aa..de4827638 100644 --- a/common/src/main/java/me/lucko/luckperms/common/tasks/UpdateTask.java +++ b/common/src/main/java/me/lucko/luckperms/common/tasks/UpdateTask.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.tasks; import lombok.AllArgsConstructor; + import me.lucko.luckperms.api.event.events.PostSyncEvent; import me.lucko.luckperms.api.event.events.PreSyncEvent; import me.lucko.luckperms.common.LuckPermsPlugin; diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/AbstractListener.java b/common/src/main/java/me/lucko/luckperms/common/utils/AbstractListener.java index 535abee96..4fd9a5cbe 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/AbstractListener.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/AbstractListener.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.utils; import lombok.AllArgsConstructor; + import me.lucko.luckperms.api.event.events.UserFirstLoginEvent; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.core.UuidCache; diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/ArgumentChecker.java b/common/src/main/java/me/lucko/luckperms/common/utils/ArgumentChecker.java index 8ecda1f05..ea8c4340b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/ArgumentChecker.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/ArgumentChecker.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.utils; import lombok.experimental.UtilityClass; + import me.lucko.luckperms.common.constants.Patterns; /** diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/Buffer.java b/common/src/main/java/me/lucko/luckperms/common/utils/Buffer.java index c7a5bad28..35af989bb 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/Buffer.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/Buffer.java @@ -22,7 +22,11 @@ package me.lucko.luckperms.common.utils; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.Setter; import java.util.LinkedList; import java.util.List; diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/BufferedRequest.java b/common/src/main/java/me/lucko/luckperms/common/utils/BufferedRequest.java index 2d91c6605..137ca91f5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/BufferedRequest.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/BufferedRequest.java @@ -77,13 +77,11 @@ public abstract class BufferedRequest { private static class Processor implements Runnable { private final long delayMillis; private final Supplier supplier; - + private final ReentrantLock lock = new ReentrantLock(); + private final CompletableFuture future = new CompletableFuture(); @Getter private boolean usable = true; - - private final ReentrantLock lock = new ReentrantLock(); private long executionTime; - private final CompletableFuture future = new CompletableFuture(); @Override public void run() { diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/Cache.java b/common/src/main/java/me/lucko/luckperms/common/utils/Cache.java index ce208499b..8b58aaca1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/Cache.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/Cache.java @@ -30,6 +30,7 @@ import java.util.function.Supplier; /** * Thread-safe caching utility + * * @param the type being stored */ @RequiredArgsConstructor diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/DateUtil.java b/common/src/main/java/me/lucko/luckperms/common/utils/DateUtil.java index 100f0cf5a..128455653 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/DateUtil.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/DateUtil.java @@ -27,7 +27,8 @@ public class DateUtil { /** * Converts a time string to a unix timestamp - * @param time the time string + * + * @param time the time string * @param future if the date is in the future, as opposed to the past * @return a unix timestamp * @throws IllegalDateException if the date input was invalid diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/DebugHandler.java b/common/src/main/java/me/lucko/luckperms/common/utils/DebugHandler.java index 6b424d578..852a6c1be 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/DebugHandler.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/DebugHandler.java @@ -22,10 +22,12 @@ package me.lucko.luckperms.common.utils; -import com.google.common.collect.ImmutableList; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; + +import com.google.common.collect.ImmutableList; + import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.constants.Message; @@ -48,13 +50,14 @@ public class DebugHandler { executor.execute(() -> { while (true) { - for (Data e; (e = queue.poll()) != null;) { + for (Data e; (e = queue.poll()) != null; ) { handleOutput(e.getChecked(), e.getNode(), e.getValue()); } try { Thread.sleep(200); - } catch (InterruptedException ignored) {} + } catch (InterruptedException ignored) { + } } }); } diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/ExtractedContexts.java b/common/src/main/java/me/lucko/luckperms/common/utils/ExtractedContexts.java index 7c989f969..2a9ef1bc1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/ExtractedContexts.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/ExtractedContexts.java @@ -24,6 +24,7 @@ package me.lucko.luckperms.common.utils; import lombok.Getter; import lombok.ToString; + import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.context.MutableContextSet; diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/Identifiable.java b/common/src/main/java/me/lucko/luckperms/common/utils/Identifiable.java index aa27c088c..ca478d36e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/Identifiable.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/Identifiable.java @@ -24,13 +24,13 @@ package me.lucko.luckperms.common.utils; /** * Interface to represent an identifiable object - * @param */ public interface Identifiable { /** * Returns the objects identifier. * If the type is a {@link String}, this method must return a {@link String#toLowerCase()} representation + * * @return the identifier */ T getId(); diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/ImmutableCollectors.java b/common/src/main/java/me/lucko/luckperms/common/utils/ImmutableCollectors.java index dad6cd791..85b86026f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/ImmutableCollectors.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/ImmutableCollectors.java @@ -22,10 +22,11 @@ package me.lucko.luckperms.common.utils; +import lombok.experimental.UtilityClass; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import lombok.experimental.UtilityClass; import java.util.function.Function; import java.util.stream.Collector; diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/ImmutableLocalizedNode.java b/common/src/main/java/me/lucko/luckperms/common/utils/ImmutableLocalizedNode.java index a0819f935..6ba821f51 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/ImmutableLocalizedNode.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/ImmutableLocalizedNode.java @@ -22,8 +22,13 @@ package me.lucko.luckperms.common.utils; -import lombok.*; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NonNull; +import lombok.ToString; import lombok.experimental.Delegate; + import me.lucko.luckperms.api.LocalizedNode; import me.lucko.luckperms.api.Node; diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/LocaleManager.java b/common/src/main/java/me/lucko/luckperms/common/utils/LocaleManager.java index f36e6cb46..6e49109df 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/LocaleManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/LocaleManager.java @@ -22,9 +22,12 @@ package me.lucko.luckperms.common.utils; -import com.google.common.collect.ImmutableMap; import lombok.Cleanup; + +import com.google.common.collect.ImmutableMap; + import me.lucko.luckperms.common.constants.Message; + import org.yaml.snakeyaml.Yaml; import java.io.File; diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/LogFactory.java b/common/src/main/java/me/lucko/luckperms/common/utils/LogFactory.java index 241659b7a..f583a5d2b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/LogFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/LogFactory.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.common.utils; import lombok.experimental.UtilityClass; + import me.lucko.luckperms.api.Logger; /** diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/PermissionCache.java b/common/src/main/java/me/lucko/luckperms/common/utils/PermissionCache.java index 7fe0656ab..6cd7b7e8e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/PermissionCache.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/PermissionCache.java @@ -22,10 +22,11 @@ package me.lucko.luckperms.common.utils; -import com.google.common.base.Splitter; import lombok.Getter; import lombok.NonNull; +import com.google.common.base.Splitter; + import java.util.List; import java.util.Map; import java.util.Optional; @@ -46,13 +47,14 @@ public class PermissionCache { executor.execute(() -> { while (true) { - for (String e; (e = queue.poll()) != null;) { + for (String e; (e = queue.poll()) != null; ) { insert(e.toLowerCase()); } try { Thread.sleep(5000); - } catch (InterruptedException ignored) {} + } catch (InterruptedException ignored) { + } } }); } diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/ShorthandParser.java b/common/src/main/java/me/lucko/luckperms/common/utils/ShorthandParser.java index ccac1a55f..c9ac538c1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/ShorthandParser.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/ShorthandParser.java @@ -22,9 +22,10 @@ package me.lucko.luckperms.common.utils; +import lombok.experimental.UtilityClass; + import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; -import lombok.experimental.UtilityClass; import java.util.ArrayList; import java.util.HashSet; @@ -116,6 +117,15 @@ public class ShorthandParser { private static class NumericRangeParser implements Function> { + private static boolean isInt(String a) { + try { + Integer.parseInt(a); + return true; + } catch (NumberFormatException e) { + return false; + } + } + @Override public List apply(String s) { int index = s.indexOf("-"); @@ -131,19 +141,18 @@ public class ShorthandParser { } return null; } - - private static boolean isInt(String a) { - try { - Integer.parseInt(a); - return true; - } catch (NumberFormatException e) { - return false; - } - } } private static class CharacterRangeParser implements Function> { + private static List getCharRange(char a, char b) { + List s = new ArrayList<>(); + for (char c = a; c <= b; c++) { + s.add(Character.toString(c)); + } + return s; + } + @Override public List apply(String s) { int index = s.indexOf("-"); @@ -158,14 +167,6 @@ public class ShorthandParser { } return null; } - - private static List getCharRange(char a, char b) { - List s = new ArrayList<>(); - for (char c = a; c <= b; c++) { - s.add(Character.toString(c)); - } - return s; - } } } diff --git a/pom.xml b/pom.xml index dfc971ccb..119235deb 100644 --- a/pom.xml +++ b/pom.xml @@ -1,12 +1,12 @@ - 4.0.0 me.lucko.luckperms luckperms - 2.15-SNAPSHOT + 2.16-SNAPSHOT common api @@ -38,7 +38,7 @@ UTF-8 - 2.15 + 2.16 diff --git a/sponge/pom.xml b/sponge/pom.xml index d0de596c9..d82f36268 100644 --- a/sponge/pom.xml +++ b/sponge/pom.xml @@ -1,11 +1,11 @@ - luckperms me.lucko.luckperms - 2.15-SNAPSHOT + 2.16-SNAPSHOT 4.0.0 diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java index 8dbcc95a3..c7d06b143 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java @@ -22,8 +22,10 @@ package me.lucko.luckperms.sponge; -import com.google.inject.Inject; import lombok.Getter; + +import com.google.inject.Inject; + import me.lucko.luckperms.ApiHandler; import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.LuckPermsApi; @@ -48,7 +50,11 @@ import me.lucko.luckperms.common.storage.Storage; import me.lucko.luckperms.common.storage.StorageFactory; import me.lucko.luckperms.common.tasks.ExpireTemporaryTask; import me.lucko.luckperms.common.tasks.UpdateTask; -import me.lucko.luckperms.common.utils.*; +import me.lucko.luckperms.common.utils.BufferedRequest; +import me.lucko.luckperms.common.utils.DebugHandler; +import me.lucko.luckperms.common.utils.LocaleManager; +import me.lucko.luckperms.common.utils.LogFactory; +import me.lucko.luckperms.common.utils.PermissionCache; import me.lucko.luckperms.sponge.commands.SpongeMainCommand; import me.lucko.luckperms.sponge.contexts.WorldCalculator; import me.lucko.luckperms.sponge.managers.SpongeGroupManager; @@ -56,6 +62,7 @@ import me.lucko.luckperms.sponge.managers.SpongeUserManager; import me.lucko.luckperms.sponge.service.LuckPermsService; import me.lucko.luckperms.sponge.timings.LPTimings; import me.lucko.luckperms.sponge.utils.VersionData; + import org.slf4j.Logger; import org.spongepowered.api.Game; import org.spongepowered.api.Sponge; @@ -81,7 +88,12 @@ import org.spongepowered.api.text.Text; import java.io.File; import java.nio.file.Path; -import java.util.*; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -91,31 +103,23 @@ import java.util.stream.StreamSupport; @Plugin(id = "luckperms", name = "LuckPerms", version = VersionData.VERSION, authors = {"Luck"}, description = "A permissions plugin") public class LPSpongePlugin implements LuckPermsPlugin { + private final Set ignoringLogs = ConcurrentHashMap.newKeySet(); @Inject private Logger logger; - @Inject private Game game; - @Inject @ConfigDir(sharedRoot = false) private Path configDir; - private Scheduler scheduler = Sponge.getScheduler(); - @Inject @SynchronousExecutor private SpongeExecutorService syncExecutor; - @Inject @AsynchronousExecutor private SpongeExecutorService asyncExecutor; - private LPTimings timings; - private boolean lateLoad = false; - - private final Set ignoringLogs = ConcurrentHashMap.newKeySet(); private LPConfiguration configuration; private SpongeUserManager userManager; private SpongeGroupManager groupManager; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCalculatorFactory.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCalculatorFactory.java index b0d4721f8..d23519897 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCalculatorFactory.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCalculatorFactory.java @@ -22,8 +22,10 @@ package me.lucko.luckperms.sponge; -import com.google.common.collect.ImmutableList; import lombok.AllArgsConstructor; + +import com.google.common.collect.ImmutableList; + import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.common.calculators.AbstractCalculatorFactory; import me.lucko.luckperms.common.calculators.PermissionCalculator; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommand.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommand.java index 25b37f3fe..1283b06cb 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommand.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommand.java @@ -22,12 +22,13 @@ package me.lucko.luckperms.sponge; -import co.aikar.timings.Timing; import com.google.common.base.Splitter; + import me.lucko.luckperms.common.commands.CommandManager; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.constants.Patterns; import me.lucko.luckperms.sponge.timings.LPTiming; + import org.spongepowered.api.command.CommandCallable; import org.spongepowered.api.command.CommandException; import org.spongepowered.api.command.CommandResult; @@ -36,10 +37,13 @@ import org.spongepowered.api.text.Text; import org.spongepowered.api.world.Location; import org.spongepowered.api.world.World; -import javax.annotation.Nullable; import java.util.List; import java.util.Optional; +import javax.annotation.Nullable; + +import co.aikar.timings.Timing; + @SuppressWarnings("NullableProblems") class SpongeCommand extends CommandManager implements CommandCallable { private final LPSpongePlugin plugin; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeConfig.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeConfig.java index ce2904423..8ecc0601c 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeConfig.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeConfig.java @@ -23,11 +23,8 @@ package me.lucko.luckperms.sponge; import com.google.common.base.Splitter; + import me.lucko.luckperms.common.config.AbstractConfiguration; -import ninja.leaping.configurate.ConfigurationNode; -import ninja.leaping.configurate.commented.CommentedConfigurationNode; -import ninja.leaping.configurate.hocon.HoconConfigurationLoader; -import ninja.leaping.configurate.loader.ConfigurationLoader; import java.io.File; import java.io.IOException; @@ -39,6 +36,11 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import ninja.leaping.configurate.ConfigurationNode; +import ninja.leaping.configurate.commented.CommentedConfigurationNode; +import ninja.leaping.configurate.hocon.HoconConfigurationLoader; +import ninja.leaping.configurate.loader.ConfigurationLoader; + class SpongeConfig extends AbstractConfiguration { private ConfigurationNode root; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeListener.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeListener.java index 84d4f765f..71136bf5c 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeListener.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeListener.java @@ -22,13 +22,13 @@ package me.lucko.luckperms.sponge; -import co.aikar.timings.Timing; import me.lucko.luckperms.api.caching.UserData; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.utils.AbstractListener; import me.lucko.luckperms.sponge.timings.LPTiming; + import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.Order; @@ -41,6 +41,8 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import co.aikar.timings.Timing; + @SuppressWarnings("WeakerAccess") public class SpongeListener extends AbstractListener { private final LPSpongePlugin plugin; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeSenderFactory.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeSenderFactory.java index 760bf14d0..b5006e614 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeSenderFactory.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeSenderFactory.java @@ -25,6 +25,7 @@ package me.lucko.luckperms.sponge; import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.commands.sender.SenderFactory; import me.lucko.luckperms.common.constants.Constants; + import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.text.serializer.TextSerializers; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/calculators/DefaultsProcessor.java b/sponge/src/main/java/me/lucko/luckperms/sponge/calculators/DefaultsProcessor.java index 17e6a4ef9..953b67c43 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/calculators/DefaultsProcessor.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/calculators/DefaultsProcessor.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.sponge.calculators; import lombok.AllArgsConstructor; + import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.common.calculators.PermissionProcessor; @@ -37,7 +38,7 @@ public class DefaultsProcessor implements PermissionProcessor { @Override public Tristate hasPermission(String permission) { - Tristate t = service.getUserSubjects().getDefaultSubject().resolve(service).getPermissionValue(contexts, permission); + Tristate t = service.getUserSubjects().getDefaultSubject().resolve(service).getPermissionValue(contexts, permission); if (t != Tristate.UNDEFINED) { return t; } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionClear.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionClear.java index 4274cb032..931d3d17f 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionClear.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionClear.java @@ -33,6 +33,7 @@ import me.lucko.luckperms.common.commands.utils.ArgumentUtils; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.utils.Predicates; + import org.spongepowered.api.service.permission.SubjectData; import java.util.List; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionInfo.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionInfo.java index 434329fee..42f46c308 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionInfo.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionInfo.java @@ -33,6 +33,7 @@ import me.lucko.luckperms.common.commands.utils.ArgumentUtils; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.utils.Predicates; + import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.permission.SubjectData; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionSet.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionSet.java index 681cc2680..bc0f73c25 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionSet.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionSet.java @@ -33,6 +33,7 @@ import me.lucko.luckperms.common.commands.utils.ArgumentUtils; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.utils.Predicates; + import org.spongepowered.api.service.permission.SubjectData; import java.util.List; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionUnset.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionUnset.java index 5e51be312..e87a1c6bf 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionUnset.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/OptionUnset.java @@ -33,6 +33,7 @@ import me.lucko.luckperms.common.commands.utils.ArgumentUtils; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.utils.Predicates; + import org.spongepowered.api.service.permission.SubjectData; import java.util.List; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentAdd.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentAdd.java index cc69229a7..cfac31da1 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentAdd.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentAdd.java @@ -33,6 +33,7 @@ import me.lucko.luckperms.common.commands.utils.ArgumentUtils; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.utils.Predicates; + import org.spongepowered.api.Sponge; import org.spongepowered.api.service.permission.PermissionService; import org.spongepowered.api.service.permission.Subject; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentClear.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentClear.java index 976f8e0b3..66a796dd0 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentClear.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentClear.java @@ -33,6 +33,7 @@ import me.lucko.luckperms.common.commands.utils.ArgumentUtils; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.utils.Predicates; + import org.spongepowered.api.service.permission.SubjectData; import java.util.List; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java index 425a48e6f..1007f5960 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java @@ -33,6 +33,7 @@ import me.lucko.luckperms.common.commands.utils.ArgumentUtils; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.utils.Predicates; + import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.permission.Subject; import org.spongepowered.api.service.permission.SubjectData; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentRemove.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentRemove.java index 60097af7d..6d567c323 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentRemove.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentRemove.java @@ -33,6 +33,7 @@ import me.lucko.luckperms.common.commands.utils.ArgumentUtils; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.utils.Predicates; + import org.spongepowered.api.Sponge; import org.spongepowered.api.service.permission.PermissionService; import org.spongepowered.api.service.permission.Subject; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionClear.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionClear.java index 9d97227d8..ae7f647a8 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionClear.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionClear.java @@ -33,6 +33,7 @@ import me.lucko.luckperms.common.commands.utils.ArgumentUtils; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.utils.Predicates; + import org.spongepowered.api.service.permission.SubjectData; import java.util.List; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionInfo.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionInfo.java index ae08114d9..502043ec9 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionInfo.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionInfo.java @@ -33,6 +33,7 @@ import me.lucko.luckperms.common.commands.utils.ArgumentUtils; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.utils.Predicates; + import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.permission.SubjectData; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionSet.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionSet.java index 0f2f3d40a..146f53d58 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionSet.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/PermissionSet.java @@ -33,6 +33,7 @@ import me.lucko.luckperms.common.commands.utils.ArgumentUtils; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.utils.Predicates; + import org.spongepowered.api.service.permission.SubjectData; import org.spongepowered.api.util.Tristate; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeMainCommand.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeMainCommand.java index 26b643ba4..2b1b469ad 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeMainCommand.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeMainCommand.java @@ -24,8 +24,14 @@ package me.lucko.luckperms.sponge.commands; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; + import me.lucko.luckperms.common.LuckPermsPlugin; -import me.lucko.luckperms.common.commands.*; +import me.lucko.luckperms.common.commands.Arg; +import me.lucko.luckperms.common.commands.BaseCommand; +import me.lucko.luckperms.common.commands.Command; +import me.lucko.luckperms.common.commands.CommandException; +import me.lucko.luckperms.common.commands.CommandManager; +import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.common.constants.Message; @@ -33,11 +39,16 @@ import me.lucko.luckperms.common.utils.ImmutableCollectors; import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.sponge.LPSpongePlugin; import me.lucko.luckperms.sponge.service.LuckPermsService; + import org.spongepowered.api.service.permission.Subject; import org.spongepowered.api.service.permission.SubjectCollection; import org.spongepowered.api.service.permission.SubjectData; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.StreamSupport; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeUtils.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeUtils.java index 5e259db69..8850cab63 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeUtils.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeUtils.java @@ -22,10 +22,13 @@ package me.lucko.luckperms.sponge.commands; -import com.google.common.collect.Maps; import lombok.experimental.UtilityClass; + +import com.google.common.collect.Maps; + import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.common.commands.utils.ArgumentUtils; + import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.permission.Subject; import org.spongepowered.api.util.Tristate; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/SpongeCalculatorLink.java b/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/SpongeCalculatorLink.java index 00faafde6..2e22cacfa 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/SpongeCalculatorLink.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/SpongeCalculatorLink.java @@ -23,9 +23,11 @@ package me.lucko.luckperms.sponge.contexts; import lombok.AllArgsConstructor; + import me.lucko.luckperms.api.context.ContextCalculator; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.sponge.service.base.Util; + import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.permission.Subject; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/WorldCalculator.java b/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/WorldCalculator.java index f30f3aa6c..6da68b19d 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/WorldCalculator.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/WorldCalculator.java @@ -23,10 +23,12 @@ package me.lucko.luckperms.sponge.contexts; import lombok.RequiredArgsConstructor; + import me.lucko.luckperms.api.context.ContextCalculator; import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.common.commands.utils.Util; import me.lucko.luckperms.sponge.LPSpongePlugin; + import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.permission.Subject; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeGroupManager.java b/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeGroupManager.java index 6bc9c032e..de710e6ab 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeGroupManager.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeGroupManager.java @@ -22,14 +22,15 @@ package me.lucko.luckperms.sponge.managers; -import co.aikar.timings.Timing; +import lombok.NonNull; + import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import lombok.NonNull; + import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.common.core.model.Group; @@ -43,11 +44,14 @@ import me.lucko.luckperms.sponge.service.base.LPSubject; import me.lucko.luckperms.sponge.service.base.LPSubjectCollection; import me.lucko.luckperms.sponge.service.references.SubjectReference; import me.lucko.luckperms.sponge.timings.LPTiming; + import org.spongepowered.api.service.permission.PermissionService; import java.util.Collection; import java.util.Map; +import co.aikar.timings.Timing; + public class SpongeGroupManager implements GroupManager, LPSubjectCollection { private final LPSpongePlugin plugin; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeUserManager.java b/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeUserManager.java index 22a25ffee..b02dd5beb 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeUserManager.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeUserManager.java @@ -22,14 +22,15 @@ package me.lucko.luckperms.sponge.managers; -import co.aikar.timings.Timing; +import lombok.NonNull; + import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import lombok.NonNull; + import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.common.commands.utils.Util; @@ -45,6 +46,7 @@ import me.lucko.luckperms.sponge.service.base.LPSubject; import me.lucko.luckperms.sponge.service.base.LPSubjectCollection; import me.lucko.luckperms.sponge.service.references.SubjectReference; import me.lucko.luckperms.sponge.timings.LPTiming; + import org.spongepowered.api.service.permission.PermissionService; import java.util.Collection; @@ -52,6 +54,8 @@ import java.util.Map; import java.util.Set; import java.util.UUID; +import co.aikar.timings.Timing; + public class SpongeUserManager implements UserManager, LPSubjectCollection { private final LPSpongePlugin plugin; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java index 5f32f794a..f1afaaa1d 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionManager.java @@ -33,6 +33,7 @@ import me.lucko.luckperms.common.constants.Permission; import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.utils.Predicates; + import org.spongepowered.api.Sponge; import org.spongepowered.api.plugin.PluginContainer; import org.spongepowered.api.service.permission.PermissionService; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java index 2f3052af6..670861100 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationPermissionsEx.java @@ -35,6 +35,7 @@ import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.sponge.LPSpongePlugin; import me.lucko.luckperms.sponge.service.LuckPermsService; + import org.spongepowered.api.Sponge; import org.spongepowered.api.plugin.PluginContainer; import org.spongepowered.api.service.permission.PermissionService; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationUtils.java b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationUtils.java index d71da2281..e2cc6ae26 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationUtils.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/migration/MigrationUtils.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.sponge.migration; import lombok.experimental.UtilityClass; + import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.common.core.NodeBuilder; import me.lucko.luckperms.common.core.NodeFactory; @@ -30,6 +31,7 @@ import me.lucko.luckperms.common.core.model.PermissionHolder; import me.lucko.luckperms.common.utils.ExtractedContexts; import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.sponge.service.base.Util; + import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.permission.PermissionService; import org.spongepowered.api.service.permission.Subject; @@ -57,7 +59,8 @@ public class MigrationUtils { for (Map.Entry perm : e.getValue().entrySet()) { try { holder.setPermission(new NodeBuilder(perm.getKey()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(perm.getValue()).build()); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } } } @@ -76,15 +79,18 @@ public class MigrationUtils { if (opt.getKey().equalsIgnoreCase("prefix")) { try { holder.setPermission(NodeFactory.makePrefixNode(100, opt.getValue()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build()); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } } else if (opt.getKey().equalsIgnoreCase("suffix")) { try { holder.setPermission(NodeFactory.makeSuffixNode(100, opt.getValue()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build()); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } } else { try { holder.setPermission(NodeFactory.makeMetaNode(opt.getKey(), opt.getValue()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build()); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } } } } @@ -110,7 +116,8 @@ public class MigrationUtils { try { holder.setPermission(new NodeBuilder("group." + s.getIdentifier().toLowerCase()).setServerRaw(server).setWorld(world).withExtraContext(contexts).setValue(true).build()); - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } } } } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeGroup.java b/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeGroup.java index 57ba54cbd..450fc084e 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeGroup.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeGroup.java @@ -22,9 +22,10 @@ package me.lucko.luckperms.sponge.model; -import co.aikar.timings.Timing; -import com.google.common.collect.ImmutableSet; import lombok.Getter; + +import com.google.common.collect.ImmutableSet; + import me.lucko.luckperms.api.LocalizedNode; import me.lucko.luckperms.api.MetaUtils; import me.lucko.luckperms.api.Node; @@ -40,6 +41,7 @@ import me.lucko.luckperms.sponge.service.base.Util; import me.lucko.luckperms.sponge.service.references.SubjectCollectionReference; import me.lucko.luckperms.sponge.service.references.SubjectReference; import me.lucko.luckperms.sponge.timings.LPTiming; + import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.service.permission.NodeTree; import org.spongepowered.api.service.permission.PermissionService; @@ -49,6 +51,8 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import co.aikar.timings.Timing; + public class SpongeGroup extends Group { @Getter diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeUser.java b/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeUser.java index 5dfbfbbb4..3609d3995 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeUser.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeUser.java @@ -22,9 +22,10 @@ package me.lucko.luckperms.sponge.model; -import co.aikar.timings.Timing; -import com.google.common.collect.ImmutableSet; import lombok.Getter; + +import com.google.common.collect.ImmutableSet; + import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.caching.MetaData; import me.lucko.luckperms.api.context.ContextSet; @@ -36,6 +37,7 @@ import me.lucko.luckperms.sponge.service.base.LPSubject; import me.lucko.luckperms.sponge.service.references.SubjectCollectionReference; import me.lucko.luckperms.sponge.service.references.SubjectReference; import me.lucko.luckperms.sponge.timings.LPTiming; + import org.spongepowered.api.Sponge; import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.entity.living.player.Player; @@ -45,6 +47,8 @@ import java.util.Optional; import java.util.Set; import java.util.UUID; +import co.aikar.timings.Timing; + public class SpongeUser extends User { @Getter diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java index b466cf1ba..232ddbf34 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java @@ -22,7 +22,14 @@ package me.lucko.luckperms.sponge.service; -import co.aikar.timings.Timing; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.ToString; + import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -31,7 +38,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.MapMaker; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import lombok.*; + import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.context.ContextSet; @@ -50,6 +57,7 @@ import me.lucko.luckperms.sponge.service.persisted.SubjectStorage; import me.lucko.luckperms.sponge.service.references.SubjectReference; import me.lucko.luckperms.sponge.service.simple.SimpleCollection; import me.lucko.luckperms.sponge.timings.LPTiming; + import org.spongepowered.api.plugin.PluginContainer; import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.context.ContextCalculator; @@ -60,9 +68,17 @@ import org.spongepowered.api.service.permission.SubjectCollection; import org.spongepowered.api.text.Text; import java.io.File; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import co.aikar.timings.Timing; + /** * The LuckPerms implementation of the Sponge Permission Service */ @@ -197,10 +213,9 @@ public class LuckPermsService implements PermissionService { public static class DescriptionBuilder implements PermissionDescription.Builder { private final LuckPermsService service; private final PluginContainer container; - + private final Map roles = new HashMap<>(); private String id = null; private Text description = null; - private final Map roles = new HashMap<>(); @Override public PermissionDescription.Builder id(@NonNull String s) { diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsSubjectData.java index 07ea0bcd2..5ea670039 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsSubjectData.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsSubjectData.java @@ -22,12 +22,13 @@ package me.lucko.luckperms.sponge.service; -import co.aikar.timings.Timing; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NonNull; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.context.ContextSet; @@ -44,12 +45,20 @@ import me.lucko.luckperms.sponge.service.base.LPSubject; import me.lucko.luckperms.sponge.service.base.LPSubjectData; import me.lucko.luckperms.sponge.service.references.SubjectReference; import me.lucko.luckperms.sponge.timings.LPTiming; + import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.permission.PermissionService; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; +import co.aikar.timings.Timing; + @SuppressWarnings({"OptionalGetWithoutIsPresent", "unused"}) @AllArgsConstructor public class LuckPermsSubjectData implements LPSubjectData { @@ -119,7 +128,8 @@ public class LuckPermsSubjectData implements LPSubjectData { } else { holder.unsetTransientPermission(node); } - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } objectSave(holder); return true; @@ -131,10 +141,11 @@ public class LuckPermsSubjectData implements LPSubjectData { try { if (enduring) { holder.unsetPermission(node); - }else { + } else { holder.unsetTransientPermission(node); } - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } try { if (enduring) { @@ -142,7 +153,8 @@ public class LuckPermsSubjectData implements LPSubjectData { } else { holder.setTransientPermission(node); } - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } objectSave(holder); return true; @@ -189,7 +201,8 @@ public class LuckPermsSubjectData implements LPSubjectData { } else { holder.unsetTransientPermission(n); } - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } }); if (holder instanceof User) { @@ -252,7 +265,8 @@ public class LuckPermsSubjectData implements LPSubjectData { .withExtraContext(contexts) .build()); } - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } objectSave(holder); return true; @@ -277,7 +291,8 @@ public class LuckPermsSubjectData implements LPSubjectData { .withExtraContext(contexts) .build()); } - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } objectSave(holder); return true; @@ -300,7 +315,8 @@ public class LuckPermsSubjectData implements LPSubjectData { } else { holder.unsetTransientPermission(n); } - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } }); if (holder instanceof User) { @@ -343,7 +359,8 @@ public class LuckPermsSubjectData implements LPSubjectData { } else { holder.unsetTransientPermission(n); } - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } }); if (holder instanceof User) { @@ -429,7 +446,8 @@ public class LuckPermsSubjectData implements LPSubjectData { toRemove.forEach(n -> { try { holder.unsetPermission(n); - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } }); try { @@ -438,7 +456,8 @@ public class LuckPermsSubjectData implements LPSubjectData { } else { holder.setTransientPermission(NodeFactory.makeMetaNode(key, value).withExtraContext(context).build()); } - } catch (ObjectAlreadyHasException ignored) {} + } catch (ObjectAlreadyHasException ignored) { + } objectSave(holder); return true; } @@ -454,7 +473,8 @@ public class LuckPermsSubjectData implements LPSubjectData { toRemove.forEach(n -> { try { holder.unsetPermission(n); - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } }); objectSave(holder); @@ -493,7 +513,8 @@ public class LuckPermsSubjectData implements LPSubjectData { } else { holder.unsetTransientPermission(n); } - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } }); objectSave(holder); @@ -515,7 +536,8 @@ public class LuckPermsSubjectData implements LPSubjectData { } else { holder.unsetTransientPermission(n); } - } catch (ObjectLacksException ignored) {} + } catch (ObjectLacksException ignored) { + } }); objectSave(holder); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/base/LPSubject.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/base/LPSubject.java index 33f41d52e..6a97a015f 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/base/LPSubject.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/base/LPSubject.java @@ -23,11 +23,13 @@ package me.lucko.luckperms.sponge.service.base; import lombok.NonNull; + import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.common.utils.ImmutableCollectors; import me.lucko.luckperms.sponge.service.LuckPermsService; import me.lucko.luckperms.sponge.service.references.SubjectCollectionReference; import me.lucko.luckperms.sponge.service.references.SubjectReference; + import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.permission.Subject; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/base/LPSubjectCollection.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/base/LPSubjectCollection.java index 9bc9340de..82afdd89f 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/base/LPSubjectCollection.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/base/LPSubjectCollection.java @@ -23,11 +23,13 @@ package me.lucko.luckperms.sponge.service.base; import lombok.NonNull; + import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.common.utils.ImmutableCollectors; import me.lucko.luckperms.sponge.service.LuckPermsService; import me.lucko.luckperms.sponge.service.references.SubjectCollectionReference; import me.lucko.luckperms.sponge.service.references.SubjectReference; + import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.permission.Subject; import org.spongepowered.api.service.permission.SubjectCollection; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/base/LPSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/base/LPSubjectData.java index fde2c36fd..c13bce36f 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/base/LPSubjectData.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/base/LPSubjectData.java @@ -24,19 +24,22 @@ package me.lucko.luckperms.sponge.service.base; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; + import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.common.utils.ImmutableCollectors; import me.lucko.luckperms.sponge.service.references.SubjectReference; + import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.permission.Subject; import org.spongepowered.api.service.permission.SubjectData; import org.spongepowered.api.util.Tristate; -import javax.annotation.Nullable; import java.util.List; import java.util.Map; import java.util.Set; +import javax.annotation.Nullable; + import static me.lucko.luckperms.sponge.service.base.Util.convertContexts; import static me.lucko.luckperms.sponge.service.base.Util.convertTristate; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/base/Util.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/base/Util.java index 869069d97..823979360 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/base/Util.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/base/Util.java @@ -22,10 +22,13 @@ package me.lucko.luckperms.sponge.service.base; -import com.google.common.collect.Maps; import lombok.experimental.UtilityClass; + +import com.google.common.collect.Maps; + import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.common.utils.ImmutableCollectors; + import org.spongepowered.api.service.context.Context; import org.spongepowered.api.util.Tristate; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/CalculatedSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/CalculatedSubjectData.java index a8d16a08f..0de4aa5d8 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/CalculatedSubjectData.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/CalculatedSubjectData.java @@ -22,6 +22,9 @@ package me.lucko.luckperms.sponge.service.calculated; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -29,8 +32,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedMap; -import lombok.Getter; -import lombok.RequiredArgsConstructor; + import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.common.calculators.PermissionCalculator; @@ -42,19 +44,60 @@ import me.lucko.luckperms.sponge.service.base.LPSubject; import me.lucko.luckperms.sponge.service.base.LPSubjectData; import me.lucko.luckperms.sponge.service.references.SubjectReference; -import java.util.*; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.SortedMap; import java.util.concurrent.ConcurrentHashMap; @RequiredArgsConstructor public class CalculatedSubjectData implements LPSubjectData { private static final ContextComparator CONTEXT_COMPARATOR = new ContextComparator(); + private static Map flattenMap(ContextSet contexts, Map> source) { + Map map = new HashMap<>(); + + SortedMap> ret = getRelevantEntries(contexts, source); + for (Map m : ret.values()) { + for (Map.Entry e : m.entrySet()) { + if (!map.containsKey(e.getKey())) { + map.put(e.getKey(), e.getValue()); + } + } + } + + return ImmutableMap.copyOf(map); + } + + private static SortedMap> getRelevantEntries(ContextSet set, Map> map) { + ImmutableSortedMap.Builder> perms = ImmutableSortedMap.orderedBy(CONTEXT_COMPARATOR); + + loop: + for (Map.Entry> e : map.entrySet()) { + + for (Map.Entry c : e.getKey().toSet()) { + if (!set.has(c.getKey(), c.getValue())) { + continue loop; + } + } + + perms.put(e.getKey().makeImmutable(), ImmutableMap.copyOf(e.getValue())); + } + + return perms.build(); + } + + private static boolean stringEquals(String a, String b) { + return a == null && b == null || a != null && b != null && a.equalsIgnoreCase(b); + } + @Getter private final LPSubject parentSubject; - private final LuckPermsService service; private final String calculatorDisplayName; - + private final Map> permissions = new ConcurrentHashMap<>(); private final LoadingCache permissionCache = CacheBuilder.newBuilder() .build(new CacheLoader() { @Override @@ -69,7 +112,8 @@ public class CalculatedSubjectData implements LPSubjectData { return holder; } }); - + private final Map> parents = new ConcurrentHashMap<>(); + private final Map> options = new ConcurrentHashMap<>(); private final LoadingCache> optionCache = CacheBuilder.newBuilder() .build(new CacheLoader>() { @Override @@ -78,10 +122,6 @@ public class CalculatedSubjectData implements LPSubjectData { } }); - private final Map> permissions = new ConcurrentHashMap<>(); - private final Map> parents = new ConcurrentHashMap<>(); - private final Map> options = new ConcurrentHashMap<>(); - public Tristate getPermissionValue(ContextSet contexts, String permission) { return permissionCache.getUnchecked(contexts).getCalculator().getPermissionValue(permission); } @@ -274,43 +314,6 @@ public class CalculatedSubjectData implements LPSubjectData { return false; } - private static Map flattenMap(ContextSet contexts, Map> source) { - Map map = new HashMap<>(); - - SortedMap> ret = getRelevantEntries(contexts, source); - for (Map m : ret.values()) { - for (Map.Entry e : m.entrySet()) { - if (!map.containsKey(e.getKey())) { - map.put(e.getKey(), e.getValue()); - } - } - } - - return ImmutableMap.copyOf(map); - } - - private static SortedMap> getRelevantEntries(ContextSet set, Map> map) { - ImmutableSortedMap.Builder> perms = ImmutableSortedMap.orderedBy(CONTEXT_COMPARATOR); - - loop: - for (Map.Entry> e : map.entrySet()) { - - for (Map.Entry c : e.getKey().toSet()) { - if (!set.has(c.getKey(), c.getValue())) { - continue loop; - } - } - - perms.put(e.getKey().makeImmutable(), ImmutableMap.copyOf(e.getValue())); - } - - return perms.build(); - } - - private static boolean stringEquals(String a, String b) { - return a == null && b == null || a != null && b != null && a.equalsIgnoreCase(b); - } - private static class ContextComparator implements Comparator { @Override diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/OptionLookup.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/OptionLookup.java index d39646fc1..6817e2fee 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/OptionLookup.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/OptionLookup.java @@ -26,6 +26,7 @@ import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; + import me.lucko.luckperms.api.context.ContextSet; @Getter diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/PermissionLookup.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/PermissionLookup.java index 43b4f2b1d..285899cfe 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/PermissionLookup.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/PermissionLookup.java @@ -26,6 +26,7 @@ import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; + import me.lucko.luckperms.api.context.ContextSet; @Getter diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedCollection.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedCollection.java index 390ed8840..2bc415b1c 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedCollection.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedCollection.java @@ -22,14 +22,16 @@ package me.lucko.luckperms.sponge.service.persisted; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import com.google.common.collect.ImmutableMap; import lombok.AccessLevel; import lombok.Getter; import lombok.NonNull; import lombok.RequiredArgsConstructor; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import com.google.common.collect.ImmutableMap; + import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.common.utils.ImmutableCollectors; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java index 9ec1165db..fdb7c5d65 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java @@ -22,10 +22,11 @@ package me.lucko.luckperms.sponge.service.persisted; -import co.aikar.timings.Timing; -import com.google.common.collect.ImmutableSet; import lombok.Getter; import lombok.NonNull; + +import com.google.common.collect.ImmutableSet; + import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.common.utils.BufferedRequest; @@ -35,6 +36,7 @@ import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData; import me.lucko.luckperms.sponge.service.references.SubjectCollectionReference; import me.lucko.luckperms.sponge.service.references.SubjectReference; import me.lucko.luckperms.sponge.timings.LPTiming; + import org.spongepowered.api.command.CommandSource; import java.io.IOException; @@ -42,6 +44,8 @@ import java.util.HashSet; import java.util.Optional; import java.util.Set; +import co.aikar.timings.Timing; + /** * A simple persistable Subject implementation */ diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubjectData.java index 34392b2a2..3c17e3a8c 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubjectData.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubjectData.java @@ -24,6 +24,7 @@ package me.lucko.luckperms.sponge.service.persisted; import lombok.Getter; import lombok.Setter; + import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.sponge.service.LuckPermsService; import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/SubjectDataHolder.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/SubjectDataHolder.java index bd88b706f..087f1321a 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/SubjectDataHolder.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/SubjectDataHolder.java @@ -23,6 +23,7 @@ package me.lucko.luckperms.sponge.service.persisted; import lombok.ToString; + import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData; import me.lucko.luckperms.sponge.service.references.SubjectReference; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/references/SubjectCollectionReference.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/references/SubjectCollectionReference.java index fd5d47ca0..1003d58bd 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/references/SubjectCollectionReference.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/references/SubjectCollectionReference.java @@ -26,6 +26,7 @@ import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; + import me.lucko.luckperms.sponge.service.LuckPermsService; import me.lucko.luckperms.sponge.service.base.LPSubjectCollection; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/references/SubjectReference.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/references/SubjectReference.java index 11b95be87..2c586844b 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/references/SubjectReference.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/references/SubjectReference.java @@ -22,14 +22,17 @@ package me.lucko.luckperms.sponge.service.references; -import com.google.common.base.Splitter; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; + +import com.google.common.base.Splitter; + import me.lucko.luckperms.sponge.service.LuckPermsService; import me.lucko.luckperms.sponge.service.base.LPSubject; import me.lucko.luckperms.sponge.service.base.LPSubjectCollection; + import org.spongepowered.api.service.permission.Subject; import java.util.List; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/simple/SimpleCollection.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/simple/SimpleCollection.java index 44fb811c1..c484ce2b9 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/simple/SimpleCollection.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/simple/SimpleCollection.java @@ -22,14 +22,16 @@ package me.lucko.luckperms.sponge.service.simple; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import com.google.common.collect.ImmutableMap; import lombok.AccessLevel; import lombok.Getter; import lombok.NonNull; import lombok.RequiredArgsConstructor; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import com.google.common.collect.ImmutableMap; + import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.common.utils.ImmutableCollectors; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/simple/SimpleSubject.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/simple/SimpleSubject.java index 76b0fdd12..fe2e6b1f0 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/simple/SimpleSubject.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/simple/SimpleSubject.java @@ -22,13 +22,14 @@ package me.lucko.luckperms.sponge.service.simple; -import co.aikar.timings.Timing; +import lombok.Getter; +import lombok.NonNull; + import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableSet; -import lombok.Getter; -import lombok.NonNull; + import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.sponge.service.LuckPermsService; @@ -44,6 +45,8 @@ import java.util.HashSet; import java.util.Optional; import java.util.Set; +import co.aikar.timings.Timing; + /** * Super simple Subject implementation. */ @@ -55,15 +58,6 @@ public class SimpleSubject implements LPSubject { private final SubjectCollectionReference parentCollection; private final CalculatedSubjectData subjectData; private final CalculatedSubjectData transientSubjectData; - - private final LoadingCache permissionLookupCache = CacheBuilder.newBuilder() - .build(new CacheLoader() { - @Override - public Tristate load(PermissionLookup lookup) { - return lookupPermissionValue(lookup.getContexts(), lookup.getNode()); - } - }); - private final LoadingCache> parentLookupCache = CacheBuilder.newBuilder() .build(new CacheLoader>() { @Override @@ -71,7 +65,13 @@ public class SimpleSubject implements LPSubject { return lookupParents(contexts); } }); - + private final LoadingCache permissionLookupCache = CacheBuilder.newBuilder() + .build(new CacheLoader() { + @Override + public Tristate load(PermissionLookup lookup) { + return lookupPermissionValue(lookup.getContexts(), lookup.getNode()); + } + }); private final LoadingCache> optionLookupCache = CacheBuilder.newBuilder() .build(new CacheLoader>() { @Override @@ -124,7 +124,7 @@ public class SimpleSubject implements LPSubject { Set s = new HashSet<>(); s.addAll(subjectData.getParents(contexts)); - if (!getParentCollection().resolve(service).getIdentifier().equalsIgnoreCase("defaults")){ + if (!getParentCollection().resolve(service).getIdentifier().equalsIgnoreCase("defaults")) { s.addAll(getParentCollection().resolve(service).getDefaultSubject().resolve(service).getParents(contexts)); s.addAll(service.getDefaults().getParents(contexts)); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/timings/LPTimings.java b/sponge/src/main/java/me/lucko/luckperms/sponge/timings/LPTimings.java index afb37768a..6c8e28a6e 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/timings/LPTimings.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/timings/LPTimings.java @@ -22,14 +22,17 @@ package me.lucko.luckperms.sponge.timings; -import co.aikar.timings.Timing; -import co.aikar.timings.Timings; -import com.google.common.collect.ImmutableMap; import lombok.NonNull; + +import com.google.common.collect.ImmutableMap; + import me.lucko.luckperms.sponge.LPSpongePlugin; import java.util.Map; +import co.aikar.timings.Timing; +import co.aikar.timings.Timings; + public class LPTimings { private final Map timings;