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

Hotfix/bankcaps affect taxes #4366

Merged
merged 4 commits into from
Oct 23, 2020
Merged
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
54 changes: 37 additions & 17 deletions src/com/palmergames/bukkit/towny/tasks/DailyTimerTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ protected void collectTownTaxes(Town town) throws EconomyException {
while (residentItr.hasNext()) {
resident = residentItr.next();

double tax = town.getTaxes();
/*
* Only collect resident tax from this resident if it really
* still exists. We are running in an Async thread so MUST
Expand All @@ -335,18 +336,34 @@ protected void collectTownTaxes(Town town) throws EconomyException {
}
continue;
} else if (town.isTaxPercentage()) {
double cost = resident.getAccount().getHoldingBalance() * town.getTaxes() / 100;
tax = resident.getAccount().getHoldingBalance() * tax / 100;

// Make sure that the town percent tax doesn't remove above the
// allotted amount of cash.
cost = Math.min(cost, town.getMaxPercentTaxAmount());
tax = Math.min(tax, town.getMaxPercentTaxAmount());

// Handle if the bank cannot be paid because of the cap. Since it is a %
// they will be able to pay but it might be more than the bank can accept,
// so we reduce it to the amount that the bank can accept, even if it
// becomes 0.
if (tax + town.getAccount().getHoldingBalance() > TownySettings.getTownBankCap())
tax = town.getAccount().getBalanceCap() - town.getAccount().getHoldingBalance();

resident.getAccount().payTo(cost, town, "Town Tax (Percentage)");
} else if (!resident.getAccount().payTo(town.getTaxes(), town, "Town Tax")) {
removedResidents.add(resident.getName());
resident.getAccount().payTo(tax, town, "Town Tax (Percentage)");
} else {
// Check if the bank could take the money, reduce it to 0 if required so that
// players do not get kicked in a situation they could be paying but cannot because
// of the bank cap.
if (tax + town.getAccount().getHoldingBalance() > TownySettings.getTownBankCap())
tax = town.getAccount().getBalanceCap() - town.getAccount().getHoldingBalance();

// remove this resident from the town.
resident.removeTown();
if (resident.getAccount().canPayFromHoldings(tax))
resident.getAccount().payTo(tax, town, "Town tax (FlatRate)");
else {
removedResidents.add(resident.getName());
// remove this resident from the town.
resident.removeTown();
}
}
}
}
Expand Down Expand Up @@ -380,22 +397,25 @@ protected void collectTownTaxes(Town town) throws EconomyException {
* verify all objects.
*/
if (universe.getDataSource().hasResident(resident.getName())) {
if (resident.hasTown())
if (resident.getTown() == townBlock.getTown())
if (TownyPerms.getResidentPerms(resident).containsKey("towny.tax_exempt") || resident.isNPC())
continue;

if (!resident.getAccount().payTo(townBlock.getType().getTax(town), town, String.format("Plot Tax (%s)", townBlock.getType()))) {
if (resident.hasTown() && resident.getTown() == townBlock.getTown())
if (TownyPerms.getResidentPerms(resident).containsKey("towny.tax_exempt") || resident.isNPC())
continue;

double tax = townBlock.getType().getTax(town);

// If the tax would put the town over the bank cap we reduce what will be
// paid by the plot owner to what will be allowed.
if (tax + town.getAccount().getHoldingBalance() > TownySettings.getTownBankCap())
tax = town.getAccount().getBalanceCap() - town.getAccount().getHoldingBalance();

if (!resident.getAccount().payTo(tax, town, String.format("Plot Tax (%s)", townBlock.getType()))) {
if (!lostPlots.contains(resident.getName()))
lostPlots.add(resident.getName());
lostPlots.add(resident.getName());

townBlock.setResident(null);
townBlock.setPlotPrice(-1);

// Set the plot permissions to mirror the towns.
townBlock.setType(townBlock.getType());

universe.getDataSource().saveResident(resident);
universe.getDataSource().saveTownBlock(townBlock);
}
}
Expand Down