Skip to content
Open
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
10 changes: 10 additions & 0 deletions Towny/src/main/java/com/palmergames/bukkit/towny/object/Town.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ public boolean equals(Object other) {
public Collection<TownBlock> getTownBlocks() {
return Collections.unmodifiableCollection(townBlocks.values());
}

public Collection<TownBlock> getTownBlocksInWorld(@NotNull TownyWorld world) {
List<TownBlock> list = new ArrayList<>();
for (Map.Entry<WorldCoord, TownBlock> entry : townBlocks.entrySet()) {
if (world.getName().equals(entry.getKey().getWorldName())) {
list.add(entry.getValue());
}
}
return Collections.unmodifiableCollection(list);
}

public int getNumTownBlocks() {
return getTownBlocks().size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static void testAdjacentClaimsRulesOrThrow(WorldCoord townBlockToClaim, T
}

public static void testAdjacentClaimsRulesOrThrow(WorldCoord townBlockToClaim, Town town, boolean outpost, int minAdjacentBlocks) throws TownyException {
if (!outpost && minAdjacentBlocks > 0 && townHasClaimedEnoughLandToBeRestrictedByAdjacentClaims(town, minAdjacentBlocks)) {
if (!outpost && minAdjacentBlocks > 0 && townHasClaimedEnoughLandToBeRestrictedByAdjacentClaims(town, minAdjacentBlocks, townBlockToClaim)) {
// Only consider the first worldCoord, larger selection-claims will automatically "bubble" anyways.
int numAdjacent = numAdjacentTownOwnedTownBlocks(town, townBlockToClaim);
// The number of adjacent TBs is not enough and there is not a nearby outpost.
Expand All @@ -113,11 +113,13 @@ public static void testAdjacentClaimsRulesOrThrow(WorldCoord townBlockToClaim, T
}
}

private static boolean townHasClaimedEnoughLandToBeRestrictedByAdjacentClaims(Town town, int minAdjacentBlocks) {
if (minAdjacentBlocks == 3 && town.getTownBlocks().size() < 5)
private static boolean townHasClaimedEnoughLandToBeRestrictedByAdjacentClaims(Town town, int minAdjacentBlocks, WorldCoord worldCoord) {
TownyWorld world = worldCoord.getTownyWorld();
int claimedTownBlocks = world != null ? town.getTownBlocksInWorld(world).size() : town.getNumTownBlocks();
if (minAdjacentBlocks == 3 && claimedTownBlocks < 5)
// Special rule that makes sure a town can claim a fifth plot after claiming a 2x2 square.
return false;
return town.getTownBlocks().size() > minAdjacentBlocks;
return claimedTownBlocks > minAdjacentBlocks;
}

private static int numAdjacentTownOwnedTownBlocks(Town town, WorldCoord worldCoord) {
Expand Down Expand Up @@ -181,7 +183,7 @@ public static void testAdjacentUnclaimsRulesOrThrow(WorldCoord townBlockToUnclai

public static void testAdjacentUnclaimsRulesOrThrow(WorldCoord townBlockToUnclaim, Town town, int minAdjacentBlocks) throws TownyException {
// Prevent unclaiming land that would reduce the number of adjacent claims of neighbouring plots below the threshold.
if (minAdjacentBlocks > 0 && townHasClaimedEnoughLandToBeRestrictedByAdjacentClaims(town, minAdjacentBlocks)) {
if (minAdjacentBlocks > 0 && townHasClaimedEnoughLandToBeRestrictedByAdjacentClaims(town, minAdjacentBlocks, townBlockToUnclaim)) {

// Outposts cannot be unclaimed when there are any connected townblocks.
if (townBlockToUnclaim.getTownBlockOrNull().isOutpost() && numAdjacentTownOwnedTownBlocks(town, townBlockToUnclaim) > 0)
Expand Down Expand Up @@ -213,7 +215,7 @@ public static void testAdjacentUnclaimsRulesOrThrow(WorldCoord townBlockToUnclai
*/

public static void testAdjacentAddDistrictRulesOrThrow(WorldCoord townBlockToClaim, Town town, District district, int minAdjacentBlocks) throws TownyException {
if (minAdjacentBlocks > 0 && townHasClaimedEnoughLandToBeRestrictedByAdjacentClaims(town, minAdjacentBlocks)) {
if (minAdjacentBlocks > 0 && townHasClaimedEnoughLandToBeRestrictedByAdjacentClaims(town, minAdjacentBlocks, townBlockToClaim)) {
int numAdjacent = numAdjacentDistrictTownBlocks(town, district, townBlockToClaim);
// The number of adjacement TBs with the same District is not enough.
if (numAdjacent < minAdjacentBlocks)
Expand All @@ -231,7 +233,7 @@ private static int numAdjacentDistrictTownBlocks(Town town, District district, W

public static void testAdjacentRemoveDistrictRulesOrThrow(WorldCoord districtCoordBeingRemoved, Town town, District district, int minAdjacentBlocks) throws TownyException {
// Prevent removing parts of Districts that would cause a district to split into two sections.
if (minAdjacentBlocks > 0 && townHasClaimedEnoughLandToBeRestrictedByAdjacentClaims(town, minAdjacentBlocks)) {
if (minAdjacentBlocks > 0 && townHasClaimedEnoughLandToBeRestrictedByAdjacentClaims(town, minAdjacentBlocks, districtCoordBeingRemoved)) {
List<WorldCoord> allAdjacentDistrictWorldCoords = getAdjacentDistrictWorldCoords(town, district, districtCoordBeingRemoved, false);
int districtPlots = allAdjacentDistrictWorldCoords.size();

Expand Down
Loading