Fix the money bug
This commit is contained in:
parent
6bebf3643e
commit
be46ac065f
|
@ -73,6 +73,30 @@ public class Economy {
|
|||
return manager.subtract(uName.getName(name), roundUp(amount));
|
||||
}
|
||||
|
||||
public static boolean canHold(String name, double amount) {
|
||||
if (!transactionCanFail()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isServerAccount(name)) {
|
||||
if (!getServerAccountName().isEmpty()) {
|
||||
name = getServerAccountName();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
name = uName.getName(name);
|
||||
|
||||
if (!manager.add(name, amount)) {
|
||||
return false;
|
||||
} else {
|
||||
manager.subtract(name, amount);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean hasEnough(String name, double amount) {
|
||||
if (amount <= 0) {
|
||||
return true;
|
||||
|
|
|
@ -50,13 +50,9 @@ public class PartialTransactionModule implements Listener {
|
|||
|
||||
String seller = event.getOwner().getName();
|
||||
|
||||
if (Economy.transactionCanFail()) {
|
||||
if (Economy.add(seller, price)) {
|
||||
Economy.subtract(seller, price); //Cash can be safely deposited
|
||||
} else {
|
||||
event.setCancelled(SHOP_DEPOSIT_FAILED);
|
||||
return;
|
||||
}
|
||||
if (!Economy.canHold(seller, price)) {
|
||||
event.setCancelled(SHOP_DEPOSIT_FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
stock = event.getStock();
|
||||
|
@ -103,9 +99,7 @@ public class PartialTransactionModule implements Listener {
|
|||
|
||||
stock = event.getStock();
|
||||
|
||||
if (Economy.add(player, price)) {
|
||||
Economy.subtract(player, price); //Cash can be safely deposited
|
||||
} else {
|
||||
if (!Economy.canHold(player, price)) {
|
||||
event.setCancelled(CLIENT_DEPOSIT_FAILED);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue