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
25 changes: 2 additions & 23 deletions src/main/java/world/bentobox/chunkblock/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 <player> <new range>")
@ConfigComment("or set this permission: chunkblock.island.range.<number>")
@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;

Expand Down Expand Up @@ -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
*/
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/world/bentobox/chunkblock/chunks/ChunkManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 &gt;= 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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ public void celebrateClaim(Island island, int chunkX, int chunkZ, @Nullable UUID
user.sendMessage("chunkblock.chunks.claimed", TextVariables.NAME, claimerName,
"[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);
}
});
Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
Loading