From c07c0974fc4b0b3e3e926d344f0c9eac437af626 Mon Sep 17 00:00:00 2001 From: Magnus Ulf Date: Thu, 24 Jan 2019 19:23:31 +0100 Subject: [PATCH] Yet another econ fix Yes, I am not doing that well --- .../massivecore/money/MoneyMixinVault.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/com/massivecraft/massivecore/money/MoneyMixinVault.java b/src/com/massivecraft/massivecore/money/MoneyMixinVault.java index c29ae5e2..bb6a4f29 100644 --- a/src/com/massivecraft/massivecore/money/MoneyMixinVault.java +++ b/src/com/massivecraft/massivecore/money/MoneyMixinVault.java @@ -3,6 +3,7 @@ package com.massivecraft.massivecore.money; import com.massivecraft.massivecore.util.IdUtil; import com.massivecraft.massivecore.util.MUtil; import net.milkbowl.vault.economy.Economy; +import net.milkbowl.vault.economy.EconomyResponse; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.plugin.RegisteredServiceProvider; @@ -180,9 +181,14 @@ public class MoneyMixinVault extends MoneyMixinAbstract toId = temp; } - OfflinePlayer offlinePlayerFrom = IdUtil.getOfflinePlayer(fromId); - OfflinePlayer offlinePlayerTo = IdUtil.getOfflinePlayer(toId); - + Object objectFrom = getEconomyObject(fromId); + OfflinePlayer opFrom = objectFrom instanceof OfflinePlayer ? (OfflinePlayer) objectFrom : null; + String nameFrom = objectFrom instanceof String ? (String) objectFrom : null; + + Object objectTo = getEconomyObject(toId); + OfflinePlayer opTo = objectTo instanceof OfflinePlayer ? (OfflinePlayer) objectTo : null; + String nameTo = objectTo instanceof String ? (String) objectTo : null; + // Ensure the accounts exist if (fromId != null) this.ensureExists(fromId); if (toId != null) this.ensureExists(toId); @@ -190,7 +196,8 @@ public class MoneyMixinVault extends MoneyMixinAbstract // Subtract From if (fromId != null) { - if (!economy.withdrawPlayer(offlinePlayerFrom, amount).transactionSuccess()) + EconomyResponse response = opTo != null ? economy.withdrawPlayer(opFrom, amount) : economy.withdrawPlayer(nameFrom, amount); + if (!response.transactionSuccess()) { return false; } @@ -199,12 +206,15 @@ public class MoneyMixinVault extends MoneyMixinAbstract // Add To if (toId != null) { - if (!economy.depositPlayer(offlinePlayerTo, amount).transactionSuccess()) + EconomyResponse response = opTo != null ? economy.depositPlayer(opTo, amount) : economy.depositPlayer(nameTo, amount); + if (!response.transactionSuccess()) { if (fromId != null) { // Undo the withdraw - economy.depositPlayer(offlinePlayerFrom, amount); + if (opFrom != null) economy.depositPlayer(opFrom, amount); + if (nameFrom != null) economy.depositPlayer(nameFrom, amount); + throw new RuntimeException(); } return false; }