From 8822d0bf74822dd5e5fee3a21138ab4fde3f0e69 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 23 Aug 2026 08:18:25 -0700 Subject: [PATCH] refactor: remove max-chunks setting, derive limit from protection range MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The max-chunks config setting was redundant — the protection range already prevents claims outside it via maxRingRadius. The effective chunk cap is now derived solely from the island's protection range: maxChunks = (2 * floor((range - 8) / 16) + 1)^2 With the default range of 168 that gives 441 chunks (21x21), exactly what max-chunks was set to. Admins who want more or fewer chunks adjust the protection range instead of juggling two settings. Co-Authored-By: Claude Opus 4.6 (1M context) Claude-Session: https://claude.ai/code/session_01QWvvUY9ZZJHxUYm1UyjdwK --- .../world/bentobox/chunkblock/Settings.java | 25 ++----------------- .../chunkblock/chunks/ChunkManager.java | 15 ++++------- .../chunkblock/listeners/LevelListener.java | 3 --- src/main/resources/config.yml | 8 ++---- .../chunkblock/chunks/ChunkManagerTest.java | 21 ++++++---------- 5 files changed, 16 insertions(+), 56 deletions(-) diff --git a/src/main/java/world/bentobox/chunkblock/Settings.java b/src/main/java/world/bentobox/chunkblock/Settings.java index 4defcee..381709d 100644 --- a/src/main/java/world/bentobox/chunkblock/Settings.java +++ b/src/main/java/world/bentobox/chunkblock/Settings.java @@ -116,13 +116,6 @@ public class Settings implements WorldSettings { @ConfigEntry(path = "chunkblock.levels-per-chunk") private int levelsPerChunk = 1; - @ConfigComment("Maximum number of chunks an island can claim, including the center chunk.") - @ConfigComment("441 chunks is a full 21 x 21 chunk square. Use -1 for no limit beyond what the") - @ConfigComment("island protection range can hold. The effective maximum is always capped so") - @ConfigComment("claimed chunks fit inside the protection range.") - @ConfigEntry(path = "chunkblock.max-chunks") - private int maxChunks = 441; - @ConfigComment("Require confirmation before level credit is spent on a chunk. When true, the") @ConfigComment("first hit on the border previews the target chunk and its cost; the player") @ConfigComment("must then sneak and hit the border again to actually claim it. This stops a") @@ -313,8 +306,8 @@ public class Settings implements WorldSettings { @ConfigComment("Default protection range radius in blocks. Cannot be larger than distance.") @ConfigComment("Admins can change protection sizes for players individually using /chadmin range set ") @ConfigComment("or set this permission: chunkblock.island.range.") - @ConfigComment("ChunkBlock: this must cover the largest unlockable ring of chunks (see chunkblock.max-chunks).") - @ConfigComment("With max-chunks 441 (21x21, ring 10) the minimum needed is 168.") + @ConfigComment("ChunkBlock: the protection range determines how many chunks can be claimed.") + @ConfigComment("With range 168 the largest ring is 10, giving a 21x21 = 441 chunk square.") @ConfigEntry(path = "world.protection-range") private int islandProtectionRange = 168; @@ -2624,20 +2617,6 @@ public void setLevelsPerChunk(int levelsPerChunk) { this.levelsPerChunk = levelsPerChunk; } - /** - * @return the configured maximum number of unlockable chunks including the center; -1 means unlimited - */ - public int getMaxChunks() { - return maxChunks; - } - - /** - * @param maxChunks the maxChunks to set - */ - public void setMaxChunks(int maxChunks) { - this.maxChunks = maxChunks; - } - /** * @return true if ring milestones are announced to the whole server */ diff --git a/src/main/java/world/bentobox/chunkblock/chunks/ChunkManager.java b/src/main/java/world/bentobox/chunkblock/chunks/ChunkManager.java index f461f73..930bd17 100644 --- a/src/main/java/world/bentobox/chunkblock/chunks/ChunkManager.java +++ b/src/main/java/world/bentobox/chunkblock/chunks/ChunkManager.java @@ -50,7 +50,7 @@ public enum ClaimResult { ALREADY_UNLOCKED, /** The chunk does not touch the island's unlocked territory */ NOT_ADJACENT, - /** The chunk is outside the island's protection range or over max-chunks */ + /** The chunk is outside the island's protection range */ BEYOND_LIMIT, /** Not enough level credit */ NO_CREDIT @@ -301,9 +301,7 @@ public ClaimResult checkGeometry(Island island, int chunkX, int chunkZ) { if (data.isChunkUnlocked(dx, dz)) { return ClaimResult.ALREADY_UNLOCKED; } - if (Math.max(Math.abs(dx), Math.abs(dz)) > maxRingRadius(island) - || (addon.getSettings().getMaxChunks() >= 0 - && data.getUnlockedChunkCount() >= addon.getSettings().getMaxChunks())) { + if (Math.max(Math.abs(dx), Math.abs(dz)) > maxRingRadius(island)) { return ClaimResult.BEYOND_LIMIT; } // Must share a face with territory the island already owns @@ -379,18 +377,15 @@ public int maxRingRadius(Island island) { } /** - * Returns the effective maximum number of chunks this island can unlock: the - * configured max-chunks, additionally capped by what fits inside the island's - * protection range. + * Returns the maximum number of chunks this island can unlock, determined by + * what fits inside the island's protection range. * * @param island the island * @return the maximum unlockable chunk count, always >= 1 */ public int getMaxChunks(Island island) { int rangeRadius = maxRingRadius(island); - int rangeCap = (2 * rangeRadius + 1) * (2 * rangeRadius + 1); - int configured = addon.getSettings().getMaxChunks(); - return Math.max(1, configured < 0 ? rangeCap : Math.min(configured, rangeCap)); + return Math.max(1, (2 * rangeRadius + 1) * (2 * rangeRadius + 1)); } /** diff --git a/src/main/java/world/bentobox/chunkblock/listeners/LevelListener.java b/src/main/java/world/bentobox/chunkblock/listeners/LevelListener.java index fa1d085..51bb4f7 100644 --- a/src/main/java/world/bentobox/chunkblock/listeners/LevelListener.java +++ b/src/main/java/world/bentobox/chunkblock/listeners/LevelListener.java @@ -189,9 +189,6 @@ public void celebrateClaim(Island island, int chunkX, int chunkZ, @Nullable UUID if (user.isOnline() && addon.inWorld(user.getWorld())) { user.sendMessage("chunkblock.chunks.claimed", "[number]", String.valueOf(count), "[credit]", String.valueOf(creditLeft)); - if (count >= cm.getMaxChunks(island)) { - user.sendMessage("chunkblock.chunks.max-reached", "[number]", String.valueOf(count)); - } user.getPlayer().playSound(user.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1F, 1F); } }); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c088b97..97ba4bf 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -51,11 +51,6 @@ chunkblock: # Island levels are chunk currency: credit = island level minus levels already # spent. The island owner spends credit by hitting the border where they want to expand. levels-per-chunk: 1 - # Maximum number of chunks an island can claim, including the center chunk. - # 441 chunks is a full 21 x 21 chunk square. Use -1 for no limit beyond what the - # island protection range can hold. The effective maximum is always capped so - # claimed chunks fit inside the protection range. - max-chunks: 441 claim: # Require confirmation before level credit is spent on a chunk. When true, the # first hit on the border previews the target chunk and its cost; the player @@ -209,7 +204,8 @@ world: # Default protection range radius in blocks. Cannot be larger than distance. # Admins can change protection sizes for players individually using /chadmin range set # or set this permission: chunkblock.island.range. - # ChunkBlock: this must cover the largest unlockable ring of chunks (see chunkblock.max-chunks). + # ChunkBlock: the protection range determines how many chunks can be claimed. + # With range 168 the largest ring is 10, giving a 21x21 = 441 chunk square. protection-range: 240 # Start islands at these coordinates. This is where new islands will start in the # world. These must be a factor of your island distance, but the plugin will auto diff --git a/src/test/java/world/bentobox/chunkblock/chunks/ChunkManagerTest.java b/src/test/java/world/bentobox/chunkblock/chunks/ChunkManagerTest.java index 8a6680c..2a75be2 100644 --- a/src/test/java/world/bentobox/chunkblock/chunks/ChunkManagerTest.java +++ b/src/test/java/world/bentobox/chunkblock/chunks/ChunkManagerTest.java @@ -133,15 +133,6 @@ void testClaimBeyondProtectionRangeDenied() { assertEquals(ClaimResult.BEYOND_LIMIT, cm.claim(island, 3, 0)); } - @Test - void testClaimBeyondMaxChunksDenied() { - level = 100000; - settings.setMaxChunks(3); - assertEquals(ClaimResult.OK, cm.claim(island, 1, 0)); - assertEquals(ClaimResult.OK, cm.claim(island, -1, 0)); - assertEquals(ClaimResult.BEYOND_LIMIT, cm.claim(island, 0, 1)); - } - @Test void testLevelsPerChunkCost() { settings.setLevelsPerChunk(10); @@ -210,13 +201,15 @@ void testOffsetIslandCenter() { } @Test - void testMaxChunksCappedByProtectionRange() { - assertEquals(441, cm.getMaxChunks(island)); + void testMaxChunksDerivedFromProtectionRange() { + // Default setup: protectionRange=240, maxRingRadius=(240-8)/16=14, (2*14+1)^2=841 + assertEquals(841, cm.getMaxChunks(island)); when(island.getProtectionRange()).thenReturn(50); + // (50-8)/16=2, (2*2+1)^2=25 assertEquals(25, cm.getMaxChunks(island)); - settings.setMaxChunks(-1); - when(island.getProtectionRange()).thenReturn(240); - assertEquals(841, cm.getMaxChunks(island)); + when(island.getProtectionRange()).thenReturn(168); + // (168-8)/16=10, (2*10+1)^2=441 + assertEquals(441, cm.getMaxChunks(island)); } @Test