Optimized the transaction module

This commit is contained in:
Acrobot 2013-02-01 19:28:42 +01:00
parent 0880ec6575
commit d3524faae9
5 changed files with 23 additions and 5 deletions

View File

@ -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();
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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();