Add PermissionHolder#getQueryOptions API method

This commit is contained in:
Luck 2020-05-10 12:22:40 +01:00
parent 52731fe68e
commit a19cb71394
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
11 changed files with 57 additions and 17 deletions

View File

@ -141,7 +141,7 @@ public interface LuckPerms {
* @throws IllegalArgumentException if the player class is not correct
* @since 5.1
*/
<T> @NonNull PlayerAdapter<T> getPlayerAdapter(Class<T> playerClass);
<T> @NonNull PlayerAdapter<T> getPlayerAdapter(@NonNull Class<T> playerClass);
/**
* Gets the {@link Platform}, which represents the server platform the

View File

@ -107,6 +107,7 @@ public interface CachedDataManager {
*
* @return a meta data instance
* @since 5.1
* @see PermissionHolder#getQueryOptions()
*/
@NonNull CachedMetaData getMetaData();

View File

@ -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}.
*
* <p>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.</p>
*
* <p>For {@link Group}s, the most appropriate query options will always be
* {@link ContextManager#getStaticQueryOptions()} the current static query options.</p>
*
* @return query options
* @since 5.1
*/
@NonNull QueryOptions getQueryOptions();
/**
* Gets the holders {@link CachedDataManager} cache.
*

View File

@ -125,7 +125,7 @@ public class LuckPermsApiProvider implements LuckPerms {
@SuppressWarnings("unchecked")
@Override
public @NonNull <T> PlayerAdapter<T> getPlayerAdapter(Class<T> playerClass) {
public @NonNull <T> PlayerAdapter<T> getPlayerAdapter(@NonNull Class<T> playerClass) {
Objects.requireNonNull(playerClass, "playerClass");
Class<?> expectedClass = this.plugin.getContextManager().getPlayerClass();
if (!expectedClass.equals(playerClass)) {

View File

@ -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();

View File

@ -45,8 +45,4 @@ public class GroupCachedDataManager extends HolderCachedDataManager<Group> imple
return new CacheMetadata(HolderType.GROUP, this.holder.getPlainDisplayName(), queryOptions);
}
@Override
protected QueryOptions getQueryOptions() {
return getPlugin().getContextManager().getStaticQueryOptions();
}
}

View File

@ -51,6 +51,11 @@ public abstract class HolderCachedDataManager<T extends PermissionHolder> extend
this.holder = holder;
}
@Override
protected QueryOptions getQueryOptions() {
return this.holder.getQueryOptions();
}
@Override
protected CalculatorFactory getCalculatorFactory() {
return getPlugin().getCalculatorFactory();

View File

@ -45,13 +45,4 @@ public class UserCachedDataManager extends HolderCachedDataManager<User> 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();
}
}

View File

@ -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<String> 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

View File

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

View File

@ -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;
}