Add an option to disable bypass permission cache

This commit is contained in:
TheMolkaPL 2020-06-27 03:31:47 +02:00 committed by wizjany
parent 36e42eefd0
commit a97db0ede9
3 changed files with 15 additions and 4 deletions

View File

@ -76,6 +76,7 @@ public abstract class ConfigurationManager {
public boolean migrateRegionsToUuid;
public boolean keepUnresolvedNames;
public boolean particleEffects;
public boolean disablePermissionCache;
@Unreported public Map<String, String> hostKeys = new HashMap<>();
public boolean hostKeysAllowFMLClients;

View File

@ -63,6 +63,7 @@ public void load() {
usePlayerMove = config.getBoolean("use-player-move-event", true);
usePlayerTeleports = config.getBoolean("use-player-teleports", true);
particleEffects = config.getBoolean("use-particle-effects", true);
disablePermissionCache = config.getBoolean("disable-permission-cache", false);
deopOnJoin = config.getBoolean("security.deop-everyone-on-join", false);
blockInGameOp = config.getBoolean("security.block-in-game-op-command", false);

View File

@ -48,6 +48,7 @@
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.logging.Level;
import static com.google.common.base.Preconditions.checkNotNull;
@ -57,11 +58,14 @@ public abstract class AbstractSessionManager implements SessionManager {
public static final int RUN_DELAY = 20;
public static final long SESSION_LIFETIME = 10;
private static final Predicate<WorldPlayerTuple> BYPASS_PERMISSION_TEST = tuple -> {
return tuple.getPlayer().hasPermission("worldguard.region.bypass." + tuple.getWorld().getName());
};
private final LoadingCache<WorldPlayerTuple, Boolean> bypassCache = CacheBuilder.newBuilder()
.maximumSize(1000)
.expireAfterWrite(2, TimeUnit.SECONDS)
.build(CacheLoader.from(tuple ->
tuple.getPlayer().hasPermission("worldguard.region.bypass." + tuple.getWorld().getName())));
.build(CacheLoader.from(BYPASS_PERMISSION_TEST::test));
private final LoadingCache<CacheKey, Session> sessions = CacheBuilder.newBuilder()
.expireAfterAccess(SESSION_LIFETIME, TimeUnit.MINUTES)
@ -134,8 +138,13 @@ public boolean unregisterHandler(Handler.Factory<? extends Handler> factory) {
@Override
public boolean hasBypass(LocalPlayer player, World world) {
Session sess = getIfPresent(player);
return sess != null && !sess.hasBypassDisabled()
&& bypassCache.getUnchecked(new WorldPlayerTuple(world, player));
if (sess == null || sess.hasBypassDisabled()) {
return false;
}
WorldPlayerTuple tuple = new WorldPlayerTuple(world, player);
boolean disablePermissionCache = WorldGuard.getInstance().getPlatform().getGlobalStateManager().disablePermissionCache;
return disablePermissionCache ? BYPASS_PERMISSION_TEST.test(tuple) : bypassCache.getUnchecked(tuple);
}
@Override