mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-23 09:37:51 +01:00
Allocate WorldPlayerTuple only when using cache
This commit is contained in:
parent
a97db0ede9
commit
1652c9bfc0
@ -48,7 +48,7 @@
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
@ -58,14 +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 static final BiPredicate<World, LocalPlayer> BYPASS_PERMISSION_TEST = (world, player) -> {
|
||||
return player.hasPermission("worldguard.region.bypass." + world.getName());
|
||||
};
|
||||
|
||||
private final LoadingCache<WorldPlayerTuple, Boolean> bypassCache = CacheBuilder.newBuilder()
|
||||
.maximumSize(1000)
|
||||
.expireAfterWrite(2, TimeUnit.SECONDS)
|
||||
.build(CacheLoader.from(BYPASS_PERMISSION_TEST::test));
|
||||
.build(CacheLoader.from(tuple -> BYPASS_PERMISSION_TEST.test(tuple.getWorld(), tuple.getPlayer())));
|
||||
|
||||
private final LoadingCache<CacheKey, Session> sessions = CacheBuilder.newBuilder()
|
||||
.expireAfterAccess(SESSION_LIFETIME, TimeUnit.MINUTES)
|
||||
@ -142,9 +142,11 @@ public boolean hasBypass(LocalPlayer player, World world) {
|
||||
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);
|
||||
if (WorldGuard.getInstance().getPlatform().getGlobalStateManager().disablePermissionCache) {
|
||||
return BYPASS_PERMISSION_TEST.test(world, player);
|
||||
}
|
||||
|
||||
return bypassCache.getUnchecked(new WorldPlayerTuple(world, player));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user