Skip to content
Merged
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 @@ -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;
Expand All @@ -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]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading