From 4b099d3588ba89c4872914653665774958c5af45 Mon Sep 17 00:00:00 2001 From: Pierre Maurice Schwang Date: Tue, 3 Sep 2024 23:16:00 +0200 Subject: [PATCH] fix(GriefDefender): invalidate mask on claim change (#2903) --- .../bukkit/regions/GriefDefenderFeature.java | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/GriefDefenderFeature.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/GriefDefenderFeature.java index 9ac2fd68a..f1baf3d9e 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/GriefDefenderFeature.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/regions/GriefDefenderFeature.java @@ -3,7 +3,9 @@ package com.fastasyncworldedit.bukkit.regions; import com.fastasyncworldedit.core.regions.FaweMask; import com.griefdefender.api.GriefDefender; import com.griefdefender.api.claim.Claim; +import com.griefdefender.api.claim.ClaimManager; import com.griefdefender.api.claim.TrustTypes; +import com.griefdefender.lib.flowpowered.math.vector.Vector3i; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.math.BlockVector3; @@ -17,8 +19,8 @@ public class GriefDefenderFeature extends BukkitMaskManager implements Listener private static final Logger LOGGER = LogManagerCompat.getLogger(); - public GriefDefenderFeature(final Plugin GriefDefenderPlugin) { - super(GriefDefenderPlugin.getName()); + public GriefDefenderFeature(final Plugin plugin) { + super(plugin.getName()); LOGGER.info("Plugin 'GriefDefender' found. Using it now."); } @@ -44,9 +46,14 @@ public class GriefDefenderFeature extends BukkitMaskManager implements Listener ); return new FaweMask(new CuboidRegion(pos1, pos2)) { + private final int[] bounds = new int[]{ + pos1.x(), pos1.y(), pos1.z(), + pos2.x(), pos2.y(), pos2.z() + }; + @Override public boolean isValid(com.sk89q.worldedit.entity.Player wePlayer, MaskType type) { - return isAllowed(player, claim, type); + return validateClaimAgainstCache(claim, bounds) && isAllowed(player, claim, type); } }; } @@ -54,4 +61,20 @@ public class GriefDefenderFeature extends BukkitMaskManager implements Listener return null; } + private static boolean validateClaimAgainstCache(Claim claim, int[] bounds) { + Vector3i min = claim.getLesserBoundaryCorner(); + Vector3i max = claim.getGreaterBoundaryCorner(); + if (min.getX() != bounds[0] || min.getY() != bounds[1] || min.getZ() != bounds[2]) { + return false; + } + if (max.getX() != bounds[3] || max.getY() != bounds[4] || max.getZ() != bounds[5]) { + return false; + } + final ClaimManager manager = GriefDefender.getCore().getClaimManager(claim.getWorldUniqueId()); + if (manager == null) { + return false; + } + return manager.getClaimByUUID(claim.getUniqueId()) != null; + } + }