From d3524faae91b75981c28a64d3940f80e22b8f0c0 Mon Sep 17 00:00:00 2001 From: Acrobot Date: Fri, 1 Feb 2013 19:28:42 +0100 Subject: [PATCH] Optimized the transaction module --- com/Acrobot/ChestShop/Economy/Economy.java | 4 ++++ com/Acrobot/ChestShop/Economy/EconomyManager.java | 4 ++++ com/Acrobot/ChestShop/Economy/Register.java | 4 ++++ com/Acrobot/ChestShop/Economy/Vault.java | 4 ++++ .../PreTransaction/PartialTransactionModule.java | 12 +++++++----- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/com/Acrobot/ChestShop/Economy/Economy.java b/com/Acrobot/ChestShop/Economy/Economy.java index cdebfb1..5e4e759 100644 --- a/com/Acrobot/ChestShop/Economy/Economy.java +++ b/com/Acrobot/ChestShop/Economy/Economy.java @@ -15,6 +15,10 @@ import static com.Acrobot.Breeze.Utils.NumberUtil.roundUp; public class Economy { private static EconomyManager manager = new EconomyManager(); + public static boolean transactionCanFail() { + return manager.transactionCanFail(); + } + public static boolean isOwnerEconomicallyActive(Inventory inventory) { return !ChestShopSign.isAdminShop(inventory) || !getServerAccountName().isEmpty(); } diff --git a/com/Acrobot/ChestShop/Economy/EconomyManager.java b/com/Acrobot/ChestShop/Economy/EconomyManager.java index e0056b4..9019c2b 100644 --- a/com/Acrobot/ChestShop/Economy/EconomyManager.java +++ b/com/Acrobot/ChestShop/Economy/EconomyManager.java @@ -6,6 +6,10 @@ import com.Acrobot.ChestShop.ChestShop; * @author Acrobot */ public class EconomyManager { + public boolean transactionCanFail() { + return false; + } + public boolean hasAccount(String player) { printError(); return false; diff --git a/com/Acrobot/ChestShop/Economy/Register.java b/com/Acrobot/ChestShop/Economy/Register.java index 8ac300e..52b2843 100644 --- a/com/Acrobot/ChestShop/Economy/Register.java +++ b/com/Acrobot/ChestShop/Economy/Register.java @@ -12,6 +12,10 @@ public class Register extends EconomyManager { this.method = method; } + public boolean transactionCanFail() { + return false; + } + public boolean hasAccount(String player) { return method.hasAccount(player); } diff --git a/com/Acrobot/ChestShop/Economy/Vault.java b/com/Acrobot/ChestShop/Economy/Vault.java index 3c491a4..738e57f 100644 --- a/com/Acrobot/ChestShop/Economy/Vault.java +++ b/com/Acrobot/ChestShop/Economy/Vault.java @@ -9,6 +9,10 @@ import org.bukkit.plugin.RegisteredServiceProvider; public class Vault extends EconomyManager { private static net.milkbowl.vault.economy.Economy vaultPlugin; + public boolean transactionCanFail() { + return getPluginName().equals("Gringotts") || getPluginName().equals("GoldIsMoney") || getPluginName().equals("MultiCurrency"); + } + public boolean hasAccount(String player) { return vaultPlugin.hasAccount(player); } diff --git a/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java b/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java index 55ebf49..5847a10 100644 --- a/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java +++ b/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java @@ -50,11 +50,13 @@ public class PartialTransactionModule implements Listener { String seller = event.getOwner().getName(); - if (Economy.add(seller, price)) { - Economy.subtract(seller, price); //Cash can be safely deposited - } else { - event.setCancelled(SHOP_DEPOSIT_FAILED); - return; + if (Economy.transactionCanFail()) { + if (Economy.add(seller, price)) { + Economy.subtract(seller, price); //Cash can be safely deposited + } else { + event.setCancelled(SHOP_DEPOSIT_FAILED); + return; + } } stock = event.getStock();