mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-23 18:45:31 +01:00
Optimized the transaction module
This commit is contained in:
parent
0880ec6575
commit
d3524faae9
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user