Skip to content

Commit

Permalink
Final polishing commit #3
Browse files Browse the repository at this point in the history
- Fix events running in async.
- Add onLogin message warning of ruin status.
- Fix ruined towns still paying upkeep.
  - Somehow they are not storing the hasUpkeep=false when their mayor is
set to NPC.
- Add some more language strings.
- Move delete message to centralized removeTown() method.
- Add remaining hours to the Town status screen.
- Moved the config section to above the war section.
  - Town ruining is not dependant on war being used at all.
  • Loading branch information
LlmDl committed Nov 29, 2020
1 parent 3df7e7d commit 376ba87
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 59 deletions.
5 changes: 4 additions & 1 deletion resources/english.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Towny
version: 0.91
version: 0.92
language: english
author: ElgarL
website: 'http://townyadvanced.github.io/'
Expand Down Expand Up @@ -1195,6 +1195,7 @@ msg_universe_contributors: ' And contributors like you. '
msg_universe_heart: '<3'
townblock_plu: 'TownBlocks'

#Added in 0.92
#Town Ruins
admin_panel_4: 'Run the new hour code'
msg_newhour_success: 'newhour command executed successfully'
Expand All @@ -1205,3 +1206,5 @@ msg_err_cannot_reclaim_town_yet: '&cYou cannot reclaim your town for another %d
msg_town_reclaimed: '&b%s has reclaimed the town of %s.'
msg_err_cannot_attack_ruined_town: '&6[War]&c You cannot attack a ruined town.'
msg_err_cannot_use_command_because_town_ruined: "&cYou cannot use this command because your town is ruined. To resume normal command usage, either reclaim the town using ''/town reclaim'', or leave the town using ''/town leave''."
msg_remaining_ruins_time: '&cRemaining ruins time: %s hours.'
msg_warning_your_town_is_ruined_for_x_more_hours: '&cYour town lies in a ruined state for %d more hours. Use ''/town reclaim'' to save the town and become mayor.'
83 changes: 38 additions & 45 deletions src/com/palmergames/bukkit/config/ConfigNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ public enum ConfigNodes {
"# How much it costs to start a town."),
ECO_PRICE_RECLAIM_RUINED_TOWN(
"economy.new_expand.price_reclaim_ruined_town",
"200.0",
"500.0",
"# How much it costs to reclaim a ruined town.",
"# This is only applicable if the town-ruins & town-reclaim features are enabled."),
ECO_PRICE_OUTPOST(
Expand Down Expand Up @@ -2004,7 +2004,42 @@ public enum ConfigNodes {
"false",
"",
"# If true players will only be able to use /t deposit, /t withdraw, /n deposit & /n withdraw while inside bank plots belonging to the town or nation capital respectively.",
"# Home plots will also allow deposit and withdraw commands."),
"# Home plots will also allow deposit and withdraw commands."),

TOWN_RUINING_HEADER("town_ruining", "", "", "",
" ############################################################",
" # +------------------------------------------------------+ #",
" # | Town Ruining Settings | #",
" # +------------------------------------------------------+ #",
" ############################################################",
""),
TOWN_RUINING_TOWN_RUINS_ENABLED(
"town_ruining.town_ruins.enabled",
"false",
"",
"# If this is true, then if a town falls, it remains in a 'ruined' state for a time.",
"# In this state, the town cannot be claimed, but can be looted.",
"# The feature prevents mayors from escaping attack/occupation, ",
"# by deleting then quickly recreating their town."),
TOWN_RUINING_TOWN_RUINS_MAX_DURATION_HOURS(
"town_ruining.town_ruins.max_duration_hours",
"72",
"",
"# This value determines the maximum duration in which a town can lie in ruins",
"# After this time is reached, the town will be completely deleted.",
"# Does not accept values greater than 1000."),
TOWN_RUINING_TOWN_RUINS_MIN_DURATION_HOURS(
"town_ruining.town_ruins.min_duration_hours",
"4",
"",
"# This value determines the minimum duration in which a town must lie in ruins,",
"# before it can be reclaimed by a resident."),
TOWN_RUINING_TOWN_RUINS_RECLAIM_ENABLED(
"town_ruining.town_ruins.reclaim_enabled",
"true",
"",
"# If this is true, then after a town has been ruined for the minimum configured time,",
"# it can then be reclaimed by any resident who runs /t reclaim, and pays the required price. (price is configured in the eco section)"),
WAR(
"war",
"",
Expand Down Expand Up @@ -2324,49 +2359,7 @@ public enum ConfigNodes {
"",
"# A list of blocks that will not be exploded, mostly because they won't regenerate properly.",
"# These blocks will also protect the block below them, so that blocks like doors do not dupe themselves.",
"# Only under affect when explosions_break_blocks is true."),

WAR_COMMON("war.common", "", "", "",
"############################################################",
"# +------------------------------------------------------+ #",
"# | Common War settings | #",
"# | | #",
"# | These configs are common to multiple war systems. | #",
"# | | #",
"# | Note: The town ruins settings are here, | #",
"# | because town ruin is critical to many war systems | #",
"# | | #",
"# +------------------------------------------------------+ #",
"############################################################",
""),
// Town Ruins
WAR_COMMON_TOWN_RUINS_ENABLED(
"war.common.town_ruins.enabled",
"true",
"",
"# If this is true, then if a town falls, it remains in a 'ruined' state for a time.",
"# In this state, the town cannot be claimed, but can be looted.",
"# The feature prevents mayors from escaping attack/occupation, ",
"# by deleting then quickly recreating their town."),
WAR_COMMON_TOWN_RUINS_MAX_DURATION_HOURS(
"war.common.town_ruins.max_duration_hours",
"72",
"",
"# This value determines the maximum duration in which a town can lie in ruins",
"# After this time is reached, the town will be completely deleted.",
"# Does not accept values greater than 1000."),
WAR_COMMON_TOWN_RUINS_MIN_DURATION_HOURS(
"war.common.town_ruins.min_duration_hours",
"24",
"",
"# This value determines the minimum duration in which a town must lie in ruins,",
"# before it can be reclaimed by a resident."),
WAR_COMMON_TOWN_RUINS_RECLAIM_ENABLED(
"war.common.town_ruins.reclaim_enabled",
"true",
"",
"# If this is true, then after a town has been ruined for the minimum configured time,",
"# it can then be reclaimed by any resident who runs /t reclaim, and pays the required price. (price is configured in the eco section)");
"# Only under affect when explosions_break_blocks is true.");

private final String Root;
private final String Default;
Expand Down
6 changes: 4 additions & 2 deletions src/com/palmergames/bukkit/towny/TownyFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,10 @@ public static List<String> getStatus(Town town) {
Translation.of("firespread") + ((town.isFire() || world.isForceFire()) ? Translation.of("status_on"): Translation.of("status_off")) +
Translation.of("mobspawns") + ((town.hasMobs() || world.isForceTownMobs()) ? Translation.of("status_on"): Translation.of("status_off")));

// Only display the remaining fields if town is not ruined
if (!town.isRuined()) {
if (town.isRuined())
out.add(Translation.of("msg_remaining_ruins_time", town.getRuinDurationRemainingHours()));
// Only display the remaining fields if town is not ruined
else {
// | Bank: 534 coins
if (TownySettings.isUsingEconomy() && TownyEconomyHandler.isActive()) {
String bankString = "";
Expand Down
1 change: 0 additions & 1 deletion src/com/palmergames/bukkit/towny/command/TownCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2782,7 +2782,6 @@ public void townDelete(Player player, String[] split) {

town = resident.getTown();
Confirmation.runOnAccept(() -> {
TownyMessaging.sendGlobalMessage(Translation.of("MSG_DEL_TOWN", town.getName()));
TownyUniverse.getInstance().getDataSource().removeTown(town);
})
.sendTo(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -941,11 +941,9 @@ public void parseAdminTownCommand(String[] split) throws TownyException {
} else if (split[1].equalsIgnoreCase("delete")) {
if (!isConsole) {
TownyMessaging.sendMessage(sender, Translation.of("town_deleted_by_admin", town.getName()));
TownyMessaging.sendGlobalMessage(Translation.of("msg_del_town", town.getName()));
townyUniverse.getDataSource().removeTown(town);
} else { //isConsole
Confirmation.runOnAccept(() -> {
TownyMessaging.sendGlobalMessage(Translation.of("MSG_DEL_TOWN", town.getName()));
TownyUniverse.getInstance().getDataSource().removeTown(town);
})
.sendTo(sender);
Expand Down
3 changes: 3 additions & 0 deletions src/com/palmergames/bukkit/towny/db/TownyDatabaseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.palmergames.bukkit.towny.object.TownBlock;
import com.palmergames.bukkit.towny.object.TownyPermission;
import com.palmergames.bukkit.towny.object.TownyWorld;
import com.palmergames.bukkit.towny.object.Translation;
import com.palmergames.bukkit.towny.object.WorldCoord;
import com.palmergames.bukkit.towny.regen.PlotBlockData;
import com.palmergames.bukkit.towny.regen.TownyRegenAPI;
Expand Down Expand Up @@ -688,6 +689,8 @@ public void removeTown(Town town) {
@Override
public void removeTown(Town town, boolean delayFullRemoval) {

TownyMessaging.sendGlobalMessage(Translation.of("msg_del_town", town.getName()));

if (delayFullRemoval) {
/*
* When Town ruining is active, send the Town into a ruined state, prior to real removal.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.palmergames.bukkit.towny.event.town;

import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

Expand All @@ -13,6 +14,7 @@ public class TownReclaimedEvent extends Event {
private final Resident resident;

public TownReclaimedEvent(Town town, Resident resident) {
super(!Bukkit.getServer().isPrimaryThread());
this.town = town;
this.resident = resident;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.palmergames.bukkit.towny.event.town;

import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

Expand All @@ -11,6 +12,7 @@ public class TownRuinedEvent extends Event {
private final Town town;

public TownRuinedEvent(Town town) {
super(!Bukkit.getServer().isPrimaryThread());
this.town = town;
}

Expand Down
4 changes: 2 additions & 2 deletions src/com/palmergames/bukkit/towny/tasks/DailyTimerTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ protected void collectNationTaxes(Nation nation) throws EconomyException {
* We are running in an Async thread so MUST verify all objects.
*/
if (universe.getDataSource().hasTown(town.getName())) {
if (town.isCapital() || !town.hasUpkeep())
if (town.isCapital() || !town.hasUpkeep() || town.isRuined())
continue;
if (town.getAccount().canPayFromHoldings(taxAmount)) {
// Town is able to pay the nation's tax.
Expand Down Expand Up @@ -450,7 +450,7 @@ public void collectTownCosts() throws EconomyException, TownyException {
*/
if (universe.getDataSource().hasTown(town.getName())) {

if (town.hasUpkeep()) {
if (town.hasUpkeep() && !town.isRuined()) {
double upkeep = TownySettings.getTownUpkeepCost(town);
double upkeepPenalty = TownySettings.getTownPenaltyUpkeepCost(town);
if (upkeepPenalty > 0 && upkeep > 0)
Expand Down
7 changes: 6 additions & 1 deletion src/com/palmergames/bukkit/towny/tasks/OnPlayerLogin.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private void warningMessage(Resident resident) {
if (resident.hasTown()) {
try {
Town town = resident.getTown();
if (town.hasUpkeep()) {
if (town.hasUpkeep() && !town.isRuined()) {
double upkeep = TownySettings.getTownUpkeepCost(town);
try {
if ((upkeep > 0) && (!town.getAccount().canPayFromHoldings(upkeep))) {
Expand Down Expand Up @@ -195,5 +195,10 @@ private void warningMessage(Resident resident) {
}
}

try {
if (resident.hasTown() && resident.getTown().isRuined()) {
TownyMessaging.sendMsg(resident, Translation.of("msg_warning_your_town_is_ruined_for_x_more_hours", resident.getTown().getRuinDurationRemainingHours()));
}
} catch (NotRegisteredException e) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
public class TownRuinSettings {

public static boolean getWarCommonTownRuinsEnabled() {
return TownySettings.getBoolean(ConfigNodes.WAR_COMMON_TOWN_RUINS_ENABLED);
return TownySettings.getBoolean(ConfigNodes.TOWN_RUINING_TOWN_RUINS_ENABLED);
}

public static int getWarCommonTownRuinsMaxDurationHours() {
return Math.min(TownySettings.getInt(ConfigNodes.WAR_COMMON_TOWN_RUINS_MAX_DURATION_HOURS), 1000);
return Math.min(TownySettings.getInt(ConfigNodes.TOWN_RUINING_TOWN_RUINS_MAX_DURATION_HOURS), 1000);
}

public static int getWarCommonTownRuinsMinDurationHours() {
return TownySettings.getInt(ConfigNodes.WAR_COMMON_TOWN_RUINS_MIN_DURATION_HOURS);
return TownySettings.getInt(ConfigNodes.TOWN_RUINING_TOWN_RUINS_MIN_DURATION_HOURS);
}

public static boolean getWarCommonTownRuinsReclaimEnabled() {
return TownySettings.getBoolean(ConfigNodes.WAR_COMMON_TOWN_RUINS_RECLAIM_ENABLED);
return TownySettings.getBoolean(ConfigNodes.TOWN_RUINING_TOWN_RUINS_RECLAIM_ENABLED);
}

public static double getEcoPriceReclaimTown() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void putTownIntoRuinedState(Town town, Towny plugin) {
// Call the TownRuinEvent.
TownRuinedEvent event = new TownRuinedEvent(town);
Bukkit.getPluginManager().callEvent(event);

// Set Town settings.
town.setRuined(true);
town.setRuinDurationRemainingHours(TownRuinSettings.getWarCommonTownRuinsMaxDurationHours());
Expand Down

0 comments on commit 376ba87

Please sign in to comment.