diff --git a/pom.xml b/pom.xml index 5a4e0cc..a80ac9d 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ quicktax quicktax - 1.4.0 + 1.4.1 QuickTax diff --git a/src/main/java/tk/taverncraft/quicktax/utils/TaxManager.java b/src/main/java/tk/taverncraft/quicktax/utils/TaxManager.java index 8010007..7b9f2c1 100644 --- a/src/main/java/tk/taverncraft/quicktax/utils/TaxManager.java +++ b/src/main/java/tk/taverncraft/quicktax/utils/TaxManager.java @@ -25,6 +25,14 @@ public class TaxManager { public static boolean isCollecting; 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. */ @@ -51,6 +59,13 @@ public class TaxManager { } 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)) { MessageManager.sendMessage(sender, "tax-collect-success-individual", new String[]{"%player%"}, @@ -60,6 +75,7 @@ public class TaxManager { new String[]{"%player%"}, new String[]{name}); } + if (validationManager.doStoreData(null)) { this.main.getStatsManager().updateServerStats(this.totalTaxCollected, true); } @@ -88,7 +104,12 @@ public class TaxManager { } 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"); if (validationManager.doStoreData(null)) { this.main.getStatsManager().updateServerStats(this.totalTaxCollected, true); @@ -118,6 +139,9 @@ public class TaxManager { Arrays.stream(this.main.getServer().getOfflinePlayers()) .forEach(offlinePlayer -> { + if (isTaxExempt(offlinePlayer, exemptCollectRankPerm)) { + return; + } for (String rank : ranks.getKeys(true)) { String[] playerGroups = Main.getPermissions().getPlayerGroups(Bukkit.getWorlds().get(0).getName(), offlinePlayer); if (Arrays.stream(playerGroups).anyMatch(rank::equalsIgnoreCase)) { @@ -169,6 +193,9 @@ public class TaxManager { Arrays.stream(this.main.getServer().getOfflinePlayers()) .forEach(offlinePlayer -> { + if (isTaxExempt(offlinePlayer, exemptCollectBalPerm)) { + return; + } for (int bal : intList) { if (offlinePlayer.getName() == null) { continue; @@ -221,6 +248,9 @@ public class TaxManager { Arrays.stream(this.main.getServer().getOfflinePlayers()) .forEach(offlinePlayer -> { + if (isTaxExempt(offlinePlayer, exemptCollectActivityPerm)) { + return; + } for (long lastSeen : longList) { if (offlinePlayer.getName() == null) { continue; @@ -401,6 +431,17 @@ public class TaxManager { 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. * diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1916d29..b06987e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -13,6 +13,15 @@ enable-sound: true # list of supported sound: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html 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 # diff --git a/src/main/resources/en.yml b/src/main/resources/en.yml index 50d9703..887da7a 100644 --- a/src/main/resources/en.yml +++ b/src/main/resources/en.yml @@ -29,6 +29,7 @@ tax-withdraw-success: '&aBalance withdrawn successfully!' tax-withdraw-fail: '&cThere is insufficient server tax balance!' 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-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-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%