Skip to content

Commit

Permalink
- Add ability to prevent conquered towns from using their nation's
Browse files Browse the repository at this point in the history
nation zones.
    - Conquered towns can still use their own nationzone outside of
their town.
    - Closes #7507.
  - New Config Option:
global_nation_settings.nationzone.not_for_conquered_towns
    - Default: false
    - When set to true, players which are part of a conquered town, will
not have access to their nation's nationzone.
    - They will still be able to use the nation_zone outside of their
own town.
  • Loading branch information
LlmDl committed Jul 15, 2024
1 parent f25a886 commit c902236
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Towny/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<artifactId>towny</artifactId>
<packaging>jar</packaging>
<version>0.100.3.7</version>
<version>0.100.3.8</version>

<licenses>
<license>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,12 @@ public enum ConfigNodes {
"0",
"",
"# Amount of buffer added to nation zone width surrounding capitals only. Creates a larger buffer around nation capitals."),
GNATION_SETTINGS_NATIONZONE_SKIPS_CONQUERED_TOWNS(
"global_nation_settings.nationzone.not_for_conquered_towns",
"false",
"",
"# When set to true, players which are part of a conquered town, will not have access to their nation's nationzone.",
"# They will still be able to use the nation_zone outside of their own town."),
GNATION_SETTINGS_NATIONZONE_WAR_DISABLES(
"global_nation_settings.nationzone.war_disables",
"true",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3219,6 +3219,10 @@ public static boolean getNationZonesShowNotifications() {
return getBoolean(ConfigNodes.GNATION_SETTINGS_NATIONZONE_SHOW_NOTIFICATIONS);
}

public static boolean getNationZonesSkipConqueredTowns() {
return getBoolean(ConfigNodes.GNATION_SETTINGS_NATIONZONE_SKIPS_CONQUERED_TOWNS);
}

public static int getNationZonesCapitalBonusSize() {
return getInt(ConfigNodes.GNATION_SETTINGS_NATIONZONE_CAPITAL_BONUS_SIZE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ private static boolean getPermission(Player player, TownBlockStatus status, Worl
/*
* Handle the possiblity that NationZones are enabled the
* TownBlockStatus is NATION_ZONE instead of UNCLAIMED_ZONE.
* In all situations the player still has to hasWildOverride.
* In all situations the player still has to have hasWildOverride.
*/
if (TownySettings.getNationZonesEnabled() && status == TownBlockStatus.NATION_ZONE) {
// Admins that also have wilderness permission can bypass the nation zone.
Expand All @@ -330,11 +330,21 @@ private static boolean getPermission(Player player, TownBlockStatus status, Worl
}

// We know that the nearest Town will have a nation because the TownBlockStatus.
Nation nearestNation = TownyAPI.getInstance().getTownNationOrNull(pos.getTownyWorld().getClosestTownWithNationFromCoord(pos.getCoord(), null));
Town nearestTown = pos.getTownyWorld().getClosestTownWithNationFromCoord(pos.getCoord(), null);
Nation nearestNation = nearestTown.getNationOrNull();

// If the player has a Nation and is a member of this NationZone's nation.
if (res.hasNation() && res.getNationOrNull().getUUID().equals(nearestNation.getUUID()))
// This player is in their nation's nationzone.
if (nearestNation.hasResident(res)) {

// Prevent conquered towns using their nation's Nation Zone, unless that nation zone is surrounding the conquered town.
if (TownySettings.getNationZonesSkipConqueredTowns() && res.getTownOrNull().isConquered() && !nearestTown.hasResident(res)) {
cacheBlockErrMsg(player, Translatable.of("nation_zone_conquered_status_denies_use").forLocale(res));
return false;
}

// Allow a resident to use their nation's nation zone.
return true;
}

// The player is not a nation member of this NationZone.
cacheBlockErrMsg(player, Translatable.of("nation_zone_this_area_under_protection_of", pos.getTownyWorld().getFormattedUnclaimedZoneName(), nearestNation.getName()).forLocale(player));
Expand Down
10 changes: 9 additions & 1 deletion Towny/src/main/resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9900,4 +9900,12 @@ v0.92.0.11:
- If a plugin you use has broken, the author needs only change their imports section, switching to the re-located Transaction, TransactionType classes.
- Plugins under the umbrella of the TownyAdvanced organization which are known to have broken include EventWar, FlagWar.
- Do not update your Towny if you use either of these plugins until you see they have had a compatibility update.
- Fix for SQL db code related to new Districts.
- Fix for SQL db code related to new Districts.
0.100.3.8:
- Add ability to prevent conquered towns from using their nation's nation zones.
- Conquered towns can still use their own nationzone outside of their town.
- Closes #7507.
- New Config Option: global_nation_settings.nationzone.not_for_conquered_towns
- Default: false
- When set to true, players which are part of a conquered town, will not have access to their nation's nationzone.
- They will still be able to use the nation_zone outside of their own town.

0 comments on commit c902236

Please sign in to comment.