Merge pull request #201 from jastice/econfix
Handle EconomyResponse objects from Vault on all transactions.
This commit is contained in:
commit
04d808e54d
@ -17,6 +17,7 @@ import com.massivecraft.factions.struct.FPerm;
|
|||||||
import com.massivecraft.factions.util.RelationUtil;
|
import com.massivecraft.factions.util.RelationUtil;
|
||||||
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import net.milkbowl.vault.economy.EconomyResponse;
|
||||||
|
|
||||||
|
|
||||||
public class Econ
|
public class Econ
|
||||||
@ -142,14 +143,25 @@ public class Econ
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Transfer money
|
// Transfer money
|
||||||
econ.withdrawPlayer(from.getAccountId(), amount);
|
EconomyResponse erw = econ.withdrawPlayer(from.getAccountId(), amount);
|
||||||
econ.depositPlayer(to.getAccountId(), amount);
|
|
||||||
|
|
||||||
// Inform
|
|
||||||
if (notify)
|
|
||||||
sendTransferInfo(invoker, from, to, amount);
|
|
||||||
|
|
||||||
|
if (erw.transactionSuccess()) {
|
||||||
|
EconomyResponse erd = econ.depositPlayer(to.getAccountId(), amount);
|
||||||
|
if (erd.transactionSuccess()) {
|
||||||
|
if (notify) sendTransferInfo(invoker, from, to, amount);
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
// transaction failed, refund account
|
||||||
|
econ.depositPlayer(from.getAccountId(), amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we get here something with the transaction failed
|
||||||
|
if (notify)
|
||||||
|
invoker.msg("Unable to transfer %s<b> to <h>%s<b> from <h>%s<b>.", moneyString(amount), to.describeTo(invoker), from.describeTo(invoker, true));
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<FPlayer> getFplayers(EconomyParticipator ep)
|
public static Set<FPlayer> getFplayers(EconomyParticipator ep)
|
||||||
@ -239,22 +251,29 @@ public class Econ
|
|||||||
if (delta > 0)
|
if (delta > 0)
|
||||||
{
|
{
|
||||||
// The player should gain money
|
// The player should gain money
|
||||||
// There is no risk of failure
|
// The account might not have enough space
|
||||||
econ.depositPlayer(acc, delta);
|
EconomyResponse er = econ.depositPlayer(acc, delta);
|
||||||
|
if (er.transactionSuccess()) {
|
||||||
modifyUniverseMoney(-delta);
|
modifyUniverseMoney(-delta);
|
||||||
if (forDoingThis != null && !forDoingThis.isEmpty())
|
if (forDoingThis != null && !forDoingThis.isEmpty())
|
||||||
ep.msg("<h>%s<i> gained <h>%s<i> %s.", You, moneyString(delta), forDoingThis);
|
ep.msg("<h>%s<i> gained <h>%s<i> %s.", You, moneyString(delta), forDoingThis);
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
// transfer to account failed
|
||||||
|
if (forDoingThis != null && !forDoingThis.isEmpty())
|
||||||
|
ep.msg("<h>%s<i> would have gained <h>%s<i> %s, but the deposit failed.", You, moneyString(delta), forDoingThis);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// The player should loose money
|
// The player should loose money
|
||||||
// The player might not have enough.
|
// The player might not have enough.
|
||||||
|
|
||||||
if (econ.has(acc, -delta))
|
if (econ.has(acc, -delta) && econ.withdrawPlayer(acc, -delta).transactionSuccess())
|
||||||
{
|
{
|
||||||
// There is enough money to pay
|
// There is enough money to pay
|
||||||
econ.withdrawPlayer(acc, -delta);
|
|
||||||
modifyUniverseMoney(-delta);
|
modifyUniverseMoney(-delta);
|
||||||
if (forDoingThis != null && !forDoingThis.isEmpty())
|
if (forDoingThis != null && !forDoingThis.isEmpty())
|
||||||
ep.msg("<h>%s<i> lost <h>%s<i> %s.", You, moneyString(-delta), forDoingThis);
|
ep.msg("<h>%s<i> lost <h>%s<i> %s.", You, moneyString(-delta), forDoingThis);
|
||||||
|
Loading…
Reference in New Issue
Block a user