Skip to content

Commit

Permalink
Add messages to residents when they pay town and plot taxes.
Browse files Browse the repository at this point in the history
Closes #7657.
  • Loading branch information
LlmDl committed Nov 4, 2024
1 parent 96afba7 commit 6c08e3a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.bukkit.entity.Player;

Expand All @@ -39,6 +41,7 @@ public class DailyTimerTask extends TownyTimerTask {
private final List<String> bankruptedTowns = new ArrayList<>();
private final List<String> removedTowns = new ArrayList<>();
private final List<String> removedNations = new ArrayList<>();
private final Map<Resident, Map<Town, Double>> residentPlotTaxMap = new ConcurrentHashMap<>();

public DailyTimerTask(Towny plugin) {

Expand All @@ -61,6 +64,7 @@ public void doNewDay() {
bankruptedTowns.clear();
removedTowns.clear();
removedNations.clear();
residentPlotTaxMap.clear();

BukkitTools.fireEvent(new PreNewDayEvent()); // Pre-New Day Event

Expand Down Expand Up @@ -388,6 +392,9 @@ public void collectTownTaxes() {

collectTownTaxes(town);
}

if (!residentPlotTaxMap.isEmpty())
messageResidentsAboutPlotTaxesPaid();
}

/**
Expand Down Expand Up @@ -485,6 +492,8 @@ private boolean collectTownTaxFromResident(double tax, Resident resident, Town t
return true;

resident.getAccount().payTo(tax, town, String.format("Town Tax (Percentage) paid by %s.", resident.getName()));
if (resident.isOnline())
TownyMessaging.sendMsg(resident, Translatable.of("msg_you_paid_town_tax", prettyMoney(tax)));
taxCollected += tax;
return true;
}
Expand All @@ -500,6 +509,8 @@ private boolean collectTownTaxFromResident(double tax, Resident resident, Town t

if (resident.getAccount().canPayFromHoldings(tax)) {
resident.getAccount().payTo(tax, town, String.format("Town tax (FlatRate) paid by %s.", resident.getName()));
if (resident.isOnline())
TownyMessaging.sendMsg(resident, Translatable.of("msg_you_paid_town_tax", prettyMoney(tax)));
taxCollected += tax;
return true;
}
Expand Down Expand Up @@ -579,6 +590,10 @@ private void collecTownPlotTax(Town town) {
private boolean collectPlotTaxFromResident(double tax, Resident resident, Town town, TownBlock townBlock) {
if (resident.getAccount().canPayFromHoldings(tax)) {
resident.getAccount().payTo(tax, town, String.format("Plot Tax (%s) paid by %s", townBlock.getTypeName(), resident.getName()));

if (resident.isOnline())
addPaymentToPlotTaxMap(resident, town, tax);

taxCollected += tax;
return true;
}
Expand All @@ -600,6 +615,34 @@ private boolean collectPlotTaxFromResident(double tax, Resident resident, Town t
return false;
}

private void addPaymentToPlotTaxMap(Resident resident, Town town, double tax) {
if (!residentPlotTaxMap.containsKey(resident)) {
Map<Town, Double> townMap = new ConcurrentHashMap<>();
townMap.put(town, tax);
residentPlotTaxMap.put(resident, townMap);
return;
}

Map<Town, Double> townMap = residentPlotTaxMap.get(resident);
double amount = townMap.containsKey(town) ? townMap.get(town) + tax : tax;
townMap.put(town, amount);
residentPlotTaxMap.put(resident, townMap);
}

private void messageResidentsAboutPlotTaxesPaid() {
for (Resident resident : residentPlotTaxMap.keySet()) {
if (!resident.isOnline())
continue;
Map<Town, Double> townMap = residentPlotTaxMap.get(resident);
if (townMap.isEmpty())
continue;
for (Town townKey : townMap.keySet()) {
double tax = townMap.get(townKey);
TownyMessaging.sendMsg(resident, Translatable.of("msg_you_paid_plottax_to_town", prettyMoney(tax), townKey));
}
}
}

private void payPlotTaxToResidents(double tax, Resident resident, Town town, String typeName) {
if (!town.getAccount().canPayFromHoldings(tax))
return;
Expand Down
2 changes: 2 additions & 0 deletions Towny/src/main/resources/lang/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ msg_couldnt_pay_taxes: '&b%s couldn''t pay taxes and was kicked from the %s.'
msg_couldnt_pay_plot_taxes: '&b%s couldn''t pay taxes and lost ownership of a plot.'
msg_you_couldnt_pay_plot_tax: '&bYou couldn''t pay the plot tax of %s and lost ownership of the plot at %s.'
msg_you_couldnt_pay_town_tax: '&bYou couldn''t pay the town tax of %s and have been removed from %s.'
msg_you_paid_town_tax: '&bYou paid your town a tax of %s.'
msg_you_paid_plottax_to_town: '&bYou paid plot taxes totalling %s to the town of %s.'
msg_payed_town_tax: '&bPayed town tax of '
msg_payed_plot_cost: '&bPayed %s for %s plots in %s'
msg_payed_resident_tax: '&bPayed resident tax of '
Expand Down

0 comments on commit 6c08e3a

Please sign in to comment.