mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 03:25:19 +01:00
Invalidate QueryOptions cache when op status changes
This commit is contained in:
parent
dce792083b
commit
37367fe91f
@ -32,7 +32,6 @@ import me.lucko.luckperms.common.cache.LoadingMap;
|
|||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.context.ContextManager;
|
import me.lucko.luckperms.common.context.ContextManager;
|
||||||
import me.lucko.luckperms.common.context.QueryOptionsCache;
|
import me.lucko.luckperms.common.context.QueryOptionsCache;
|
||||||
import me.lucko.luckperms.common.context.QueryOptionsSupplier;
|
|
||||||
import me.lucko.luckperms.common.util.CaffeineFactory;
|
import me.lucko.luckperms.common.util.CaffeineFactory;
|
||||||
|
|
||||||
import net.luckperms.api.context.ImmutableContextSet;
|
import net.luckperms.api.context.ImmutableContextSet;
|
||||||
@ -70,7 +69,7 @@ public class BukkitContextManager extends ContextManager<Player> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryOptionsSupplier getCacheFor(Player subject) {
|
public QueryOptionsCache<Player> getCacheFor(Player subject) {
|
||||||
if (subject == null) {
|
if (subject == null) {
|
||||||
throw new NullPointerException("subject");
|
throw new NullPointerException("subject");
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,15 @@ import com.google.common.collect.ImmutableList;
|
|||||||
|
|
||||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||||
import me.lucko.luckperms.bukkit.calculator.DefaultsProcessor;
|
import me.lucko.luckperms.bukkit.calculator.DefaultsProcessor;
|
||||||
|
import me.lucko.luckperms.bukkit.context.BukkitContextManager;
|
||||||
import me.lucko.luckperms.common.calculator.result.TristateResult;
|
import me.lucko.luckperms.common.calculator.result.TristateResult;
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.context.QueryOptionsSupplier;
|
import me.lucko.luckperms.common.context.QueryOptionsCache;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
import me.lucko.luckperms.common.util.ImmutableCollectors;
|
import me.lucko.luckperms.common.util.ImmutableCollectors;
|
||||||
import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent;
|
import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent;
|
||||||
|
|
||||||
|
import net.luckperms.api.query.QueryOptions;
|
||||||
import net.luckperms.api.util.Tristate;
|
import net.luckperms.api.util.Tristate;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -93,7 +95,7 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
private final LPBukkitPlugin plugin;
|
private final LPBukkitPlugin plugin;
|
||||||
|
|
||||||
// caches context lookups for the player
|
// caches context lookups for the player
|
||||||
private final QueryOptionsSupplier queryOptionsSupplier;
|
private final QueryOptionsCache<Player> queryOptionsSupplier;
|
||||||
|
|
||||||
// the players previous permissible. (the one they had before this one was injected)
|
// the players previous permissible. (the one they had before this one was injected)
|
||||||
private PermissibleBase oldPermissible = null;
|
private PermissibleBase oldPermissible = null;
|
||||||
@ -163,8 +165,14 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
throw new NullPointerException("permission");
|
throw new NullPointerException("permission");
|
||||||
}
|
}
|
||||||
|
|
||||||
Tristate ts = this.user.getCachedData().getPermissionData(this.queryOptionsSupplier.getQueryOptions()).checkPermission(permission, PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK).result();
|
QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
|
||||||
return ts != Tristate.UNDEFINED ? ts.asBoolean() : Permission.DEFAULT_PERMISSION.getValue(isOp());
|
Tristate ts = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission, PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK).result();
|
||||||
|
if (ts != Tristate.UNDEFINED) {
|
||||||
|
return ts.asBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isOp = queryOptions.option(BukkitContextManager.OP_OPTION).orElse(false);
|
||||||
|
return Permission.DEFAULT_PERMISSION.getValue(isOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -173,15 +181,17 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
throw new NullPointerException("permission");
|
throw new NullPointerException("permission");
|
||||||
}
|
}
|
||||||
|
|
||||||
Tristate ts = this.user.getCachedData().getPermissionData(this.queryOptionsSupplier.getQueryOptions()).checkPermission(permission.getName(), PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK).result();
|
QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
|
||||||
|
Tristate ts = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission.getName(), PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK).result();
|
||||||
if (ts != Tristate.UNDEFINED) {
|
if (ts != Tristate.UNDEFINED) {
|
||||||
return ts.asBoolean();
|
return ts.asBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isOp = queryOptions.option(BukkitContextManager.OP_OPTION).orElse(false);
|
||||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) {
|
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) {
|
||||||
return permission.getDefault().getValue(isOp());
|
return permission.getDefault().getValue(isOp);
|
||||||
} else {
|
} else {
|
||||||
return Permission.DEFAULT_PERMISSION.getValue(isOp());
|
return Permission.DEFAULT_PERMISSION.getValue(isOp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,7 +304,13 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void recalculatePermissions() {
|
public void recalculatePermissions() {
|
||||||
// do nothing
|
// this method is called (among other times) when op status is updated.
|
||||||
|
// because we encapsulate op status within QueryOptions, we need to invalidate
|
||||||
|
// the contextmanager cache when op status changes.
|
||||||
|
// (#invalidate is a fast call)
|
||||||
|
this.queryOptionsSupplier.invalidate();
|
||||||
|
|
||||||
|
// but we don't need to do anything else in this method, unlike the CB impl.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -31,7 +31,6 @@ import me.lucko.luckperms.common.cache.LoadingMap;
|
|||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.context.ContextManager;
|
import me.lucko.luckperms.common.context.ContextManager;
|
||||||
import me.lucko.luckperms.common.context.QueryOptionsCache;
|
import me.lucko.luckperms.common.context.QueryOptionsCache;
|
||||||
import me.lucko.luckperms.common.context.QueryOptionsSupplier;
|
|
||||||
import me.lucko.luckperms.common.util.CaffeineFactory;
|
import me.lucko.luckperms.common.util.CaffeineFactory;
|
||||||
import me.lucko.luckperms.nukkit.LPNukkitPlugin;
|
import me.lucko.luckperms.nukkit.LPNukkitPlugin;
|
||||||
|
|
||||||
@ -70,7 +69,7 @@ public class NukkitContextManager extends ContextManager<Player> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryOptionsSupplier getCacheFor(Player subject) {
|
public QueryOptionsCache<Player> getCacheFor(Player subject) {
|
||||||
if (subject == null) {
|
if (subject == null) {
|
||||||
throw new NullPointerException("subject");
|
throw new NullPointerException("subject");
|
||||||
}
|
}
|
||||||
|
@ -29,14 +29,16 @@ import com.google.common.collect.ImmutableList;
|
|||||||
|
|
||||||
import me.lucko.luckperms.common.calculator.result.TristateResult;
|
import me.lucko.luckperms.common.calculator.result.TristateResult;
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.context.QueryOptionsSupplier;
|
import me.lucko.luckperms.common.context.QueryOptionsCache;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
import me.lucko.luckperms.common.util.ImmutableCollectors;
|
import me.lucko.luckperms.common.util.ImmutableCollectors;
|
||||||
import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent;
|
import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent;
|
||||||
import me.lucko.luckperms.nukkit.LPNukkitPlugin;
|
import me.lucko.luckperms.nukkit.LPNukkitPlugin;
|
||||||
import me.lucko.luckperms.nukkit.calculator.DefaultsProcessor;
|
import me.lucko.luckperms.nukkit.calculator.DefaultsProcessor;
|
||||||
|
import me.lucko.luckperms.nukkit.context.NukkitContextManager;
|
||||||
import me.lucko.luckperms.nukkit.inject.PermissionDefault;
|
import me.lucko.luckperms.nukkit.inject.PermissionDefault;
|
||||||
|
|
||||||
|
import net.luckperms.api.query.QueryOptions;
|
||||||
import net.luckperms.api.util.Tristate;
|
import net.luckperms.api.util.Tristate;
|
||||||
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
@ -94,7 +96,7 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
private final LPNukkitPlugin plugin;
|
private final LPNukkitPlugin plugin;
|
||||||
|
|
||||||
// caches context lookups for the player
|
// caches context lookups for the player
|
||||||
private final QueryOptionsSupplier queryOptionsSupplier;
|
private final QueryOptionsCache<Player> queryOptionsSupplier;
|
||||||
|
|
||||||
// the players previous permissible. (the one they had before this one was injected)
|
// the players previous permissible. (the one they had before this one was injected)
|
||||||
private PermissibleBase oldPermissible = null;
|
private PermissibleBase oldPermissible = null;
|
||||||
@ -164,8 +166,14 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
throw new NullPointerException("permission");
|
throw new NullPointerException("permission");
|
||||||
}
|
}
|
||||||
|
|
||||||
Tristate ts = this.user.getCachedData().getPermissionData(this.queryOptionsSupplier.getQueryOptions()).checkPermission(permission, PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK).result();
|
QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
|
||||||
return ts != Tristate.UNDEFINED ? ts.asBoolean() : PermissionDefault.OP.getValue(isOp());
|
Tristate ts = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission, PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK).result();
|
||||||
|
if (ts != Tristate.UNDEFINED) {
|
||||||
|
return ts.asBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isOp = queryOptions.option(NukkitContextManager.OP_OPTION).orElse(false);
|
||||||
|
return PermissionDefault.OP.getValue(isOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -174,16 +182,18 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
throw new NullPointerException("permission");
|
throw new NullPointerException("permission");
|
||||||
}
|
}
|
||||||
|
|
||||||
Tristate ts = this.user.getCachedData().getPermissionData(this.queryOptionsSupplier.getQueryOptions()).checkPermission(permission.getName(), PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK).result();
|
QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
|
||||||
|
Tristate ts = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission.getName(), PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK).result();
|
||||||
if (ts != Tristate.UNDEFINED) {
|
if (ts != Tristate.UNDEFINED) {
|
||||||
return ts.asBoolean();
|
return ts.asBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isOp = queryOptions.option(NukkitContextManager.OP_OPTION).orElse(false);
|
||||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_NUKKIT_DEFAULT_PERMISSIONS)) {
|
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_NUKKIT_DEFAULT_PERMISSIONS)) {
|
||||||
PermissionDefault def = PermissionDefault.fromPermission(permission);
|
PermissionDefault def = PermissionDefault.fromPermission(permission);
|
||||||
return def != null && def.getValue(isOp());
|
return def != null && def.getValue(isOp);
|
||||||
} else {
|
} else {
|
||||||
return PermissionDefault.OP.getValue(isOp());
|
return PermissionDefault.OP.getValue(isOp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +290,13 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void recalculatePermissions() {
|
public void recalculatePermissions() {
|
||||||
// do nothing
|
// this method is called (among other times) when op status is updated.
|
||||||
|
// because we encapsulate op status within QueryOptions, we need to invalidate
|
||||||
|
// the contextmanager cache when op status changes.
|
||||||
|
// (#invalidate is a fast call)
|
||||||
|
this.queryOptionsSupplier.invalidate();
|
||||||
|
|
||||||
|
// but we don't need to do anything else in this method, unlike the CB impl.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user