Browse Source

Added global bank account option to take the money from

This option allows server owners to define an economy bank account that
provides the money for all withdraws. This would mean that no new money
is created.

Closes #52
MasterCake 4 years ago
parent
commit
f26b57fad3

+ 12 - 0
Plugin/src/main/java/de/Linus122/TimeIsMoney/Main.java

@@ -2,6 +2,8 @@ package de.Linus122.TimeIsMoney;
 
 import com.earth2me.essentials.Essentials;
 import de.Linus122.TimeIsMoney.tools.ActionBarUtils;
+import net.milkbowl.vault.economy.EconomyResponse;
+import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
 
 import org.bukkit.Bukkit;
 import org.bukkit.Location;
@@ -413,6 +415,16 @@ public class Main extends JavaPlugin {
 		
 		//DEPOSIT
 		double payout_amt = afk ? payout.payout_amount * (afkPercent / 100) : payout.payout_amount;
+		
+		// Take money from bank
+		if (finalconfig.getString("bank-account").length() > 0) {
+			EconomyResponse response = economy.bankWithdraw(finalconfig.getString("bank-account"), payout_amt);
+			if(response.type == ResponseType.FAILURE) {
+				System.out.println("§cFailed to take money from bank account: " + finalconfig.getString("bank-account") + " amount " + payout_amt);
+				return;
+			}
+		}
+		
 		if (finalconfig.getBoolean("store-money-in-bank")) {
 			ATM.depositBank(p, payout_amt);
 		} else {

+ 3 - 0
Plugin/src/main/resources/config.yml

@@ -23,6 +23,9 @@ allow-multiple-accounts: true
 # Option to increase the maximal amount of players of the same IP getting a payout. Only applies when allow-multiple-accounts is set to false.
 max-multiple-accounts: 1
 
+# Optional: Define a server bank account for withdrawing money from that account for the payouts instead of creating money out of nowhere
+bank-account: ""
+
 # Payouts will be delivered by "chance" instead "permission".
 choose-payout-by-chance: false