Ability to pay for commands (through economy) is now checked before firing events which can be canceled, and actual payment made after making sure the event isn't canceled.
Added Econ.hasAtLeast(EconomyParticipator ep, double delta, String toDoThis) method to check if an account has at least a specified amount of money in it. Also added related FCommand.canAffordCommand(double cost, String toDoThis).
This commit is contained in:
@ -210,7 +210,20 @@ public class Econ
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean hasAtLeast(EconomyParticipator ep, double delta, String toDoThis)
|
||||
{
|
||||
if ( ! shouldBeUsed()) return true;
|
||||
|
||||
if ( ! econ.has(ep.getAccountId(), delta))
|
||||
{
|
||||
if (toDoThis != null && !toDoThis.isEmpty())
|
||||
ep.msg("<h>%s<i> can't afford <h>%s<i> %s.", ep.describeTo(ep, true), moneyString(delta), toDoThis);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean modifyMoney(EconomyParticipator ep, double delta, String toDoThis, String forDoingThis)
|
||||
{
|
||||
if ( ! shouldBeUsed()) return false;
|
||||
@ -231,7 +244,8 @@ public class Econ
|
||||
// There is no risk of failure
|
||||
econ.depositPlayer(acc, delta);
|
||||
modifyUniverseMoney(-delta);
|
||||
ep.msg("<h>%s<i> gained <h>%s<i> %s.", You, moneyString(delta), forDoingThis);
|
||||
if (forDoingThis != null && !forDoingThis.isEmpty())
|
||||
ep.msg("<h>%s<i> gained <h>%s<i> %s.", You, moneyString(delta), forDoingThis);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -244,13 +258,15 @@ public class Econ
|
||||
// There is enough money to pay
|
||||
econ.withdrawPlayer(acc, -delta);
|
||||
modifyUniverseMoney(-delta);
|
||||
ep.msg("<h>%s<i> lost <h>%s<i> %s.", You, moneyString(-delta), forDoingThis);
|
||||
if (forDoingThis != null && !forDoingThis.isEmpty())
|
||||
ep.msg("<h>%s<i> lost <h>%s<i> %s.", You, moneyString(-delta), forDoingThis);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// There was not enough money to pay
|
||||
ep.msg("<h>%s<i> can't afford <h>%s<i> %s.", You, moneyString(-delta), toDoThis);
|
||||
if (toDoThis != null && !toDoThis.isEmpty())
|
||||
ep.msg("<h>%s<i> can't afford <h>%s<i> %s.", You, moneyString(-delta), toDoThis);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user