From 5363f177a6600ec491b6967a93f10736f19e02a4 Mon Sep 17 00:00:00 2001 From: tastybento Date: Mon, 10 Aug 2026 07:56:51 -0700 Subject: [PATCH] fix: only complain about claim rank when a chunk is actually targeted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The claim rank was checked before anything had established that the click was a claim gesture, so every left or right click in the world ran the denial branch. Any player below the claim rank was told "Your rank cannot claim chunks for this island!" for opening a chest, pressing a button or mining — throttled to once every two seconds, uncancelled and unlogged, so the interaction still went through and nothing showed in console. The checks that recognise ordinary interaction — clicked block sits in unlocked territory, aim ray finds no locked chunk — all sat below the rank check and never got the chance to bail out. Move the rank check to after the target chunk is resolved, so a low-rank teammate only hears about the claim flag when they genuinely aim at a locked chunk, which is what that message was for. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_017EZEwab2kL4i1FNnBYvSmp --- .../listeners/ChunkClaimListener.java | 18 ++++++++++-------- .../listeners/ChunkClaimListenerTest.java | 12 ++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/world/bentobox/chunkblock/listeners/ChunkClaimListener.java b/src/main/java/world/bentobox/chunkblock/listeners/ChunkClaimListener.java index 15519e5..3b330e8 100644 --- a/src/main/java/world/bentobox/chunkblock/listeners/ChunkClaimListener.java +++ b/src/main/java/world/bentobox/chunkblock/listeners/ChunkClaimListener.java @@ -110,20 +110,14 @@ public void onBorderHit(PlayerInteractEvent e) { return; } Island island = optionalIsland.get(); - User user = User.getInstance(player); - // Who may spend the island's credit is an island setting, owner-only by default - if (!island.isAllowed(user, addon.CHUNKBLOCK_CLAIM_CHUNKS)) { - denyClaim(user, island); - return; - } ChunkManager cm = addon.getChunkManager(); // The player must be standing in their own territory, aiming at a locked chunk if (cm.isLocked(island, player.getLocation())) { return; } // A click on a block inside unlocked territory is ordinary interaction (mining a - // generator, pressing a button...), never a claim gesture — regardless of where - // the aim line would end up beyond it. + // generator, opening a chest, pressing a button...), never a claim gesture — + // regardless of where the aim line would end up beyond it. Block clicked = e.getClickedBlock(); if (clicked != null && cm.isUnlocked(island, clicked.getX() >> 4, clicked.getZ() >> 4)) { return; @@ -138,6 +132,14 @@ public void onBorderHit(PlayerInteractEvent e) { if (target == null) { return; } + // Only now that this is genuinely a claim gesture is rank worth raising: who may + // spend the island's credit is an island setting, owner-only by default. Checking + // any earlier turns every ordinary click into a rank complaint. + User user = User.getInstance(player); + if (!island.isAllowed(user, addon.CHUNKBLOCK_CLAIM_CHUNKS)) { + denyClaim(user, island); + return; + } attemptClaim(user, island, target[0], target[1]); } diff --git a/src/test/java/world/bentobox/chunkblock/listeners/ChunkClaimListenerTest.java b/src/test/java/world/bentobox/chunkblock/listeners/ChunkClaimListenerTest.java index 949228c..ab70f0d 100644 --- a/src/test/java/world/bentobox/chunkblock/listeners/ChunkClaimListenerTest.java +++ b/src/test/java/world/bentobox/chunkblock/listeners/ChunkClaimListenerTest.java @@ -220,6 +220,18 @@ void testMiningOwnBlockNearBorderIsNotAClaim() { verify(notifier, never()).notify(any(), any()); } + @Test + void testUsingABlockInOwnTerritoryNeverRaisesTheRankComplaint() { + // Reported bug: a member opening a chest anywhere in the island's own chunks was + // told their rank could not claim, because rank was checked before the gesture was + // known to be a claim at all. + level = 100; + when(island.isAllowed(any(User.class), eq(addon.CHUNKBLOCK_CLAIM_CHUNKS))).thenReturn(false); + when(island.getRank(any(User.class))).thenReturn(RanksManager.MEMBER_RANK); + listener.onBorderHit(hitBlock(Action.RIGHT_CLICK_BLOCK, 14, 8)); + verify(notifier, never()).notify(any(), any()); + } + @Test void testPunchingBlockInLockedChunkClaimsIt() { level = 1;