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

Add messages to residents when they pay town and plot taxes. #7659

Merged
merged 2 commits into from
Nov 5, 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
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
5 changes: 2 additions & 3 deletions Towny/src/main/resources/lang/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +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_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 '
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_bankrupt_town: ' couldn''t afford to remain a town.'
msg_bankrupt_nation: ' couldn''t afford to remain a nation.'
msg_nation_not_peaceful: '&bNation couldn''t afford it''s peaceful state.'
Expand Down
Loading