mirror of
https://github.com/lucko/LuckPerms.git
synced 2025-09-09 05:40:47 +02:00
Improve context manager caching (#4050)
This commit is contained in:
@@ -25,19 +25,19 @@
|
||||
|
||||
package me.lucko.luckperms.fabric.context;
|
||||
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.context.manager.ContextManager;
|
||||
import me.lucko.luckperms.common.context.manager.QueryOptionsCache;
|
||||
import me.lucko.luckperms.common.context.manager.DetachedContextManager;
|
||||
import me.lucko.luckperms.common.context.manager.QueryOptionsSupplier;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.fabric.model.MixinUser;
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
import net.luckperms.api.query.OptionKey;
|
||||
import net.luckperms.api.query.QueryOptions;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FabricContextManager extends ContextManager<ServerPlayerEntity, ServerPlayerEntity> {
|
||||
public class FabricContextManager extends DetachedContextManager<ServerPlayerEntity, ServerPlayerEntity> {
|
||||
public static final OptionKey<Boolean> INTEGRATED_SERVER_OWNER = OptionKey.of("integrated_server_owner", Boolean.class);
|
||||
|
||||
public FabricContextManager(LuckPermsPlugin plugin) {
|
||||
@@ -49,32 +49,17 @@ public class FabricContextManager extends ContextManager<ServerPlayerEntity, Ser
|
||||
return player.getUuid();
|
||||
}
|
||||
|
||||
public QueryOptionsCache<ServerPlayerEntity> newQueryOptionsCache(ServerPlayerEntity player) {
|
||||
return new QueryOptionsCache<>(player, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryOptionsCache<ServerPlayerEntity> getCacheFor(ServerPlayerEntity subject) {
|
||||
if (subject == null) {
|
||||
throw new NullPointerException("subject");
|
||||
}
|
||||
|
||||
public @Nullable QueryOptionsSupplier getQueryOptionsSupplier(ServerPlayerEntity subject) {
|
||||
Objects.requireNonNull(subject, "subject");
|
||||
return ((MixinUser) subject).luckperms$getQueryOptionsCache(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateCache(ServerPlayerEntity subject) {
|
||||
getCacheFor(subject).invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryOptions formQueryOptions(ServerPlayerEntity subject, ImmutableContextSet contextSet) {
|
||||
QueryOptions.Builder queryOptions = this.plugin.getConfiguration().get(ConfigKeys.GLOBAL_QUERY_OPTIONS).toBuilder();
|
||||
public void customizeQueryOptions(ServerPlayerEntity subject, QueryOptions.Builder builder) {
|
||||
if (subject.getServer().isHost(subject.getGameProfile())) {
|
||||
queryOptions.option(INTEGRATED_SERVER_OWNER, true);
|
||||
builder.option(INTEGRATED_SERVER_OWNER, true);
|
||||
}
|
||||
|
||||
return queryOptions.context(contextSet).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ package me.lucko.luckperms.fabric.mixin;
|
||||
|
||||
import me.lucko.luckperms.common.cacheddata.type.MetaCache;
|
||||
import me.lucko.luckperms.common.cacheddata.type.PermissionCache;
|
||||
import me.lucko.luckperms.common.context.manager.QueryOptionsCache;
|
||||
import me.lucko.luckperms.common.context.manager.QueryOptionsSupplier;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.verbose.event.CheckOrigin;
|
||||
import me.lucko.luckperms.fabric.context.FabricContextManager;
|
||||
@@ -61,7 +61,7 @@ public abstract class ServerPlayerEntityMixin implements MixinUser {
|
||||
* having to maintain a map of Player->Cache.
|
||||
*/
|
||||
@Unique
|
||||
private QueryOptionsCache<ServerPlayerEntity> luckperms$queryOptions;
|
||||
private QueryOptionsSupplier luckperms$queryOptions;
|
||||
|
||||
// Used by PlayerChangeWorldCallback hook below.
|
||||
@Shadow public abstract ServerWorld getServerWorld();
|
||||
@@ -72,9 +72,9 @@ public abstract class ServerPlayerEntityMixin implements MixinUser {
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryOptionsCache<ServerPlayerEntity> luckperms$getQueryOptionsCache(FabricContextManager contextManager) {
|
||||
public QueryOptionsSupplier luckperms$getQueryOptionsCache(FabricContextManager contextManager) {
|
||||
if (this.luckperms$queryOptions == null) {
|
||||
this.luckperms$queryOptions = contextManager.newQueryOptionsCache((ServerPlayerEntity) (Object) this);
|
||||
this.luckperms$queryOptions = contextManager.createQueryOptionsSupplier((ServerPlayerEntity) (Object) this);
|
||||
}
|
||||
return this.luckperms$queryOptions;
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@
|
||||
|
||||
package me.lucko.luckperms.fabric.model;
|
||||
|
||||
import me.lucko.luckperms.common.context.manager.QueryOptionsCache;
|
||||
import me.lucko.luckperms.common.context.manager.QueryOptionsSupplier;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.fabric.context.FabricContextManager;
|
||||
import net.luckperms.api.query.QueryOptions;
|
||||
@@ -41,12 +41,12 @@ public interface MixinUser {
|
||||
User luckperms$getUser();
|
||||
|
||||
/**
|
||||
* Gets (or creates using the manager) the objects {@link QueryOptionsCache}.
|
||||
* Gets (or creates using the manager) the objects {@link QueryOptionsSupplier}.
|
||||
*
|
||||
* @param contextManager the contextManager
|
||||
* @return the cache
|
||||
*/
|
||||
QueryOptionsCache<ServerPlayerEntity> luckperms$getQueryOptionsCache(FabricContextManager contextManager);
|
||||
QueryOptionsSupplier luckperms$getQueryOptionsCache(FabricContextManager contextManager);
|
||||
|
||||
/**
|
||||
* Initialises permissions for this player using the given {@link User}.
|
||||
|
Reference in New Issue
Block a user