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 max tax amount for tax percent #3969

Merged
merged 7 commits into from
May 9, 2020
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
6 changes: 5 additions & 1 deletion resources/chinese.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Towny
version: 0.82
version: 0.83
language: Chinese
author: ElgarL
website: 'http://townyadvanced.github.io/'
Expand Down Expand Up @@ -1134,3 +1134,7 @@ confirmation_prefix: "&8[&7Confirmation&8] &9"
this_message_will_expire2: '&9This will auto-expire in 20 seconds'
msg_hover_next_page: 'Next Page'
msg_hover_previous_page: 'Previous Page'

# Added in 0.83
msg_max_tax_amount_only_for_percent: "Max tax amounts can only be set for towns with tax percentages."
msg_town_set_tax_max_percent_amount: "%s has set the max tax percent amount to %s."
6 changes: 5 additions & 1 deletion resources/english.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Towny
version: 0.82
version: 0.83
language: english
author: ElgarL
website: 'http://townyadvanced.github.io/'
Expand Down Expand Up @@ -1133,3 +1133,7 @@ confirmation_prefix: "&8[&7Confirmation&8] &9"
this_message_will_expire2: '&9This will auto-expire in 20 seconds'
msg_hover_next_page: 'Next Page'
msg_hover_previous_page: 'Previous Page'

# Added in 0.83
msg_max_tax_amount_only_for_percent: "Max tax amounts can only be set for towns with tax percentages."
msg_town_set_tax_max_percent_amount: "%s has set the max tax percent amount to %s."
6 changes: 5 additions & 1 deletion resources/es-mx.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Towny
version: 0.82
version: 0.83
language: español
author: VreyaViress
website: 'http://townyadvanced.github.io/'
Expand Down Expand Up @@ -1121,3 +1121,7 @@ confirmation_prefix: "&8[&7Confirmation&8] &9"
this_message_will_expire2: '&9This will auto-expire in 20 seconds'
msg_hover_next_page: 'Next Page'
msg_hover_previous_page: 'Previous Page'

# Added in 0.83
msg_max_tax_amount_only_for_percent: "Max tax amounts can only be set for towns with tax percentages."
msg_town_set_tax_max_percent_amount: "%s has set the max tax percent amount to %s."
6 changes: 5 additions & 1 deletion resources/french.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Towny
version: 0.82
version: 0.83
language: french
author: Noiknez,TheCalypso,Cidalex,Mitsu,ARNPIK
website: 'http://townyadvanced.github.io/'
Expand Down Expand Up @@ -1134,3 +1134,7 @@ confirmation_prefix: '&8[&7Confirmation&8] &9'
this_message_will_expire2: '&9Cela expirera automatiquement dans 20 secondes.'
msg_hover_next_page: 'Page Suivante'
msg_hover_previous_page: 'Page Précédente'

# Added in 0.83
msg_max_tax_amount_only_for_percent: "Max tax amounts can only be set for towns with tax percentages."
msg_town_set_tax_max_percent_amount: "%s has set the max tax percent amount to %s."
6 changes: 5 additions & 1 deletion resources/german.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Towny
version: 0.82
version: 0.83
language: german
author: 'ElgarL, translated by Articdive, Wolf2323, BlocK, Yasu-San and enterih'
website: 'http://townyadvanced.github.io/'
Expand Down Expand Up @@ -1136,3 +1136,7 @@ confirmation_prefix: "&8[&7Confirmation&8] &9"
this_message_will_expire2: '&9This will auto-expire in 20 seconds'
msg_hover_next_page: 'Next Page'
msg_hover_previous_page: 'Previous Page'

# Added in 0.83
msg_max_tax_amount_only_for_percent: "Max tax amounts can only be set for towns with tax percentages."
msg_town_set_tax_max_percent_amount: "%s has set the max tax percent amount to %s."
6 changes: 5 additions & 1 deletion resources/italian.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Towny
version: 0.82
version: 0.83
language: italian
author: Leomixer17
website: 'http://townyadvanced.github.io/'
Expand Down Expand Up @@ -1135,3 +1135,7 @@ confirmation_prefix: "&8[&7Confirmation&8] &9"
this_message_will_expire2: '&9This will auto-expire in 20 seconds'
msg_hover_next_page: 'Next Page'
msg_hover_previous_page: 'Previous Page'

# Added in 0.83
msg_max_tax_amount_only_for_percent: "Max tax amounts can only be set for towns with tax percentages."
msg_town_set_tax_max_percent_amount: "%s has set the max tax percent amount to %s."
6 changes: 5 additions & 1 deletion resources/korean.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Towny
version: 0.82
version: 0.83
language: 한국어
author: 'Daybreak 새벽'
website: 'http://townyadvanced.github.io/'
Expand Down Expand Up @@ -1046,3 +1046,7 @@ confirmation_prefix: "&8[&7Confirmation&8] &9"
this_message_will_expire2: '&9This will auto-expire in 20 seconds'
msg_hover_next_page: 'Next Page'
msg_hover_previous_page: 'Previous Page'

# Added in 0.83
msg_max_tax_amount_only_for_percent: "Max tax amounts can only be set for towns with tax percentages."
msg_town_set_tax_max_percent_amount: "%s has set the max tax percent amount to %s."
6 changes: 5 additions & 1 deletion resources/norwegian.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Towny
version: 0.82
version: 0.83
language: norwegian
author: Nectuz, Walbern
website: 'http://townyadvanced.github.io/'
Expand Down Expand Up @@ -1133,3 +1133,7 @@ confirmation_prefix: "&8[&7Confirmation&8] &9"
this_message_will_expire2: '&9This will auto-expire in 20 seconds'
msg_hover_next_page: 'Next Page'
msg_hover_previous_page: 'Previous Page'

# Added in 0.83
msg_max_tax_amount_only_for_percent: "Max tax amounts can only be set for towns with tax percentages."
msg_town_set_tax_max_percent_amount: "%s has set the max tax percent amount to %s."
1 change: 1 addition & 0 deletions resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ permissions:
towny.command.town.set.plottax: true
towny.command.town.set.shoptax: true
towny.command.town.set.embassytax: true
towny.command.town.set.taxpercentcap: true
towny.command.town.set.title: true
towny.command.town.set.surname: true

Expand Down
6 changes: 5 additions & 1 deletion resources/polish.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Towny
version: 0.82
version: 0.83
language: polish
author: Martinez
website: 'http://townyadvanced.github.io/'
Expand Down Expand Up @@ -1133,3 +1133,7 @@ confirmation_prefix: "&8[&7Confirmation&8] &9"
this_message_will_expire2: '&9This will auto-expire in 20 seconds'
msg_hover_next_page: 'Next Page'
msg_hover_previous_page: 'Previous Page'

# Added in 0.83
msg_max_tax_amount_only_for_percent: "Max tax amounts can only be set for towns with tax percentages."
msg_town_set_tax_max_percent_amount: "%s has set the max tax percent amount to %s."
6 changes: 5 additions & 1 deletion resources/pt-br.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Towny
version: 0.82
version: 0.83
language: português (Brasil)
author: BannerGames
website: 'http://townyadvanced.github.io/'
Expand Down Expand Up @@ -1137,3 +1137,7 @@ confirmation_prefix: "&8[&7Confirmação&8] &9"
this_message_will_expire2: '&9Irá espirar automaticamente em 20 segundos'
msg_hover_next_page: 'Próxima página'
msg_hover_previous_page: 'Página anterior'

# Added in 0.83
msg_max_tax_amount_only_for_percent: "Max tax amounts can only be set for towns with tax percentages."
msg_town_set_tax_max_percent_amount: "%s has set the max tax percent amount to %s."
6 changes: 5 additions & 1 deletion resources/russian.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Towny
version: 0.82
version: 0.83
language: russian
author: ElgarL (Plugin developer), Communar (Russian Translation)
website: 'http://townyadvanced.github.io/'
Expand Down Expand Up @@ -1133,3 +1133,7 @@ confirmation_prefix: "&8[&7Confirmation&8] &9"
this_message_will_expire2: '&9This will auto-expire in 20 seconds'
msg_hover_next_page: 'Next Page'
msg_hover_previous_page: 'Previous Page'

# Added in 0.83
msg_max_tax_amount_only_for_percent: "Max tax amounts can only be set for towns with tax percentages."
msg_town_set_tax_max_percent_amount: "%s has set the max tax percent amount to %s."
6 changes: 5 additions & 1 deletion resources/spanish.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Towny
version: 0.82
version: 0.83
language: spanish
author: Seruhio, Alvarote1998, Beelzebu
website: 'http://townyadvanced.github.io/'
Expand Down Expand Up @@ -1133,3 +1133,7 @@ confirmation_prefix: "&8[&7Confirmation&8] &9"
this_message_will_expire2: '&9This will auto-expire in 20 seconds'
msg_hover_next_page: 'Next Page'
msg_hover_previous_page: 'Previous Page'

# Added in 0.83
msg_max_tax_amount_only_for_percent: "Max tax amounts can only be set for towns with tax percentages."
msg_town_set_tax_max_percent_amount: "%s has set the max tax percent amount to %s."
6 changes: 5 additions & 1 deletion resources/zh-TW.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Towny
version: 0.82
version: 0.83
language: zh-TW
author: ElgarL
website: 'http://townyadvanced.github.io/'
Expand Down Expand Up @@ -1132,3 +1132,7 @@ confirmation_prefix: "&8[&7Confirmation&8] &9"
this_message_will_expire2: '&9This will auto-expire in 20 seconds'
msg_hover_next_page: 'Next Page'
msg_hover_previous_page: 'Previous Page'

# Added in 0.83
msg_max_tax_amount_only_for_percent: "Max tax amounts can only be set for towns with tax percentages."
msg_town_set_tax_max_percent_amount: "%s has set the max tax percent amount to %s."
7 changes: 6 additions & 1 deletion src/com/palmergames/bukkit/config/ConfigNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public enum ConfigNodes {
"# Default amount for town's plottax costs."),
TOWN_DEF_TAXES_TAXPERCENTAGE(
"town.default_taxes.taxpercentage",
"false",
"true",
"# Default status of new town's taxpercentage. True means that the default_tax is treated as a percentage instead of a fixed amount."),
TOWN_DEF_TAXES_MINIMUMTAX(
"town.default_taxes.minimumtax",
Expand Down Expand Up @@ -1387,6 +1387,11 @@ public enum ConfigNodes {
"economy.daily_taxes.max_town_tax_percent",
"25",
"# Maximum tax percentage allowed when taxing by percentages for towns."),
ECO_DAILY_TAXES_MAX_TOWN_TAX_PERCENT_AMOUNT(
"economy.daily_taxes.max_town_tax_percent_amount",
"10000",
"# The maximum amount of money that can be taken from a balance when using a percent tax, this is the default for all new towns."
),
ECO_PRICE_NATION_UPKEEP(
"economy.daily_taxes.price_nation_upkeep",
"100.0",
Expand Down
6 changes: 6 additions & 0 deletions src/com/palmergames/bukkit/towny/TownySettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -1683,9 +1683,15 @@ public static double getMaxPlotPrice() {
}

public static double getMaxTownTaxPercent() {

return getDouble(ConfigNodes.ECO_DAILY_TAXES_MAX_TOWN_TAX_PERCENT);
}

public static double getMaxTownTaxPercentAmount() {

return getDouble(ConfigNodes.ECO_DAILY_TAXES_MAX_TOWN_TAX_PERCENT_AMOUNT);
}

public static boolean isBackingUpDaily() {

return getBoolean(ConfigNodes.PLUGIN_DAILY_BACKUPS);
Expand Down
23 changes: 22 additions & 1 deletion src/com/palmergames/bukkit/towny/command/TownCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public class TownCommand extends BaseCommand implements CommandExecutor, TabComp
"embassyprice",
"embassytax",
"title",
"surname"
"surname",
"taxpercentcap"
);

static final List<String> townToggleTabCompletes = Arrays.asList(
Expand Down Expand Up @@ -1799,6 +1800,7 @@ public static void townSet(Player player, String[] split, boolean admin, Town to
player.sendMessage(ChatTools.formatCommand("", "/town set", "name [name]", ""));
player.sendMessage(ChatTools.formatCommand("", "/town set", "tag [upto 4 letters] or clear", ""));
player.sendMessage(ChatTools.formatCommand("", "/town set", "title/surname [resident] [text]", ""));
player.sendMessage(ChatTools.formatCommand("", "/town set", "taxpercentcap [amount]", ""));
} else {
Resident resident;

Expand Down Expand Up @@ -1873,6 +1875,25 @@ public static void townSet(Player player, String[] split, boolean admin, Town to
else
TownyMessaging.sendPrefixedTownMessage(town, String.format(TownySettings.getLangString("msg_clear_title_surname"), "Title", resident.getName()));

} else if (split[0].equalsIgnoreCase("taxpercentcap")) {
if (!townyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWN_SET_TAXPERCENTCAP.getNode()))
throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));

if (!town.isTaxPercentage()) {
// msg_max_tax_amount_only_for_percent
throw new TownyException(TownySettings.getLangString("msg_max_tax_amount_only_for_percent"));
}

if (split.length < 2) {
TownyMessaging.sendErrorMsg("Eg. /town set taxMax 10000");
return;
}

double amount = Double.parseDouble(split[1]);
town.setMaxPercentTaxAmount(amount);

TownyMessaging.sendPrefixedTownMessage(town, String.format(TownySettings.getLangString("msg_town_set_tax_max_percent_amount"), player.getName(), TownyEconomyHandler.getFormattedBalance(town.getMaxPercentTaxAmount())));

} else if (split[0].equalsIgnoreCase("surname")) {

if (!townyUniverse.getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWN_SET_SURNAME.getNode()))
Expand Down
11 changes: 10 additions & 1 deletion src/com/palmergames/bukkit/towny/object/Town.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class Town extends TownyObject implements ResidentList, TownyInviter, Obj
private double commercialPlotTax = TownySettings.getTownDefaultShopTax();
private double plotPrice = 0.0;
private double embassyPlotTax = TownySettings.getTownDefaultEmbassyTax();
private double maxPercentTaxAmount = TownySettings.getMaxTownTaxPercentAmount();
private double commercialPlotPrice, embassyPlotPrice, spawnCost;
private Nation nation;
private boolean hasUpkeep = true;
Expand Down Expand Up @@ -1452,6 +1453,15 @@ public String getFormattedName() {
return TownySettings.getTownPrefix(this) + this.getName().replaceAll("_", " ") + TownySettings.getTownPostfix(this);
}

public double getMaxPercentTaxAmount() {
return maxPercentTaxAmount;
}

public void setMaxPercentTaxAmount(double maxPercentTaxAmount) {
// Max tax amount cannot go over amount defined in config.
this.maxPercentTaxAmount = Math.min(maxPercentTaxAmount, TownySettings.getMaxTownTaxPercentAmount());
}

/**
* @deprecated As of 0.97.0.0+ please use {@link EconomyAccount#getWorld()} instead.
*
Expand Down Expand Up @@ -1529,5 +1539,4 @@ public boolean collect(double amount, String reason) throws EconomyException {
public TownyWorld getWorld() {
return getHomeblockWorld();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public enum PermissionNodes {
TOWNY_COMMAND_TOWN_SET_JAIL("towny.command.town.set.jail"),
TOWNY_COMMAND_TOWN_SET_TITLE("towny.command.town.set.title"),
TOWNY_COMMAND_TOWN_SET_SURNAME("towny.command.town.set.surname"),
TOWNY_COMMAND_TOWN_SET_TAXPERCENTCAP("towny.command.town.set.taxpercentcap"),

TOWNY_COMMAND_TOWN_BUY("towny.command.town.buy"),
TOWNY_COMMAND_TOWN_JAIL("towny.command.town.jail"),
Expand Down
5 changes: 5 additions & 0 deletions src/com/palmergames/bukkit/towny/tasks/DailyTimerTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ protected void collectTownTaxes(Town town) throws EconomyException {
continue;
} else if (town.isTaxPercentage()) {
double cost = resident.getAccount().getHoldingBalance() * town.getTaxes() / 100;

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

resident.getAccount().payTo(cost, town, "Town Tax (Percentage)");
} else if (!resident.getAccount().payTo(town.getTaxes(), town, "Town Tax")) {
removedResidents.add(resident.getName());
Expand Down