Skip to content

Commit 3985891

Browse files
Add configurable peaceful town restrictions for homeblock moves and capitals (#1006)
- Adds peaceful_towns.cannot_move_homeblock config option to control whether peaceful towns can move their homeblock - Adds peaceful_towns.allow_peaceful_capitals config option to allow nation capitals to be peaceful Both default to existing behavior (homeblock moves blocked, capitals forced non-peaceful)
1 parent e758bf0 commit 3985891

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public void onTownUnclaim(TownPreUnclaimCmdEvent event) {
162162
}
163163

164164
/*
165-
* If town is peaceful, sieged, or occupied, it can't move homeblock.
165+
* If town is peaceful (configurable), sieged, or occupied, it can't move homeblock.
166166
* otherwise the move homeblock command could be / definitely would be
167167
* used by players as an easy exploit to escape occupation.
168168
*
@@ -176,6 +176,7 @@ public void on(TownPreSetHomeBlockEvent event) {
176176
if (SiegeWarSettings.getWarSiegeEnabled()) {
177177
Translator translator = Translator.locale(event.getPlayer());
178178
if(SiegeWarSettings.getWarCommonPeacefulTownsEnabled()
179+
&& SiegeWarSettings.arePeacefulTownsNotAllowedToMoveHomeBlock()
179180
&& SiegeWarTownPeacefulnessUtil.isTownPeaceful(event.getTown())) {
180181
event.setCancelled(true);
181182
event.setCancelMessage(translator.of("siegewar_plugin_prefix") + translator.of("msg_err_peaceful_town_cannot_move_homeblock"));

src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,17 @@ public enum ConfigNodes {
626626
"",
627627
"# Prevents players in peaceful towns from being given ranks with military-rank-permission nodes.",
628628
"# It is not recommended to set this to false."),
629+
PEACEFUL_TOWNS_CANNOT_MOVE_HOMEBLOCK(
630+
"peaceful_towns.cannot_move_homeblock",
631+
"true",
632+
"",
633+
"# If this is true, peaceful towns cannot move their homeblock."),
634+
PEACEFUL_TOWNS_ALLOW_PEACEFUL_CAPITALS(
635+
"peaceful_towns.allow_peaceful_capitals",
636+
"false",
637+
"",
638+
"# If this is true, nation capital towns are allowed to be peaceful.",
639+
"# By default, capital towns are forced to be non-peaceful."),
629640

630641
OCCUPIED_TOWNS(
631642
"occupied_towns",

src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,14 @@ public static boolean arePeacefulTownsNotAllowedToAssignMilitaryRanks() {
266266
return Settings.getBoolean(ConfigNodes.PEACEFUL_TOWNS_CANNOT_ASSIGN_MILITARY_RANKS);
267267
}
268268

269+
public static boolean arePeacefulTownsNotAllowedToMoveHomeBlock() {
270+
return Settings.getBoolean(ConfigNodes.PEACEFUL_TOWNS_CANNOT_MOVE_HOMEBLOCK);
271+
}
272+
273+
public static boolean arePeacefulCapitalsAllowed() {
274+
return Settings.getBoolean(ConfigNodes.PEACEFUL_TOWNS_ALLOW_PEACEFUL_CAPITALS);
275+
}
276+
269277
public static int getWarCommonPeacefulTownsNewTownConfirmationRequirementDays() {
270278
return Settings.getInt(ConfigNodes.PEACEFUL_TOWNS_NEW_TOWN_CONFIRMATION_REQUIREMENT_DAYS);
271279
}

src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownPeacefulnessUtil.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ public static void updateTownPeacefulnessCounters(Town town) {
8686
}
8787
TownMetaDataController.setPeacefulnessChangeCountdownDays(town, 0);
8888

89-
// The Town would become a peaceful capital city, which is not allowed.
90-
if (town.isCapital() && !TownMetaDataController.getPeacefulness(town)) {
89+
// The Town would become a peaceful capital city, which is not allowed (unless configured).
90+
if (!SiegeWarSettings.arePeacefulCapitalsAllowed() && town.isCapital() && !TownMetaDataController.getPeacefulness(town)) {
9191
TownyMessaging.sendPrefixedTownMessage(town, Translatable.of("msg_err_your_town_cannot_be_peaceful_while_a_capital_city"));
9292
return;
9393
}
@@ -126,7 +126,7 @@ public static void toggleTownPeacefulness(Player player) {
126126
}
127127

128128
Town town = resident.getTownOrNull();
129-
if (town.isCapital()) {
129+
if (!SiegeWarSettings.arePeacefulCapitalsAllowed() && town.isCapital()) {
130130
if (!isTownPeaceful(town)) {
131131
//If the capital is non-peaceful, it cannot switch to peaceful
132132
TownyMessaging.sendErrorMsg(player, translator.of("msg_err_capital_towns_cannot_go_peaceful"));
@@ -261,6 +261,8 @@ private static void removePeacefulness(Town town) {
261261
* then start the switch process
262262
*/
263263
public static void switchOffPeacefulnessForCapitals() {
264+
if (SiegeWarSettings.arePeacefulCapitalsAllowed())
265+
return;
264266
for(Nation nation: new ArrayList<>(TownyAPI.getInstance().getNations())) {
265267
if(isTownPeaceful(nation.getCapital()) && getTownPeacefulnessChangeCountdownDays(nation.getCapital()) == 0) {
266268
toggleTownPeacefulness(nation.getCapital());

0 commit comments

Comments
 (0)