From 6737a4f789be87a5843d40a4cb6d21b4a7649125 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Wed, 19 Apr 2023 19:00:02 +0200 Subject: [PATCH] Adds the missing taxAccounts option --- README.md | 36 +++++++++---------- pom.xml | 2 +- .../stargate/config/ConfigOption.java | 5 +++ .../stargate/config/EconomyConfig.java | 9 +++++ .../stargate/config/StargateConfig.java | 3 +- .../stargate/utility/EconomyHelper.java | 32 ++++++++++++++++- src/main/resources/config-migrations.txt | 3 +- 7 files changed, 68 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 1c2db98..f1b0258 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ file; see the LICENSE file for more information. This plugin should be fully compatible all known versions StarGate forks, with the following exceptions:
-- Any version from outside of the bukkit ecosystem +- Any version from outside the bukkit ecosystem - Any version of SGR (version numbers 1.0.0.0+) - Any configurations with outdated material names (i.e. numIDs) @@ -173,12 +173,12 @@ Note that colour characters (if enabled) are not counted towards the character l - You can specify (and create) your own network on the third line of the sign when making a new gate. - Gates on one network will not see gates on the second network, and vice versa. - Gates on different worlds, but in the same network, will see each other. -- Notwithstanding the above, the network for bUngee gates will always be name of its destination /server +- Notwithstanding the above, the network for BungeeCord gates will always be the name of its destination /server #### Fixed gates: - Fixed gates go to only one set destination. -- Fixed gates can be linked to other fixed gates, or normal gates. A normal gate cannot open a portal to a fixed gate +- Fixed gates can be linked to other fixed gates, or normal gates. A normal gate cannot open a portal to a fixed gate, however. - To create a fixed gate, specify a destination on the second line of the stargate sign. - Set the 4th line of the stargate sign to `A` to enable an always-open fixed gate. @@ -204,8 +204,8 @@ Note that colour characters (if enabled) are not counted towards the character l ## Using a gate: -- Right click the sign to choose a destination (not needed for Fixed gates, undefined gates). -- Right click the activator to open up a portal. +- Right-click the sign to choose a destination (not needed for Fixed gates, undefined gates). +- Right-click the activator to open up a portal. - Step through. ## Custom Gate Layouts @@ -225,11 +225,11 @@ destroycost=0 toowner=false X=OBSIDIAN -=OBSIDIAN -XX + XX X..X -..- X*.X -XX + XX ``` ### Keys @@ -324,11 +324,11 @@ will appear in your world, with every character representing a block. ``` X=OBSIDIAN -=OBSIDIAN -XX + XX X..X -..- X*.X -XX + XX ``` This example is a standard nether portal. @@ -349,18 +349,18 @@ Other special characters include the following: Gates may be constructed underwater in much the same manner as they may be constructed above the surface.
There are, however, a few considerations for underwater portals: -```properties +``` portal-open=KELP_PLANT portal-closed=WATER button=BRAIN_CORAL_WALL_FAN toowner=false X=SEA_LANTERN -=SEA_LANTERN -XX + XX X..X -..- X*.X -XX + XX ``` - Buttons can not be waterlogged, and as such, are not ideal: wall coral fans are an ideal substitute. @@ -379,7 +379,7 @@ as `OBSIDIAN`); they may also use [tags](https://hub.spigotmc.org/javadocs/spigo as `#WOOL`).
Note that all tags must be prefaced with a hashtag (`#`), as in `#WOOL`. -```properties +``` portal-open=WATER portal-closed=AIR X=#WOOL @@ -403,11 +403,11 @@ toowner=false X=OBSIDIAN -=GLOWSTONE A=GLOWSTONE -XAX + XAX X...X -...- X.*.X -XAX + XAX ``` # Configuration @@ -674,9 +674,9 @@ found [here](https://github.com/stargate-rewritten/Stargate-Bukkit/blob/legacy/R #### \[Version 0.9.0.5] EpicKnarvik97 fork - Adds configuration toggles for: - - Whether or not living non-player entities may be teleported. - - Whether or not vehicles may teleport without a player riding them. - - Whether or not vehicles may teleport living non-player entities if accompanied by a player rider. + - Whether living non-player entities may be teleported. + - Whether vehicles may teleport without a player riding them. + - Whether vehicles may teleport living non-player entities if accompanied by a player rider. - Fixes a bug that could result in unauthorised teleportation. - Fixes a bug that, in certain circumstances, could result in chat spam. diff --git a/pom.xml b/pom.xml index 4869d0c..de1c04b 100644 --- a/pom.xml +++ b/pom.xml @@ -113,7 +113,7 @@ org.apache.maven.plugins maven-shade-plugin 3.4.1 - + false diff --git a/src/main/java/net/knarcraft/stargate/config/ConfigOption.java b/src/main/java/net/knarcraft/stargate/config/ConfigOption.java index e12ea59..1747bae 100644 --- a/src/main/java/net/knarcraft/stargate/config/ConfigOption.java +++ b/src/main/java/net/knarcraft/stargate/config/ConfigOption.java @@ -150,6 +150,11 @@ public enum ConfigOption { CHARGE_FREE_DESTINATION("economy.chargeFreeDestination", "Whether to require payment if the destination is free, but the entrance stargate is not", true), + /** + * The account to transfer all paid fees to + */ + TAX_ACCOUNT("economy.taxAccount", "The UUID of the account all fees are paid to (except for money to the Stargate owner)", ""), + /** * Whether to mark free gates with a different color */ diff --git a/src/main/java/net/knarcraft/stargate/config/EconomyConfig.java b/src/main/java/net/knarcraft/stargate/config/EconomyConfig.java index 1b8400c..b3b5d34 100644 --- a/src/main/java/net/knarcraft/stargate/config/EconomyConfig.java +++ b/src/main/java/net/knarcraft/stargate/config/EconomyConfig.java @@ -132,6 +132,15 @@ public final class EconomyConfig { return (Integer) configOptions.get(ConfigOption.DESTROY_COST); } + /** + * Gets the account all taxes are paid to + * + * @return

The account all taxes are paid to

+ */ + public String getTaxAccount() { + return (String) configOptions.get(ConfigOption.TAX_ACCOUNT); + } + /** * Checks whether the given player can afford the given fee * diff --git a/src/main/java/net/knarcraft/stargate/config/StargateConfig.java b/src/main/java/net/knarcraft/stargate/config/StargateConfig.java index f03b852..99b0096 100644 --- a/src/main/java/net/knarcraft/stargate/config/StargateConfig.java +++ b/src/main/java/net/knarcraft/stargate/config/StargateConfig.java @@ -364,7 +364,8 @@ public final class StargateConfig { FileConfiguration newConfig = Stargate.getInstance().getConfig(); boolean isMigrating = false; - if (newConfig.getString("lang") != null || newConfig.getString("economy.freeGatesGreen") != null) { + if (newConfig.getString("lang") != null || newConfig.getString("economy.freeGatesGreen") != null || + newConfig.getString("economy.taxAccount") == null) { migrateConfig(newConfig); isMigrating = true; } diff --git a/src/main/java/net/knarcraft/stargate/utility/EconomyHelper.java b/src/main/java/net/knarcraft/stargate/utility/EconomyHelper.java index 6c58e52..4c725ae 100644 --- a/src/main/java/net/knarcraft/stargate/utility/EconomyHelper.java +++ b/src/main/java/net/knarcraft/stargate/utility/EconomyHelper.java @@ -7,6 +7,7 @@ import net.knarcraft.stargate.portal.Portal; import net.knarcraft.stargate.portal.property.PortalOwner; import net.milkbowl.vault.economy.Economy; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import java.util.UUID; @@ -186,6 +187,28 @@ public final class EconomyHelper { return true; } + /** + * Transfers the given fees to the tax account + * + * @param economy

The economy to use

+ * @param cost

The cost to transfer

+ */ + @SuppressWarnings("deprecation") + private static void transferFees(Economy economy, int cost) { + String accountName = Stargate.getEconomyConfig().getTaxAccount(); + if (accountName == null || accountName.isEmpty()) { + return; + } + + try { + UUID accountId = UUID.fromString(accountName); + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(accountId); + economy.depositPlayer(offlinePlayer, cost); + } catch (IllegalArgumentException exception) { + economy.depositPlayer(accountName, cost); + } + } + /** * Charges the player for an action, if required * @@ -198,7 +221,14 @@ public final class EconomyHelper { return true; } //Charge player - return chargePlayer(player, cost); + boolean charged = chargePlayer(player, cost); + + // Transfer the charged amount to the tax account + if (charged) { + transferFees(Stargate.getEconomyConfig().getEconomy(), cost); + } + + return charged; } /** diff --git a/src/main/resources/config-migrations.txt b/src/main/resources/config-migrations.txt index cad71cb..b898212 100644 --- a/src/main/resources/config-migrations.txt +++ b/src/main/resources/config-migrations.txt @@ -46,5 +46,6 @@ portal-open= portal-closed= cost-type= cost-to-activate= -taxaccount=taxAccount +taxAccount=economy.taxAccount +taxaccount=economy.taxAccount usevault= \ No newline at end of file