diff --git a/api/src/main/java/net/luckperms/api/LuckPerms.java b/api/src/main/java/net/luckperms/api/LuckPerms.java index eb34dfa00..b3c94c8b1 100644 --- a/api/src/main/java/net/luckperms/api/LuckPerms.java +++ b/api/src/main/java/net/luckperms/api/LuckPerms.java @@ -141,7 +141,7 @@ public interface LuckPerms { * @throws IllegalArgumentException if the player class is not correct * @since 5.1 */ - @NonNull PlayerAdapter getPlayerAdapter(Class playerClass); + @NonNull PlayerAdapter getPlayerAdapter(@NonNull Class playerClass); /** * Gets the {@link Platform}, which represents the server platform the diff --git a/api/src/main/java/net/luckperms/api/cacheddata/CachedDataManager.java b/api/src/main/java/net/luckperms/api/cacheddata/CachedDataManager.java index 8c735dc5b..fe52d97a2 100644 --- a/api/src/main/java/net/luckperms/api/cacheddata/CachedDataManager.java +++ b/api/src/main/java/net/luckperms/api/cacheddata/CachedDataManager.java @@ -107,6 +107,7 @@ public interface CachedDataManager { * * @return a meta data instance * @since 5.1 + * @see PermissionHolder#getQueryOptions() */ @NonNull CachedMetaData getMetaData(); diff --git a/api/src/main/java/net/luckperms/api/model/PermissionHolder.java b/api/src/main/java/net/luckperms/api/model/PermissionHolder.java index 36cb8bd45..076dfe766 100644 --- a/api/src/main/java/net/luckperms/api/model/PermissionHolder.java +++ b/api/src/main/java/net/luckperms/api/model/PermissionHolder.java @@ -26,6 +26,7 @@ package net.luckperms.api.model; import net.luckperms.api.cacheddata.CachedDataManager; +import net.luckperms.api.context.ContextManager; import net.luckperms.api.model.data.DataType; import net.luckperms.api.model.data.NodeMap; import net.luckperms.api.model.group.Group; @@ -112,6 +113,24 @@ public interface PermissionHolder { */ @NonNull String getFriendlyName(); + /** + * Gets the most appropriate query options available at the time for the + * {@link PermissionHolder}. + * + *

For {@link User}s, the most appropriate query options will be their + * {@link ContextManager#getQueryOptions(User) current active query options} if the + * corresponding player is online, and otherwise, will fallback to + * {@link ContextManager#getStaticQueryOptions() the current static query options} + * if they are offline.

+ * + *

For {@link Group}s, the most appropriate query options will always be + * {@link ContextManager#getStaticQueryOptions()} the current static query options.

+ * + * @return query options + * @since 5.1 + */ + @NonNull QueryOptions getQueryOptions(); + /** * Gets the holders {@link CachedDataManager} cache. * diff --git a/common/src/main/java/me/lucko/luckperms/common/api/LuckPermsApiProvider.java b/common/src/main/java/me/lucko/luckperms/common/api/LuckPermsApiProvider.java index 6cc0e34d8..8c48d2e9b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/LuckPermsApiProvider.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/LuckPermsApiProvider.java @@ -125,7 +125,7 @@ public class LuckPermsApiProvider implements LuckPerms { @SuppressWarnings("unchecked") @Override - public @NonNull PlayerAdapter getPlayerAdapter(Class playerClass) { + public @NonNull PlayerAdapter getPlayerAdapter(@NonNull Class playerClass) { Objects.requireNonNull(playerClass, "playerClass"); Class expectedClass = this.plugin.getContextManager().getPlayerClass(); if (!expectedClass.equals(playerClass)) { diff --git a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPermissionHolder.java index 781381486..7ea39ace0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPermissionHolder.java @@ -85,6 +85,11 @@ public class ApiPermissionHolder implements net.luckperms.api.model.PermissionHo return this.handle.getPlainDisplayName(); } + @Override + public @NonNull QueryOptions getQueryOptions() { + return this.handle.getQueryOptions(); + } + @Override public @NonNull CachedDataManager getCachedData() { return this.handle.getCachedData(); diff --git a/common/src/main/java/me/lucko/luckperms/common/cacheddata/GroupCachedDataManager.java b/common/src/main/java/me/lucko/luckperms/common/cacheddata/GroupCachedDataManager.java index 0b8d73fdf..dfe527993 100644 --- a/common/src/main/java/me/lucko/luckperms/common/cacheddata/GroupCachedDataManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/cacheddata/GroupCachedDataManager.java @@ -45,8 +45,4 @@ public class GroupCachedDataManager extends HolderCachedDataManager imple return new CacheMetadata(HolderType.GROUP, this.holder.getPlainDisplayName(), queryOptions); } - @Override - protected QueryOptions getQueryOptions() { - return getPlugin().getContextManager().getStaticQueryOptions(); - } } diff --git a/common/src/main/java/me/lucko/luckperms/common/cacheddata/HolderCachedDataManager.java b/common/src/main/java/me/lucko/luckperms/common/cacheddata/HolderCachedDataManager.java index 6a1959642..d7fa0e9a6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/cacheddata/HolderCachedDataManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/cacheddata/HolderCachedDataManager.java @@ -51,6 +51,11 @@ public abstract class HolderCachedDataManager extend this.holder = holder; } + @Override + protected QueryOptions getQueryOptions() { + return this.holder.getQueryOptions(); + } + @Override protected CalculatorFactory getCalculatorFactory() { return getPlugin().getCalculatorFactory(); diff --git a/common/src/main/java/me/lucko/luckperms/common/cacheddata/UserCachedDataManager.java b/common/src/main/java/me/lucko/luckperms/common/cacheddata/UserCachedDataManager.java index 432049ece..672dc5d1d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/cacheddata/UserCachedDataManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/cacheddata/UserCachedDataManager.java @@ -45,13 +45,4 @@ public class UserCachedDataManager extends HolderCachedDataManager impleme return new CacheMetadata(HolderType.USER, this.holder.getPlainDisplayName(), queryOptions); } - @Override - protected QueryOptions getQueryOptions() { - QueryOptions queryOptions = getPlugin().getQueryOptionsForUser(this.holder).orElse(null); - if (queryOptions != null) { - return queryOptions; - } - - return getPlugin().getContextManager().getStaticQueryOptions(); - } } diff --git a/common/src/main/java/me/lucko/luckperms/common/model/Group.java b/common/src/main/java/me/lucko/luckperms/common/model/Group.java index 8d4cf2104..967894bbd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/Group.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/Group.java @@ -94,6 +94,11 @@ public class Group extends PermissionHolder { return this.apiProxy; } + @Override + public QueryOptions getQueryOptions() { + return getPlugin().getContextManager().getStaticQueryOptions(); + } + @Override public GroupCachedDataManager getCachedData() { return this.cachedData; @@ -101,8 +106,7 @@ public class Group extends PermissionHolder { @Override public String getFormattedDisplayName() { - Optional dn = getDisplayName(); - return dn.map(s -> this.name + " &r(" + s + "&r)").orElse(this.name); + return getDisplayName().map(s -> this.name + " &r(" + s + "&r)").orElse(this.name); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java index 545e29975..703fca4be 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java @@ -214,6 +214,13 @@ public abstract class PermissionHolder { */ public abstract String getPlainDisplayName(); + /** + * Gets the most appropriate query options available at the time for the holder. + * + * @return query options + */ + public abstract QueryOptions getQueryOptions(); + /** * Gets the holders cached data * diff --git a/common/src/main/java/me/lucko/luckperms/common/model/User.java b/common/src/main/java/me/lucko/luckperms/common/model/User.java index 26781c9e0..772884379 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/User.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/User.java @@ -30,6 +30,8 @@ import me.lucko.luckperms.common.cacheddata.UserCachedDataManager; import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; +import net.luckperms.api.query.QueryOptions; + import org.checkerframework.checker.nullness.qual.Nullable; import java.util.Optional; @@ -89,6 +91,16 @@ public class User extends PermissionHolder { return getFormattedDisplayName(); } + @Override + public QueryOptions getQueryOptions() { + QueryOptions queryOptions = getPlugin().getQueryOptionsForUser(this).orElse(null); + if (queryOptions != null) { + return queryOptions; + } + + return getPlugin().getContextManager().getStaticQueryOptions(); + } + public ApiUser getApiProxy() { return this.apiProxy; }