feat: Add support for tax exemptions via permission nodes

This commit is contained in:
tjtanjin 2023-12-02 23:52:07 +08:00
parent 401879c318
commit f189eb8f04
4 changed files with 53 additions and 2 deletions

View File

@ -7,7 +7,7 @@
<groupId>quicktax</groupId> <groupId>quicktax</groupId>
<artifactId>quicktax</artifactId> <artifactId>quicktax</artifactId>
<version>1.4.0</version> <version>1.4.1</version>
<name>QuickTax</name> <name>QuickTax</name>

View File

@ -25,6 +25,14 @@ public class TaxManager {
public static boolean isCollecting; public static boolean isCollecting;
public static Runnable task; public static Runnable task;
// permission nodes for tax exemptions
private final String exemptFullPerm = "quicktax.exempt.*";
private final String exemptCollectNamePerm = "quicktax.exempt.collectname";
private final String exemptCollectAllPerm = "quicktax.exempt.collectall";
private final String exemptCollectBalPerm = "quicktax.exempt.collectbal";
private final String exemptCollectRankPerm = "quicktax.exempt.collectrank";
private final String exemptCollectActivityPerm = "quicktax.exempt.collectactivity";
/** /**
* Constructor for TaxManager. * Constructor for TaxManager.
*/ */
@ -51,6 +59,13 @@ public class TaxManager {
} }
OfflinePlayer player = this.main.getServer().getOfflinePlayer(name); OfflinePlayer player = this.main.getServer().getOfflinePlayer(name);
if (isTaxExempt(player, exemptCollectNamePerm)) {
MessageManager.sendMessage(sender, "tax-exempt",
new String[]{"%player%"},
new String[]{name});
return;
}
if (func.updatePlayer(player, Double.parseDouble(amount), 0.0, false)) { if (func.updatePlayer(player, Double.parseDouble(amount), 0.0, false)) {
MessageManager.sendMessage(sender, "tax-collect-success-individual", MessageManager.sendMessage(sender, "tax-collect-success-individual",
new String[]{"%player%"}, new String[]{"%player%"},
@ -60,6 +75,7 @@ public class TaxManager {
new String[]{"%player%"}, new String[]{"%player%"},
new String[]{name}); new String[]{name});
} }
if (validationManager.doStoreData(null)) { if (validationManager.doStoreData(null)) {
this.main.getStatsManager().updateServerStats(this.totalTaxCollected, true); this.main.getStatsManager().updateServerStats(this.totalTaxCollected, true);
} }
@ -88,7 +104,12 @@ public class TaxManager {
} }
Arrays.stream(this.main.getServer().getOfflinePlayers()) Arrays.stream(this.main.getServer().getOfflinePlayers())
.forEach(offlinePlayer -> func.updatePlayer(offlinePlayer, balTaxAmount, claimsTaxAmount, usePercentage)); .forEach(offlinePlayer -> {
if (isTaxExempt(offlinePlayer, exemptCollectAllPerm)) {
return;
}
func.updatePlayer(offlinePlayer, balTaxAmount, claimsTaxAmount, usePercentage);
});
MessageManager.sendMessage(sender, "tax-collect-success-all"); MessageManager.sendMessage(sender, "tax-collect-success-all");
if (validationManager.doStoreData(null)) { if (validationManager.doStoreData(null)) {
this.main.getStatsManager().updateServerStats(this.totalTaxCollected, true); this.main.getStatsManager().updateServerStats(this.totalTaxCollected, true);
@ -118,6 +139,9 @@ public class TaxManager {
Arrays.stream(this.main.getServer().getOfflinePlayers()) Arrays.stream(this.main.getServer().getOfflinePlayers())
.forEach(offlinePlayer -> { .forEach(offlinePlayer -> {
if (isTaxExempt(offlinePlayer, exemptCollectRankPerm)) {
return;
}
for (String rank : ranks.getKeys(true)) { for (String rank : ranks.getKeys(true)) {
String[] playerGroups = Main.getPermissions().getPlayerGroups(Bukkit.getWorlds().get(0).getName(), offlinePlayer); String[] playerGroups = Main.getPermissions().getPlayerGroups(Bukkit.getWorlds().get(0).getName(), offlinePlayer);
if (Arrays.stream(playerGroups).anyMatch(rank::equalsIgnoreCase)) { if (Arrays.stream(playerGroups).anyMatch(rank::equalsIgnoreCase)) {
@ -169,6 +193,9 @@ public class TaxManager {
Arrays.stream(this.main.getServer().getOfflinePlayers()) Arrays.stream(this.main.getServer().getOfflinePlayers())
.forEach(offlinePlayer -> { .forEach(offlinePlayer -> {
if (isTaxExempt(offlinePlayer, exemptCollectBalPerm)) {
return;
}
for (int bal : intList) { for (int bal : intList) {
if (offlinePlayer.getName() == null) { if (offlinePlayer.getName() == null) {
continue; continue;
@ -221,6 +248,9 @@ public class TaxManager {
Arrays.stream(this.main.getServer().getOfflinePlayers()) Arrays.stream(this.main.getServer().getOfflinePlayers())
.forEach(offlinePlayer -> { .forEach(offlinePlayer -> {
if (isTaxExempt(offlinePlayer, exemptCollectActivityPerm)) {
return;
}
for (long lastSeen : longList) { for (long lastSeen : longList) {
if (offlinePlayer.getName() == null) { if (offlinePlayer.getName() == null) {
continue; continue;
@ -401,6 +431,17 @@ public class TaxManager {
return true; return true;
} }
/**
* Checks if a player is exempted from tax.
*
* @param player player to check
* @param permissionNode permission node used to determine if player is exempt
*/
private boolean isTaxExempt(OfflinePlayer player, String permissionNode) {
return Main.getPermissions().playerHas(Bukkit.getWorlds().get(0).getName(), player, exemptFullPerm)
|| Main.getPermissions().playerHas(Bukkit.getWorlds().get(0).getName(), player, permissionNode);
}
/** /**
* Interface to determine what type of update to run. * Interface to determine what type of update to run.
* *

View File

@ -13,6 +13,15 @@ enable-sound: true
# list of supported sound: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html # list of supported sound: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html
play-sound: ENTITY_PLAYER_LEVELUP play-sound: ENTITY_PLAYER_LEVELUP
# note: tax exemptions can be done via the following 6 permission nodes:
# quicktax.exempt.*
# quicktax.exempt.collectname
# quicktax.exempt.collectall
# quicktax.exempt.collectbal
# quicktax.exempt.collectrank
# quicktax.exempt.collectactivity
# more information here: https://github.com/tjtanjin/QuickTax/wiki/Tutorial#commands--permissions
##################################################################################### #####################################################################################
# # # #
# Leaderboard Configurations # # Leaderboard Configurations #

View File

@ -29,6 +29,7 @@ tax-withdraw-success: '&aBalance withdrawn successfully!'
tax-withdraw-fail: '&cThere is insufficient server tax balance!' tax-withdraw-fail: '&cThere is insufficient server tax balance!'
tax-collect-fail-individual: '&b%player% &chas no money to pay tax!' # %player% tax-collect-fail-individual: '&b%player% &chas no money to pay tax!' # %player%
tax-collect-already-running: '&cAn existing tax collection is ongoing, please try again later!' tax-collect-already-running: '&cAn existing tax collection is ongoing, please try again later!'
tax-exempt: '&cThe player &b%player% &cis exempted from your tax collection!'
player-pay-tax-fail: '&cYou have insufficient balance to pay tax!' # %player% player-pay-tax-fail: '&cYou have insufficient balance to pay tax!' # %player%
player-pay-tax-success: '&aTax was collected from you and you have paid $%amount%!' # %player%, %amount% player-pay-tax-success: '&aTax was collected from you and you have paid $%amount%!' # %player%, %amount%
player-receive-tax-money: '&aYou received $%amount% from the server tax balance!' # %amount% player-receive-tax-money: '&aYou received $%amount% from the server tax balance!' # %amount%