Skip to content

Commit

Permalink
Prevent ruined towns from being bought (#7073)
Browse files Browse the repository at this point in the history
  • Loading branch information
Warriorrrr authored Nov 13, 2023
1 parent 9c23abd commit d5886ff
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4445,10 +4445,14 @@ private void parseTownBuyTownCommand(CommandSender sender, String[] args) throws
if (!town.isForSale()) {
throw new TownyException(Translatable.of("msg_town_buytown_not_forsale"));
}

if (town.isRuined()) {
throw new TownyException("msg_town_buytown_ruined");
}

Resident resident = getResidentOrThrow(player);
if (resident.isMayor()) {
throw new TownyException(Translatable.of("msg_town_buytown_already_mayor", resident.getTownOrNull().getName()));
throw new TownyException(Translatable.of("msg_mayor_abandon"));
}

Confirmation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,9 @@ public void removeOutpostSpawn(Location loc) {
*/
public final void setForSale(boolean isForSale) {
this.isForSale = isForSale;

if (!isForSale)
this.forSalePrice = 0;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public static void putTownIntoRuinedState(Town town) {
if (TownySettings.getMaxResidentsPerTown() > 0)
ResidentUtil.reduceResidentCountToFitTownMaxPop(town);

town.setForSale(false);

town.save();
Towny.getPlugin().resetCache();

Expand Down
1 change: 1 addition & 0 deletions Towny/src/main/resources/lang/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,7 @@ msg_town_sell_confirmation: "This will put your town up for sale for %s. Are you
msg_town_buytown_already_mayor: "You are already mayor of %s."
msg_town_buytown_confirmation: "Buying %s will cost %s and remove you from any town you may currently be a part of. Are you sure you want to continue?"
msg_town_buytown_not_forsale: "Specified town is not for sale."
msg_town_buytown_ruined: "Ruined towns cannot be bought."

msg_resident_about_reset: "&bResident about reset."
msg_err_invalid_string_about_not_set: "Invalid string, resident about not set."
Expand Down

0 comments on commit d5886ff

Please sign in to comment.