From e79100c6f1a6145d465cf2a1424404912b4ff4cc Mon Sep 17 00:00:00 2001 From: bloodshot Date: Thu, 9 Apr 2020 15:32:27 -0400 Subject: [PATCH] Ignore observers during block tracking. Fixes #164 --- .../listener/BlockEventTracker.java | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/bukkit/src/main/java/com/griefdefender/listener/BlockEventTracker.java b/bukkit/src/main/java/com/griefdefender/listener/BlockEventTracker.java index 3fea00f..3e9c696 100644 --- a/bukkit/src/main/java/com/griefdefender/listener/BlockEventTracker.java +++ b/bukkit/src/main/java/com/griefdefender/listener/BlockEventTracker.java @@ -33,6 +33,7 @@ import com.griefdefender.internal.util.BlockUtil; import com.griefdefender.internal.util.NMSUtil; import com.griefdefender.internal.util.VecHelper; +import com.griefdefender.permission.GDPermissionManager; import com.griefdefender.permission.GDPermissionUser; import com.griefdefender.util.CauseContextHelper; import com.griefdefender.util.Direction; @@ -104,30 +105,38 @@ public void onBlockPlaceMonitor(BlockPlaceEvent event) { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPhysicsMonitor(BlockPhysicsEvent event) { - if (!event.isCancelled()) { - final Vector3i testPos = VecHelper.toVector3i(event.getBlock().getLocation()); - final Block sourceBlock = NMSUtil.getInstance().getSourceBlock(event); - final Location sourceLocation = sourceBlock != null ? sourceBlock.getLocation() : null; - if (sourceLocation != null && sourceLocation.equals(event.getBlock().getLocation())) { + final String targetBlockName = GDPermissionManager.getInstance().getPermissionIdentifier(event.getBlock()); + if (targetBlockName.equals("minecraft:observer")) { + return; + } + + final Block sourceBlock = NMSUtil.getInstance().getSourceBlock(event); + final Location sourceLocation = sourceBlock != null ? sourceBlock.getLocation() : null; + if (sourceLocation != null && sourceLocation.equals(event.getBlock().getLocation())) { + return; + } + if (sourceBlock != null) { + final String sourceBlockName = GDPermissionManager.getInstance().getPermissionIdentifier(sourceBlock); + if (sourceBlockName.equals("minecraft:observer")) { return; } + } - final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(event.getBlock().getWorld().getUID()); - final GDChunk gpChunk = claimWorldManager.getChunk(event.getBlock().getChunk()); - final GDPermissionUser user = CauseContextHelper.getEventUser(sourceLocation); - final UUID uuid = user != null ? user.getUniqueId() : null; + final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(event.getBlock().getWorld().getUID()); + final GDChunk gpChunk = claimWorldManager.getChunk(event.getBlock().getChunk()); + final GDPermissionUser user = CauseContextHelper.getEventUser(sourceLocation); + final UUID uuid = user != null ? user.getUniqueId() : null; - final Vector3i targetPos = VecHelper.toVector3i(event.getBlock().getLocation()); - //final Vector3i sourcePos = VecHelper.toVector3i(event.getSourceBlock().getLocation()); - //final Location targetLocation = event.getBlock().getLocation(); - if (uuid != null) { - gpChunk.addTrackedBlockPosition(targetPos, uuid, PlayerTracker.Type.NOTIFIER); - // Bukkit doesn't send surrounding events for performance reasons so we must handle it manually - /*for (Direction direction : NOTIFY_DIRECTIONS) { - final Vector3i directionPos = targetPos.add(direction.asBlockOffset()); - gpChunk.addTrackedBlockPosition(directionPos, uuid, PlayerTracker.Type.NOTIFIER); - }*/ - } + final Vector3i targetPos = VecHelper.toVector3i(event.getBlock().getLocation()); + //final Vector3i sourcePos = VecHelper.toVector3i(event.getSourceBlock().getLocation()); + //final Location targetLocation = event.getBlock().getLocation(); + if (uuid != null) { + gpChunk.addTrackedBlockPosition(targetPos, uuid, PlayerTracker.Type.NOTIFIER); + // Bukkit doesn't send surrounding events for performance reasons so we must handle it manually + /*for (Direction direction : NOTIFY_DIRECTIONS) { + final Vector3i directionPos = targetPos.add(direction.asBlockOffset()); + gpChunk.addTrackedBlockPosition(directionPos, uuid, PlayerTracker.Type.NOTIFIER); + }*/ } }