Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ public Entity getFirstNonPlayerEntity() {
@Nullable
public Block getFirstBlock() {
for (Object object : causes) {
if (object instanceof Block b) {
if (object instanceof Block b && (!WorldGuardPlugin.inst().isFolia()
|| Bukkit.isOwnedByCurrentRegion(b.getLocation()))) {
return b;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void onBlockPlace(BlockPlaceEvent event) {
BlockState previousState = event.getBlockReplacedState();

// Some blocks, like tall grass and fire, get replaced
if (previousState.getType() != Material.AIR && previousState.getType() != event.getBlockReplacedState().getType()) {
if (previousState.getType() != Material.AIR && previousState.getType() != event.getBlockPlaced().getType()) {
Events.fireToCancel(event, new BreakBlockEvent(event, create(event.getPlayer()), previousState.getLocation(), previousState.getType()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
Expand Down Expand Up @@ -63,10 +61,10 @@ public abstract class AbstractSessionManager implements SessionManager {
return player.hasPermission("worldguard.region.bypass." + world.getName());
};

private final LoadingCache<WorldPlayerTuple, Boolean> bypassCache = CacheBuilder.newBuilder()
private final Cache<WorldPlayerTuple, Boolean> bypassCache = CacheBuilder.newBuilder()
.maximumSize(1000)
.expireAfterWrite(2, TimeUnit.SECONDS)
.build(CacheLoader.from(tuple -> BYPASS_PERMISSION_TEST.test(tuple.getWorld(), tuple.getPlayer())));
.build();

private final Cache<CacheKey, Session> sessions = CacheBuilder.newBuilder()
.expireAfterAccess(SESSION_LIFETIME, TimeUnit.MINUTES)
Expand Down Expand Up @@ -146,7 +144,13 @@ public boolean hasBypass(LocalPlayer player, World world) {
return BYPASS_PERMISSION_TEST.test(world, player);
}

return bypassCache.getUnchecked(new WorldPlayerTuple(world, player));
WorldPlayerTuple bypassCacheKey = new WorldPlayerTuple(world, player);
Boolean bypass = bypassCache.getIfPresent(bypassCacheKey);
if (bypass == null) {
bypass = BYPASS_PERMISSION_TEST.test(world, player);
bypassCache.put(bypassCacheKey, bypass);
}
return bypass;
}

@Override
Expand Down Expand Up @@ -175,7 +179,12 @@ private Session getIfPresentInternal(CacheKey cacheKey) {

@Override
public Session get(LocalPlayer player) {
Session session = sessions.asMap().computeIfAbsent(new CacheKey(player), (k) -> new Session(this));
CacheKey cacheKey = new CacheKey(player);
Session session = sessions.getIfPresent(cacheKey);
if (session == null) {
session = new Session(this);
sessions.put(cacheKey, session);
}
session.ensureInitialized(player, this::initializeSession);
return session;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ public Location testMoveTo(LocalPlayer player, Location to, MoveType moveType) {
*/
@Nullable
public Location testMoveTo(LocalPlayer player, Location to, MoveType moveType, boolean forced) {
if (lastValid == null) {
// The session can be observed before initialization due to Bukkit event ordering.
return null;
}

RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();

if (!forced && needRefresh.getAndSet(false)) {
Expand Down
Loading