org.spongepowered.api.service.economy.transaction.ResultType Java Examples

The following examples show how to use org.spongepowered.api.service.economy.transaction.ResultType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PayVirtualCommand.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public void run(Player src, CommandContext args) {
    if (args.getOne("target").isPresent() && args.getOne("amount").isPresent()) {
        String target = args.<String>getOne("target").get();
        BigDecimal amount = BigDecimal.valueOf(args.<Double>getOne("amount").get());
        Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(target);
        Optional<UniqueAccount> uOpt = EconomyLite.getEconomyService().getOrCreateAccount(src.getUniqueId());
        // Check for negative payments
        if (amount.doubleValue() <= 0) {
            src.sendMessage(messageStorage.getMessage("command.pay.invalid"));
        } else {
            if (aOpt.isPresent() && uOpt.isPresent()) {
                Account receiver = aOpt.get();
                UniqueAccount payer = uOpt.get();
                if (payer.transfer(receiver, ecoService.getDefaultCurrency(), amount, Cause.of(EventContext.empty(), (EconomyLite.getInstance())))
                        .getResult().equals(ResultType.SUCCESS)) {
                    src.sendMessage(messageStorage.getMessage("command.pay.success", "target", receiver.getDisplayName().toPlain()));
                } else {
                    src.sendMessage(messageStorage.getMessage("command.pay.failed", "target", receiver.getDisplayName().toPlain()));
                }
            }
        }
    } else {
        src.sendMessage(messageStorage.getMessage("command.error"));
    }
}
 
Example #2
Source File: LiteUniqueAccount.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public TransferResult transfer(Account to, Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts) {
    BigDecimal newBal = to.getBalance(currency).add(amount);
    // Check if the new balance is in bounds
    if (newBal.compareTo(BigDecimal.ZERO) == -1 || newBal.compareTo(BigDecimal.valueOf(999999999)) == 1) {
        return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_SPACE, to, cause);
    }
    // Check if the account has enough funds
    if (amount.compareTo(getBalance(currency)) == 1) {
        return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_FUNDS, to, cause);
    }
    if (withdraw(currency, amount, cause).getResult().equals(ResultType.SUCCESS)
            && to.deposit(currency, amount, cause).getResult().equals(ResultType.SUCCESS)) {
        return resultAndEvent(this, amount, currency, ResultType.SUCCESS, to, cause);
    } else {
        return resultAndEvent(this, amount, currency, ResultType.FAILED, to, cause);
    }
}
 
Example #3
Source File: LiteUniqueAccount.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public TransactionResult withdraw(Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts) {
    BigDecimal newBal = getBalance(currency).subtract(amount);
    // Check if the new balance is in bounds
    if (newBal.compareTo(BigDecimal.ZERO) == -1) {
        return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_FUNDS, TransactionTypes.WITHDRAW, cause);
    }
    if (newBal.compareTo(BigDecimal.valueOf(999999999)) == 1) {
        return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_SPACE, TransactionTypes.WITHDRAW, cause);
    }
    if (playerService.withdraw(uuid, amount, currency, cause)) {
        return resultAndEvent(this, amount, currency, ResultType.SUCCESS, TransactionTypes.WITHDRAW, cause);
    } else {
        return resultAndEvent(this, amount, currency, ResultType.FAILED, TransactionTypes.WITHDRAW, cause);
    }
}
 
Example #4
Source File: AddCommand.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public void run(CommandSource src, CommandContext args) {
    if (args.getOne("player").isPresent() && args.getOne("amount").isPresent()) {
        User target = args.<User>getOne("player").get();
        String targetName = target.getName();
        BigDecimal toAdd = BigDecimal.valueOf(args.<Double>getOne("amount").get());
        Optional<UniqueAccount> uOpt = EconomyLite.getEconomyService().getOrCreateAccount(target.getUniqueId());
        if (uOpt.isPresent()) {
            UniqueAccount targetAccount = uOpt.get();
            if (targetAccount.deposit(EconomyLite.getCurrencyService().getCurrentCurrency(), toAdd,
                    Cause.of(EventContext.empty(),(EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) {
                src.sendMessage(messageStorage.getMessage("command.econ.addsuccess", "name", targetName));
                attemptNotify(target);
            } else {
                src.sendMessage(messageStorage.getMessage("command.econ.addfail", "name", targetName));
            }
        } else {
            src.sendMessage(messageStorage.getMessage("command.error"));
        }
    } else {
        src.sendMessage(messageStorage.getMessage("command.error"));
    }
}
 
Example #5
Source File: LiteVirtualAccount.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public TransferResult transfer(Account to, Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts) {
    BigDecimal newBal = to.getBalance(currency).add(amount);
    // Check if the new balance is in bounds
    if (newBal.compareTo(BigDecimal.ZERO) == -1 || newBal.compareTo(BigDecimal.valueOf(999999999)) == 1) {
        return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_SPACE, to, cause);
    }
    // Check if the account has enough funds
    if (amount.compareTo(getBalance(currency)) == 1) {
        return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_FUNDS, to, cause);
    }
    if (withdraw(currency, amount, cause).getResult().equals(ResultType.SUCCESS)
            && to.deposit(currency, amount, cause).getResult().equals(ResultType.SUCCESS)) {
        return resultAndEvent(this, amount, currency, ResultType.SUCCESS, to, cause);
    } else {
        return resultAndEvent(this, amount, currency, ResultType.FAILED, to, cause);
    }
}
 
Example #6
Source File: LiteVirtualAccount.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public TransactionResult withdraw(Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts) {
    BigDecimal newBal = getBalance(currency).subtract(amount);
    // Check if the new balance is in bounds
    if (newBal.compareTo(BigDecimal.ZERO) == -1) {
        return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_FUNDS, TransactionTypes.WITHDRAW, cause);
    }
    if (newBal.compareTo(BigDecimal.valueOf(999999999)) == 1) {
        return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_SPACE, TransactionTypes.WITHDRAW, cause);
    }
    if (virtualService.withdraw(name, amount, currency, cause)) {
        return resultAndEvent(this, amount, currency, ResultType.SUCCESS, TransactionTypes.WITHDRAW, cause);
    } else {
        return resultAndEvent(this, amount, currency, ResultType.FAILED, TransactionTypes.WITHDRAW, cause);
    }
}
 
Example #7
Source File: SetCommand.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public void run(CommandSource src, CommandContext args) {
    if (args.getOne("player").isPresent() && args.getOne("balance").isPresent()) {
        User target = args.<User>getOne("player").get();
        String targetName = target.getName();
        BigDecimal newBal = BigDecimal.valueOf(args.<Double>getOne("balance").get());
        Optional<UniqueAccount> uOpt = EconomyLite.getEconomyService().getOrCreateAccount(target.getUniqueId());
        if (uOpt.isPresent()) {
            UniqueAccount targetAccount = uOpt.get();
            if (targetAccount.setBalance(EconomyLite.getCurrencyService().getCurrentCurrency(), newBal,
                    Cause.of(EventContext.empty(),(EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) {
                src.sendMessage(messageStorage.getMessage("command.econ.setsuccess", "name", targetName));
                attemptNotify(target);
            } else {
                src.sendMessage(messageStorage.getMessage("command.econ.setfail", "name", targetName));
            }
        } else {
            src.sendMessage(messageStorage.getMessage("command.error"));
        }
    } else {
        src.sendMessage(messageStorage.getMessage("command.error"));
    }
}
 
Example #8
Source File: VirtualAddCommand.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public void run(CommandSource src, CommandContext args) {
    if (args.getOne("account").isPresent() && args.getOne("amount").isPresent()) {
        String target = args.<String>getOne("account").get();
        BigDecimal toAdd = BigDecimal.valueOf(args.<Double>getOne("amount").get());
        Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(target);
        if (aOpt.isPresent()) {
            Account targetAccount = aOpt.get();
            if (targetAccount.deposit(EconomyLite.getCurrencyService().getCurrentCurrency(), toAdd,
                    Cause.of(EventContext.empty(),(EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) {
                src.sendMessage(messageStorage.getMessage("command.econ.addsuccess", "name", target));
            } else {
                src.sendMessage(messageStorage.getMessage("command.econ.addfail", "name", target));
            }
        } else {
            src.sendMessage(messageStorage.getMessage("command.error"));
        }
    } else {
        src.sendMessage(messageStorage.getMessage("command.error"));
    }
}
 
Example #9
Source File: VirtualRemoveCommand.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public void run(CommandSource src, CommandContext args) {
    if (args.getOne("account").isPresent() && args.getOne("amount").isPresent()) {
        String target = args.<String>getOne("account").get();
        BigDecimal toRemove = BigDecimal.valueOf(args.<Double>getOne("amount").get());
        Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(target);
        if (aOpt.isPresent()) {
            Account targetAccount = aOpt.get();
            if (targetAccount.withdraw(EconomyLite.getCurrencyService().getCurrentCurrency(), toRemove,
                    Cause.of(EventContext.empty(),(EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) {
                src.sendMessage(messageStorage.getMessage("command.econ.removesuccess", "name", target));
            } else {
                src.sendMessage(messageStorage.getMessage("command.econ.removefail", "name", target));
            }
        } else {
            src.sendMessage(messageStorage.getMessage("command.error"));
        }
    } else {
        src.sendMessage(messageStorage.getMessage("command.error"));
    }
}
 
Example #10
Source File: VirtualSetCommand.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public void run(CommandSource src, CommandContext args) {
    if (args.getOne("account").isPresent() && args.getOne("amount").isPresent()) {
        String target = args.<String>getOne("account").get();
        BigDecimal newBal = BigDecimal.valueOf(args.<Double>getOne("amount").get());
        Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(target);
        if (aOpt.isPresent()) {
            Account targetAccount = aOpt.get();
            if (targetAccount.setBalance(EconomyLite.getCurrencyService().getCurrentCurrency(), newBal,
                    Cause.of(EventContext.empty(), (EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) {
                src.sendMessage(messageStorage.getMessage("command.econ.setsuccess", "name", targetAccount.getDisplayName().toPlain()));
            } else {
                src.sendMessage(messageStorage.getMessage("command.econ.setfail", "name", targetAccount.getDisplayName().toPlain()));
            }
        } else {
            src.sendMessage(messageStorage.getMessage("command.error"));
        }
    } else {
        src.sendMessage(messageStorage.getMessage("command.error"));
    }
}
 
Example #11
Source File: RemoveCommand.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public void run(CommandSource src, CommandContext args) {
    if (args.getOne("player").isPresent() && args.getOne("amount").isPresent()) {
        User target = args.<User>getOne("player").get();
        String targetName = target.getName();
        BigDecimal toRemove = BigDecimal.valueOf(args.<Double>getOne("amount").get());
        Optional<UniqueAccount> uOpt = EconomyLite.getEconomyService().getOrCreateAccount(target.getUniqueId());
        if (uOpt.isPresent()) {
            UniqueAccount targetAccount = uOpt.get();
            if (targetAccount.withdraw(EconomyLite.getCurrencyService().getCurrentCurrency(), toRemove,
                    Cause.of(EventContext.empty(),(EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) {
                src.sendMessage(messageStorage.getMessage("command.econ.removesuccess", "name", targetName));
                attemptNotify(target);
            } else {
                src.sendMessage(messageStorage.getMessage("command.econ.removefail", "name", targetName));
            }
        } else {
            src.sendMessage(messageStorage.getMessage("command.error"));
        }
    } else {
        src.sendMessage(messageStorage.getMessage("command.error"));
    }
}
 
Example #12
Source File: LoanManager.java    From EconomyLite with MIT License 5 votes vote down vote up
/**
 * Adds currency to a player's loan balance. Automatically charges interest
 * and adds to the player's account.
 *
 * @param uuid The player.
 * @param amount The amount to add.
 * @return If the amount was added successfully.
 */
public boolean addLoanBalance(UUID uuid, double amount) {
    Currency cur = eco.getDefaultCurrency();
    Optional<Double> bOpt = getLoanBalance(uuid);
    Optional<UniqueAccount> uOpt = eco.getOrCreateAccount(uuid);
    if (bOpt.isPresent() && uOpt.isPresent()) {
        double bal = bOpt.get();
        if (amount < 0 || bal + (amount * module.getInterestRate()) > module.getMaxLoan()) {
            return false;
        }
        return (setLoanBalance(uuid, (amount * module.getInterestRate()) + bal) && uOpt.get()
                .deposit(cur, BigDecimal.valueOf(amount), CauseFactory.stringCause("loan")).getResult().equals(ResultType.SUCCESS));
    }
    return false;
}
 
Example #13
Source File: VirtualPayCommand.java    From EconomyLite with MIT License 5 votes vote down vote up
@Override
public void run(CommandSource src, CommandContext args) {
    if (args.getOne("account").isPresent() && args.getOne("target").isPresent() && args.getOne("amount").isPresent()) {
        String account = args.<String>getOne("account").get();
        User target = args.<User>getOne("target").get();
        BigDecimal amount = BigDecimal.valueOf(args.<Double>getOne("amount").get());
        Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(account);
        Optional<UniqueAccount> uOpt = EconomyLite.getEconomyService().getOrCreateAccount(target.getUniqueId());
        // Check for negative payments
        if (amount.compareTo(BigDecimal.ONE) == -1) {
            src.sendMessage(messageStorage.getMessage("command.pay.invalid"));
        } else {
            if (aOpt.isPresent() && uOpt.isPresent()) {
                Account payer = aOpt.get();
                UniqueAccount receiver = uOpt.get();
                if (payer.transfer(receiver, ecoService.getDefaultCurrency(), amount, Cause.of(EventContext.empty(), EconomyLite.getInstance
                        ()))
                        .getResult().equals(ResultType.SUCCESS)) {
                    src.sendMessage(messageStorage.getMessage("command.pay.success", "target", target.getName()));
                    if (target instanceof Player) {
                        Text label = ecoService.getDefaultCurrency().getPluralDisplayName();
                        if (amount.equals(BigDecimal.ONE)) {
                            label = ecoService.getDefaultCurrency().getDisplayName();
                        }
                        ((Player) target).sendMessage(messageStorage.getMessage("command.pay.target", "amountandlabel",
                                String.format(Locale.ENGLISH, "%,.2f", amount) + " " + label.toPlain(), "sender",
                                payer.getDisplayName().toPlain()));
                    }
                } else {
                    src.sendMessage(messageStorage.getMessage("command.pay.failed", "target", target.getName()));
                }
            }
        }
    } else {
        src.sendMessage(messageStorage.getMessage("command.error"));
    }
}
 
Example #14
Source File: LiteUniqueAccount.java    From EconomyLite with MIT License 5 votes vote down vote up
@Override
public TransactionResult resetBalance(Currency currency, Cause cause, Set<Context> contexts) {
    if (playerService.setBalance(uuid, getDefaultBalance(currency), currency, cause)) {
        return resultAndEvent(this, BigDecimal.ZERO, currency, ResultType.SUCCESS, TransactionTypes.WITHDRAW, cause);
    } else {
        return resultAndEvent(this, BigDecimal.ZERO, currency, ResultType.FAILED, TransactionTypes.WITHDRAW, cause);
    }
}
 
Example #15
Source File: LoanManager.java    From EconomyLite with MIT License 5 votes vote down vote up
/**
 * Removes loan balance from a player. Automatically removes funds from the
 * player's account.
 *
 * @param uuid The player.
 * @param amount The amount to remove.
 * @return If the amount was removed successfully.
 */
public boolean removeLoanBalance(UUID uuid, double amount) {
    Currency cur = eco.getDefaultCurrency();
    Optional<Double> bOpt = getLoanBalance(uuid);
    Optional<UniqueAccount> uOpt = eco.getOrCreateAccount(uuid);
    if (bOpt.isPresent() && uOpt.isPresent()) {
        double bal = bOpt.get();
        if (bal - amount < 0 || amount < 0) {
            return false;
        }
        return (uOpt.get().withdraw(cur, BigDecimal.valueOf(amount), CauseFactory.stringCause("loan")).getResult()
                .equals(ResultType.SUCCESS) && setLoanBalance(uuid, bal - amount));
    }
    return false;
}
 
Example #16
Source File: LiteUniqueAccount.java    From EconomyLite with MIT License 5 votes vote down vote up
@Override
public TransactionResult setBalance(Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts) {
    // Check if the new balance is in bounds
    if (amount.compareTo(BigDecimal.ZERO) == -1 || amount.compareTo(BigDecimal.valueOf(999999999)) == 1) {
        return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_SPACE, TransactionTypes.DEPOSIT, cause);
    }
    if (playerService.setBalance(uuid, amount, currency, cause)) {
        return resultAndEvent(this, amount, currency, ResultType.SUCCESS, TransactionTypes.DEPOSIT, cause);
    } else {
        return resultAndEvent(this, amount, currency, ResultType.FAILED, TransactionTypes.DEPOSIT, cause);
    }
}
 
Example #17
Source File: LiteUniqueAccount.java    From EconomyLite with MIT License 5 votes vote down vote up
@Override
public Map<Currency, TransactionResult> resetBalances(Cause cause, Set<Context> contexts) {
    HashMap<Currency, TransactionResult> results = new HashMap<>();
    for (Currency currency : currencyService.getCurrencies()) {
        if (playerService.accountExists(uuid, currency, cause)) {
            if (playerService.setBalance(uuid, getDefaultBalance(currency), currency, cause)) {
                results.put(currency, resultAndEvent(this, getBalance(currency), currency, ResultType.SUCCESS, TransactionTypes.WITHDRAW, cause));
            } else {
                results.put(currency, resultAndEvent(this, getBalance(currency), currency, ResultType.FAILED, TransactionTypes.WITHDRAW, cause));
            }
        }
    }
    return results;
}
 
Example #18
Source File: PayCommand.java    From EconomyLite with MIT License 5 votes vote down vote up
private void pay(User target, BigDecimal amount, Player src) {
    String targetName = target.getName();
    if (!target.getUniqueId().equals(src.getUniqueId())) {
        Optional<UniqueAccount> uOpt = ecoService.getOrCreateAccount(src.getUniqueId());
        Optional<UniqueAccount> tOpt = ecoService.getOrCreateAccount(target.getUniqueId());
        if (uOpt.isPresent() && tOpt.isPresent()) {
            if (uOpt.get()
                    .transfer(tOpt.get(), ecoService.getDefaultCurrency(), amount, Cause.of(EventContext.empty(), (EconomyLite.getInstance())))
                    .getResult().equals(ResultType.SUCCESS)) {
                Text label = ecoService.getDefaultCurrency().getPluralDisplayName();
                if (amount.equals(BigDecimal.ONE)) {
                    label = ecoService.getDefaultCurrency().getDisplayName();
                }
                src.sendMessage(messageStorage.getMessage("command.pay.success", "target", targetName, "amountandlabel",
                        String.format(Locale.ENGLISH, "%,.2f", amount) + " " + label.toPlain()));
                final Text curLabel = label;
                Sponge.getServer().getPlayer(target.getUniqueId()).ifPresent(p -> {
                    p.sendMessage(messageStorage.getMessage("command.pay.target", "amountandlabel",
                            String.format(Locale.ENGLISH, "%,.2f", amount) + " " + curLabel.toPlain(), "sender",
                            uOpt.get().getDisplayName().toPlain()));
                });
            } else {
                src.sendMessage(messageStorage.getMessage("command.pay.failed", "target", targetName));
            }
        } else {
            src.sendMessage(messageStorage.getMessage("command.error"));
        }
    } else {
        src.sendMessage(messageStorage.getMessage("command.pay.notyou"));
    }
}
 
Example #19
Source File: LiteVirtualAccount.java    From EconomyLite with MIT License 5 votes vote down vote up
@Override
public TransactionResult setBalance(Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts) {
    // Check if the new balance is in bounds
    if (amount.compareTo(BigDecimal.ZERO) == -1 || amount.compareTo(BigDecimal.valueOf(999999999)) == 1) {
        return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_SPACE, TransactionTypes.DEPOSIT, cause);
    }
    if (virtualService.setBalance(name, amount, currency, cause)) {
        return resultAndEvent(this, amount, currency, ResultType.SUCCESS, TransactionTypes.DEPOSIT, cause);
    } else {
        return resultAndEvent(this, amount, currency, ResultType.FAILED, TransactionTypes.DEPOSIT, cause);
    }
}
 
Example #20
Source File: LiteVirtualAccount.java    From EconomyLite with MIT License 5 votes vote down vote up
@Override
public Map<Currency, TransactionResult> resetBalances(Cause cause, Set<Context> contexts) {
    HashMap<Currency, TransactionResult> results = new HashMap<>();
    for (Currency currency : currencyService.getCurrencies()) {
        if (virtualService.accountExists(name, currency, cause)) {
            if (virtualService.setBalance(name, getDefaultBalance(currency), currency, cause)) {
                results.put(currency, resultAndEvent(this, getBalance(currency), currency, ResultType.SUCCESS, TransactionTypes.WITHDRAW, cause));
            } else {
                results.put(currency, resultAndEvent(this, getBalance(currency), currency, ResultType.FAILED, TransactionTypes.WITHDRAW, cause));
            }
        }
    }
    return results;
}
 
Example #21
Source File: LiteVirtualAccount.java    From EconomyLite with MIT License 5 votes vote down vote up
@Override
public TransactionResult resetBalance(Currency currency, Cause cause, Set<Context> contexts) {
    if (virtualService.setBalance(name, getDefaultBalance(currency), currency, cause)) {
        return resultAndEvent(this, BigDecimal.ZERO, currency, ResultType.SUCCESS, TransactionTypes.WITHDRAW, cause);
    } else {
        return resultAndEvent(this, BigDecimal.ZERO, currency, ResultType.FAILED, TransactionTypes.WITHDRAW, cause);
    }
}
 
Example #22
Source File: LiteVirtualAccount.java    From EconomyLite with MIT License 5 votes vote down vote up
@Override
public TransactionResult deposit(Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts) {
    BigDecimal newBal = getBalance(currency).add(amount);
    // Check if the new balance is in bounds
    if (newBal.compareTo(BigDecimal.ZERO) == -1 || newBal.compareTo(BigDecimal.valueOf(999999999)) == 1) {
        return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_SPACE, TransactionTypes.DEPOSIT, cause);
    }
    if (virtualService.deposit(name, amount, currency, cause)) {
        return resultAndEvent(this, amount, currency, ResultType.SUCCESS, TransactionTypes.DEPOSIT, cause);
    } else {
        return resultAndEvent(this, amount, currency, ResultType.FAILED, TransactionTypes.DEPOSIT, cause);
    }
}
 
Example #23
Source File: LiteUniqueAccount.java    From EconomyLite with MIT License 5 votes vote down vote up
@Override
public TransactionResult deposit(Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts) {
    BigDecimal newBal = getBalance(currency).add(amount);
    // Check if the new balance is in bounds
    if (newBal.compareTo(BigDecimal.ZERO) == -1 || newBal.compareTo(BigDecimal.valueOf(999999999)) == 1) {
        return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_SPACE, TransactionTypes.DEPOSIT, cause);
    }
    if (playerService.deposit(uuid, amount, currency, cause)) {
        return resultAndEvent(this, amount, currency, ResultType.SUCCESS, TransactionTypes.DEPOSIT, cause);
    } else {
        return resultAndEvent(this, amount, currency, ResultType.FAILED, TransactionTypes.DEPOSIT, cause);
    }
}
 
Example #24
Source File: LiteTransactionResult.java    From EconomyLite with MIT License 5 votes vote down vote up
public LiteTransactionResult(Account account, BigDecimal amount, Currency currency, ResultType result, TransactionType transactionType) {
	this.account = account;
	this.amount = amount;
	this.contexts = new HashSet<Context>();
	this.currency = currency;
	this.result = result;
	this.transactionType = transactionType;
}
 
Example #25
Source File: LiteTransactionResult.java    From EconomyLite with MIT License 4 votes vote down vote up
@Override
public ResultType getResult() {
	return this.result;
}
 
Example #26
Source File: LiteUniqueAccount.java    From EconomyLite with MIT License 4 votes vote down vote up
private TransferResult resultAndEvent(Account account, BigDecimal amount, Currency currency, ResultType resultType, Account toWho, Cause cause) {
    TransferResult result = new LiteTransferResult(account, amount, currency, resultType, toWho);
    Sponge.getEventManager().post(new LiteEconomyTransactionEvent(result, UUID.fromString(account.getIdentifier()), cause));
    return result;
}
 
Example #27
Source File: LiteVirtualAccount.java    From EconomyLite with MIT License 4 votes vote down vote up
private TransactionResult resultAndEvent(Account account, BigDecimal amount, Currency currency, ResultType resultType,
        TransactionType transactionType, Cause cause) {
    TransactionResult result = new LiteTransactionResult(account, amount, currency, resultType, transactionType);
    Sponge.getEventManager().post(new LiteEconomyTransactionEvent(result, cause));
    return result;
}
 
Example #28
Source File: LiteVirtualAccount.java    From EconomyLite with MIT License 4 votes vote down vote up
private TransferResult resultAndEvent(Account account, BigDecimal amount, Currency currency, ResultType resultType, Account toWho, Cause cause) {
    TransferResult result = new LiteTransferResult(account, amount, currency, resultType, toWho);
    Sponge.getEventManager().post(new LiteEconomyTransactionEvent(result, cause));
    return result;
}
 
Example #29
Source File: LiteTransferResult.java    From EconomyLite with MIT License 4 votes vote down vote up
public LiteTransferResult(Account account, BigDecimal amount, Currency currency, ResultType result, Account toWho) {
    super(account, amount, currency, result, TransactionTypes.TRANSFER);
    this.toWho = toWho;
}
 
Example #30
Source File: TaxApplyTask.java    From GriefDefender with MIT License 4 votes vote down vote up
private void handleClaimTax(GDClaim claim, GDPlayerData playerData, boolean inTown) {
    final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(playerData.getUniqueId());
    double taxRate = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Double.class), user, Options.TAX_RATE, claim);
    double taxOwed = claim.getEconomyData().getTaxBalance() + (claim.getClaimBlocks() * taxRate);
    try (final CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        Sponge.getCauseStackManager().pushCause(GriefDefenderPlugin.getInstance());
        GDTaxClaimEvent event = new GDTaxClaimEvent(claim, taxRate, taxOwed);
        GriefDefender.getEventManager().post(event);
        if (event.cancelled()) {
            return;
        }
        final double taxBalance = claim.getEconomyData().getTaxBalance();
        taxRate = event.getTaxRate();
        taxOwed = taxBalance + (claim.getClaimBlocks() * taxRate);
        final TransactionResult result = EconomyUtil.withdrawFunds(user.getUniqueId(), taxOwed);
        if (result.getResult() != ResultType.SUCCESS) {
            final Instant localNow = Instant.now();
            Instant taxPastDueDate = claim.getEconomyData().getTaxPastDueDate();
            if (taxPastDueDate == null) {
                 claim.getEconomyData().setTaxPastDueDate(Instant.now());
            } else {
                final int taxExpirationDays = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Integer.class), user, Options.TAX_EXPIRATION, claim);
                if (taxExpirationDays > 0) {
                    claim.getInternalClaimData().setExpired(true);
                    if (taxExpirationDays == 0) {
                        claim.getInternalClaimData().setExpired(true);
                        claim.getData().save();
                    } else if (taxPastDueDate.plus(Duration.ofDays(taxExpirationDays)).isBefore(localNow)) {
                        claim.getInternalClaimData().setExpired(true);
                        claim.getData().save();
                    }
                }
            }
            final double totalTaxOwed = taxBalance + taxOwed;
            claim.getEconomyData().setTaxBalance(totalTaxOwed);
            claim.getEconomyData().addPaymentTransaction(new GDPaymentTransaction(TransactionType.TAX, TransactionResultType.FAIL, Instant.now(), taxOwed));
        } else {
            claim.getEconomyData().addPaymentTransaction(new GDPaymentTransaction(TransactionType.TAX, TransactionResultType.SUCCESS, Instant.now(), taxOwed));
            claim.getEconomyData().setTaxPastDueDate(null);
            claim.getEconomyData().setTaxBalance(0);
            claim.getInternalClaimData().setExpired(false);

            if (inTown) {
                final GDClaim town = claim.getTownClaim();
                town.getData()
                    .getEconomyData()
                    .addPaymentTransaction(new GDPaymentTransaction(TransactionType.TAX, TransactionResultType.SUCCESS, Instant.now(), taxOwed));
                if (town.getEconomyAccountId().isPresent()) {
                    EconomyUtil.depositFunds(town.getEconomyAccountId().get(), taxOwed);
                }
            }
            claim.getData().save();
        }
    }
}