Skip to content

Commit

Permalink
- Add ability for overclaiming to require enemy status, when nations
Browse files Browse the repository at this point in the history
are involved.
    - Closes #7159.
  - New Config Option:
claiming.overclaiming.nations_required_to_be_enemies
    - Default: false
    - When true, when the towns involved in the overclaiming both have
nations, the overclaiming town's nation will have to have the
overclaimed town's nation declared as an enemy.
    - Towns with no nation are not affected by this rule.
  • Loading branch information
LlmDl committed Jan 3, 2024
1 parent 2352315 commit 425bff0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,12 @@ public enum ConfigNodes {
"0m",
"",
"# When in use, requires an amount of time to pass before the /t takeoverclaim command can be used again."),
CLAIMING_OVERCLAIMING_REQUIRES_NATIONS_TO_BE_ENEMIES(
"claiming.overclaiming.nations_required_to_be_enemies",
"false",
"",
"# When true, when the towns involved in the overclaiming both have nations, the overclaiming town's nation will have to have the overclaimed town's nation declared as an enemy.",
"# Towns with no nation are not affected by this rule."),

CLAIMING_BUY_BONUS_ROOT("claiming.purchased_bonus_blocks", "", "", ""),
CLAIMING_MAX_PURCHASED_BLOCKS(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,10 @@ public static int getOverclaimingCommandCooldownInSeconds() {
return (int) getSeconds(ConfigNodes.CLAIMING_OVERCLAIMING_COMMAND_COOLDOWN);
}

public static boolean isOverclaimingWithNationsRequiringEnemy() {
return getBoolean(ConfigNodes.CLAIMING_OVERCLAIMING_REQUIRES_NATIONS_TO_BE_ENEMIES);
}

public static boolean isSellingBonusBlocks(Town town) {

return getMaxPurchasedBlocks(town) != 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3749,14 +3749,26 @@ private void parseTownTakeoverClaimCommand(Player player) throws TownyException
if (wc.isWilderness())
throw new TownyException(Translatable.of("msg_not_own_place"));

Town overclaimedTown = wc.getTownOrNull();

// Make sure the town doesn't already own this land.
if (wc.getTownOrNull().equals(town))
if (overclaimedTown.equals(town))
throw new TownyException(Translatable.of("msg_already_claimed_1"));

// Make sure this is in a town which is overclaimed, allowing for stealing land.
if (!wc.canBeStolen())
throw new TownyException(Translatable.of("msg_err_this_townblock_cannot_be_taken_over"));

// Make sure that if nations are involved and the setting is true, that the
// overclaiming nation has the other declared as an enemy.
if (TownySettings.isOverclaimingWithNationsRequiringEnemy()) {
Nation overclaimingNation = town.getNationOrNull();
Nation overclaimedNation = overclaimedTown.getNationOrNull();
if (overclaimingNation != null && overclaimedNation != null && !overclaimingNation.hasEnemy(overclaimedNation)) {
throw new TownyException(Translatable.of("msg_err_cannot_overclaim_this_town_because_they_arent_your_enemy"));
}
}

// Not enough available claims.
if (!town.hasUnlimitedClaims() && town.availableTownBlocks() < 1)
throw new TownyException(Translatable.of("msg_err_not_enough_blocks"));
Expand Down Expand Up @@ -3788,7 +3800,7 @@ private void parseTownTakeoverClaimCommand(Player player) throws TownyException

double cost = TownySettings.getTakeoverClaimPrice();
String costSlug = !TownyEconomyHandler.isActive() || cost <= 0 ? Translatable.of("msg_spawn_cost_free").forLocale(player) : prettyMoney(cost);
String townName = wc.getTownOrNull().getName();
String townName = overclaimedTown.getName();
Confirmation.runOnAccept(() -> Bukkit.getScheduler().runTask(plugin, new TownClaim(plugin, player, town, Arrays.asList(wc), false, true, false)))
.setTitle(Translatable.of("confirmation_you_are_about_to_take_over_a_claim", townName, costSlug))
.setCost(new ConfirmationTransaction(() -> cost, town, "Takeover Claim (" + wc.toString() + ") from " + townName + "."))
Expand Down
8 changes: 7 additions & 1 deletion Towny/src/main/resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9358,4 +9358,10 @@ v0.92.0.11:
- The max amount of combined ocean biomes as a percent, that will be allowed in plots being claimed by towns.
- For example, if a townblock would be more than X percent ocean it will not be able to be claimed.
0.100.0.18:
- Refactor town homeblock proximity tests into new ProximityUtil method.
- Refactor town homeblock proximity tests into new ProximityUtil method.
- Add ability for overclaiming to require enemy status, when nations are involved.
- Closes #7159.
- New Config Option: claiming.overclaiming.nations_required_to_be_enemies
- Default: false
- When true, when the towns involved in the overclaiming both have nations, the overclaiming town's nation will have to have the overclaimed town's nation declared as an enemy.
- Towns with no nation are not affected by this rule.
4 changes: 3 additions & 1 deletion Towny/src/main/resources/lang/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2402,4 +2402,6 @@ msg_err_cannot_nation_spawn_your_town_is_sanctioned: "Your town is sanctioned by

msg_err_cannot_claim_the_following_worldcoords_because_of_unwanted_biome: "The following coordinate(s) cannot be claimed because they contain too much of an unwanted biome: %s."
msg_err_cannot_claim_the_following_worldcoords_because_of_ocean_biome: "The following coordinate(s) cannot be claimed because they contain too much ocean biome: %s."
msg_err_cannot_begin_town_in_this_biome: "You cannot start a town in this biome."
msg_err_cannot_begin_town_in_this_biome: "You cannot start a town in this biome."

msg_err_cannot_overclaim_this_town_because_they_arent_your_enemy: "You are not able to overclaim this town because your nation does not consider their nation an enemy."

0 comments on commit 425bff0

Please sign in to comment.