Adds the missing taxAccounts option
This commit is contained in:
		@@ -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
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -132,6 +132,15 @@ public final class EconomyConfig {
 | 
			
		||||
        return (Integer) configOptions.get(ConfigOption.DESTROY_COST);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the account all taxes are paid to
 | 
			
		||||
     *
 | 
			
		||||
     * @return <p>The account all taxes are paid to</p>
 | 
			
		||||
     */
 | 
			
		||||
    public String getTaxAccount() {
 | 
			
		||||
        return (String) configOptions.get(ConfigOption.TAX_ACCOUNT);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Checks whether the given player can afford the given fee
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -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 <p>The economy to use</p>
 | 
			
		||||
     * @param cost    <p>The cost to transfer</p>
 | 
			
		||||
     */
 | 
			
		||||
    @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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -46,5 +46,6 @@ portal-open=
 | 
			
		||||
portal-closed=
 | 
			
		||||
cost-type=
 | 
			
		||||
cost-to-activate=
 | 
			
		||||
taxaccount=taxAccount
 | 
			
		||||
taxAccount=economy.taxAccount
 | 
			
		||||
taxaccount=economy.taxAccount
 | 
			
		||||
usevault=
 | 
			
		||||
		Reference in New Issue
	
	Block a user