mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-15 07:05:32 +01:00
Add an option to disable bypass permission cache
This commit is contained in:
parent
36e42eefd0
commit
a97db0ede9
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user