Search in sources :

Example 11 with MaxMoneyException

use of net.ess3.api.MaxMoneyException in project Essentials by EssentialsX.

the class UserTest method testMoney.

public void testMoney() {
    should("properly set, take, give, and get money");
    User user = ess.getUser(base1);
    BigDecimal i = new BigDecimal("100.5");
    try {
        user.setMoney(i);
        user.takeMoney(new BigDecimal(50));
        i = i.subtract(BigDecimal.valueOf(50));
        user.giveMoney(new BigDecimal(25));
        i = i.add(BigDecimal.valueOf(25));
    } catch (MaxMoneyException ex) {
        fail();
    }
    assertEquals(user.getMoney(), i);
}
Also used : MaxMoneyException(net.ess3.api.MaxMoneyException) BigDecimal(java.math.BigDecimal)

Example 12 with MaxMoneyException

use of net.ess3.api.MaxMoneyException in project Essentials by EssentialsX.

the class User method setMoney.

@Override
public void setMoney(final BigDecimal value) throws MaxMoneyException {
    if (ess.getSettings().isEcoDisabled()) {
        if (ess.getSettings().isDebug()) {
            ess.getLogger().info("Internal economy functions disabled, aborting balance change.");
        }
        return;
    }
    final BigDecimal oldBalance = _getMoney();
    UserBalanceUpdateEvent updateEvent = new UserBalanceUpdateEvent(this.getBase(), oldBalance, value);
    ess.getServer().getPluginManager().callEvent(updateEvent);
    BigDecimal newBalance = updateEvent.getNewBalance();
    if (Methods.hasMethod()) {
        try {
            final Method method = Methods.getMethod();
            if (!method.hasAccount(this.getName())) {
                throw new Exception();
            }
            final Method.MethodAccount account = Methods.getMethod().getAccount(this.getName());
            account.set(newBalance.doubleValue());
        } catch (Exception ex) {
        }
    }
    super.setMoney(newBalance, true);
    Trade.log("Update", "Set", "API", getName(), new Trade(newBalance, ess), null, null, null, ess);
}
Also used : UserBalanceUpdateEvent(net.ess3.api.events.UserBalanceUpdateEvent) Method(com.earth2me.essentials.register.payment.Method) BigDecimal(java.math.BigDecimal) MaxMoneyException(net.ess3.api.MaxMoneyException)

Example 13 with MaxMoneyException

use of net.ess3.api.MaxMoneyException in project Essentials by EssentialsX.

the class Economy method setMoney.

public static void setMoney(String name, BigDecimal balance) throws UserDoesNotExistException, NoLoanPermittedException {
    User user = getUserByName(name);
    if (user == null) {
        throw new UserDoesNotExistException(name);
    }
    if (balance.compareTo(ess.getSettings().getMinMoney()) < 0) {
        throw new NoLoanPermittedException();
    }
    if (balance.signum() < 0 && !user.isAuthorized("essentials.eco.loan")) {
        throw new NoLoanPermittedException();
    }
    try {
        user.setMoney(balance);
    } catch (MaxMoneyException ex) {
    // TODO: Update API to show max balance errors
    }
    Trade.log("API", "Set", "API", name, new Trade(balance, ess), null, null, null, ess);
}
Also used : Trade(com.earth2me.essentials.Trade) User(com.earth2me.essentials.User) MaxMoneyException(net.ess3.api.MaxMoneyException)

Example 14 with MaxMoneyException

use of net.ess3.api.MaxMoneyException in project Essentials by drtshock.

the class Economy method setMoney.

public static void setMoney(String name, BigDecimal balance) throws UserDoesNotExistException, NoLoanPermittedException {
    User user = getUserByName(name);
    if (user == null) {
        throw new UserDoesNotExistException(name);
    }
    if (balance.compareTo(ess.getSettings().getMinMoney()) < 0) {
        throw new NoLoanPermittedException();
    }
    if (balance.signum() < 0 && !user.isAuthorized("essentials.eco.loan")) {
        throw new NoLoanPermittedException();
    }
    try {
        user.setMoney(balance);
    } catch (MaxMoneyException ex) {
    // TODO: Update API to show max balance errors
    }
    Trade.log("API", "Set", "API", name, new Trade(balance, ess), null, null, null, ess);
}
Also used : Trade(com.earth2me.essentials.Trade) User(com.earth2me.essentials.User) MaxMoneyException(net.ess3.api.MaxMoneyException)

Aggregations

MaxMoneyException (net.ess3.api.MaxMoneyException)12 BigDecimal (java.math.BigDecimal)8 ChargeException (com.earth2me.essentials.ChargeException)4 Trade (com.earth2me.essentials.Trade)4 User (com.earth2me.essentials.User)4 Method (com.earth2me.essentials.register.payment.Method)2 SignBreakEvent (net.ess3.api.events.SignBreakEvent)2 UserBalanceUpdateEvent (net.ess3.api.events.UserBalanceUpdateEvent)2