diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/config/ConfigurationManager.java b/worldguard-core/src/main/java/com/sk89q/worldguard/config/ConfigurationManager.java index c9dd5e1d..4c22353c 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/config/ConfigurationManager.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/config/ConfigurationManager.java @@ -76,6 +76,7 @@ public abstract class ConfigurationManager { public boolean migrateRegionsToUuid; public boolean keepUnresolvedNames; public boolean particleEffects; + public boolean disablePermissionCache; @Unreported public Map hostKeys = new HashMap<>(); public boolean hostKeysAllowFMLClients; diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/config/YamlConfigurationManager.java b/worldguard-core/src/main/java/com/sk89q/worldguard/config/YamlConfigurationManager.java index 56f45443..8523ee11 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/config/YamlConfigurationManager.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/config/YamlConfigurationManager.java @@ -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); diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/session/AbstractSessionManager.java b/worldguard-core/src/main/java/com/sk89q/worldguard/session/AbstractSessionManager.java index 5ac3edc7..6ba6c347 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/session/AbstractSessionManager.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/session/AbstractSessionManager.java @@ -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 BYPASS_PERMISSION_TEST = tuple -> { + return tuple.getPlayer().hasPermission("worldguard.region.bypass." + tuple.getWorld().getName()); + }; + private final LoadingCache 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 sessions = CacheBuilder.newBuilder() .expireAfterAccess(SESSION_LIFETIME, TimeUnit.MINUTES) @@ -134,8 +138,13 @@ public boolean unregisterHandler(Handler.Factory 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