Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix peaceful towns being able to become the capital of a nation. #917

Merged
merged 3 commits into from
Jul 24, 2024
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.goosius</groupId>
<artifactId>SiegeWar</artifactId>
<version>2.12.0</version>
<version>2.12.1</version>
<name>siegewar</name> <!-- Leave lower-cased -->

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,26 @@ public void on(NationToggleNeutralEvent event) {

@EventHandler(ignoreCancelled = true)
public void onNationChangeKingEvent(NationKingChangeEvent event) {
if(!SiegeWarSettings.getWarSiegeEnabled())
if(!SiegeWarSettings.getWarSiegeEnabled() || !event.isCapitalChange())
return;

Town oldCapital = event.getOldKing().getTownOrNull();
Town newCapital = event.getNewKing().getTownOrNull();
if (SiegeWarSettings.getWarSiegeEnabled()
&& SiegeWarSettings.getWarSiegeBesiegedCapitalsCannotChangeKing()
&& event.isCapitalChange()
if (SiegeWarSettings.getWarSiegeBesiegedCapitalsCannotChangeKing()
&& (SiegeController.hasSiege(oldCapital) || SiegeController.hasSiege(newCapital))) {
event.setCancelled(true);
event.setCancelMessage(Translation.of("plugin_prefix") + Translation.of("msg_err_besieged_capital_cannot_change_king"));
return;
}
}

if (!SiegeWarSettings.capitalsAllowedTownPeacefulness()
&& SiegeWarTownPeacefulnessUtil.isTownPeaceful(newCapital)) {
event.setCancelled(true);
event.setCancelMessage(Translation.of("plugin_prefix") + Translation.of("msg_err_cannot_change_capital_because_peaceful"));
return;
}
}

/**
* In SiegeWar, occupied towns cannot leave their nation in the normal way.
* Intead they must be either kicked, or win a revolt siege.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ public static void evaluatePlaceColouredBannerNearTown(Player player,
if(!nearbyTown.isAllowedToWar())
throw new TownyException(Translatable.of("msg_err_this_town_is_not_allowed_to_be_attacked"));

//Ensure the player is not part of a peaceful town.
if (SiegeWarTownPeacefulnessUtil.isTownPeaceful(residentsTown))
throw new TownyException(Translatable.of("msg_err_cannot_start_siege_as_a_peaceful_town"));

if(SiegeWarTownPeacefulnessUtil.isTownPeaceful(nearbyTown)) {
//Town is peaceful
if(residentsTown == nearbyTown) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public static void updateTownPeacefulnessCounters(Town town) {
}
TownMetaDataController.setPeacefulnessChangeCountdownDays(town, 0);

// The Town would become a peaceful capital city, which is not allowed.
if (!SiegeWarSettings.capitalsAllowedTownPeacefulness() && town.isCapital() && !TownMetaDataController.getPeacefulness(town)) {
TownyMessaging.sendPrefixedTownMessage(town, Translatable.of("msg_err_your_town_cannot_be_peaceful_while_a_capital_city"));
return;
}

//Reverse the town peacefulness setting
TownMetaDataController.setPeacefulness(town, !TownMetaDataController.getPeacefulness(town));

Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/lang/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -704,4 +704,8 @@ msg_err_town_surrender_disabled_in_the_config: "&cIn the siegewar config, town s
msg_err_invading_disabled_in_the_config: "&cIn the siegewar config, invading towns has been disabled."
msg_err_action_disable_missing_node: '&cYou don''t have enough permissions for that action: %s'
msg_err_your_nation_is_not_the_attacking_nation_cannot_invade: "Your nation is not the attacker, you cannot invade this town."
msg_err_you_arent_able_to_abandon_or_surrender_this_siege: "You do not have the authority to abandon or surrender this siege."
msg_err_you_arent_able_to_abandon_or_surrender_this_siege: "You do not have the authority to abandon or surrender this siege."

msg_err_cannot_change_capital_because_peaceful: "&cYou cannot change the capital of the nation, because the new capital is peaceful."
msg_err_your_town_cannot_be_peaceful_while_a_capital_city: "&cYour town could not change to peaceful because capital cities are not allowed to be peaceful."
msg_err_cannot_start_siege_as_a_peaceful_town: "&cYou cannot begin a siege, because your town is peaceful."