Search in sources :

Example 1 with MaxMoneyException

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

the class Commandeco method take.

private void take(BigDecimal amount, final User player, final CommandSource sender) throws ChargeException {
    BigDecimal money = player.getMoney();
    BigDecimal minBalance = ess.getSettings().getMinMoney();
    if (money.subtract(amount).compareTo(minBalance) > 0) {
        player.takeMoney(amount, sender);
    } else if (sender == null) {
        try {
            player.setMoney(minBalance);
        } catch (MaxMoneyException ex) {
        // Take shouldn't be able to throw a max money exception
        }
        player.sendMessage(tl("takenFromAccount", NumberUtil.displayCurrency(player.getMoney(), ess)));
    } else {
        throw new ChargeException(tl("insufficientFunds"));
    }
}
Also used : MaxMoneyException(net.ess3.api.MaxMoneyException) ChargeException(com.earth2me.essentials.ChargeException) BigDecimal(java.math.BigDecimal)

Example 2 with MaxMoneyException

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

the class EssentialsSign method onSignBreak.

protected final boolean onSignBreak(final Block block, final Player player, final IEssentials ess) throws MaxMoneyException {
    final ISign sign = new BlockSign(block);
    final User user = ess.getUser(player);
    try {
        if (!(user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".break") || user.isAuthorized("essentials.signs.break." + signName.toLowerCase(Locale.ENGLISH)))) {
            return false;
        }
        final SignBreakEvent signEvent = new SignBreakEvent(sign, this, user);
        ess.getServer().getPluginManager().callEvent(signEvent);
        if (signEvent.isCancelled()) {
            return false;
        }
        return onSignBreak(sign, user, getUsername(user), ess);
    } catch (SignException ex) {
        showError(ess, user.getSource(), ex, signName);
        return false;
    }
}
Also used : SignBreakEvent(net.ess3.api.events.SignBreakEvent)

Example 3 with MaxMoneyException

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

the class UserData method setMoney.

public void setMoney(BigDecimal value, boolean throwError) throws MaxMoneyException {
    BigDecimal maxMoney = ess.getSettings().getMaxMoney();
    BigDecimal minMoney = ess.getSettings().getMinMoney();
    if (value.compareTo(maxMoney) > 0) {
        if (throwError) {
            throw new MaxMoneyException();
        }
        money = maxMoney;
    } else {
        money = value;
    }
    if (money.compareTo(minMoney) < 0) {
        money = minMoney;
    }
    config.setProperty("money", money);
    stopTransaction();
}
Also used : MaxMoneyException(net.ess3.api.MaxMoneyException) BigDecimal(java.math.BigDecimal)

Example 4 with MaxMoneyException

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

the class EssentialsSign method onSignBreak.

protected final boolean onSignBreak(final Block block, final Player player, final IEssentials ess) throws MaxMoneyException {
    final ISign sign = new BlockSign(block);
    final User user = ess.getUser(player);
    try {
        if (!(user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".break") || user.isAuthorized("essentials.signs.break." + signName.toLowerCase(Locale.ENGLISH)))) {
            return false;
        }
        final SignBreakEvent signEvent = new SignBreakEvent(sign, this, user);
        ess.getServer().getPluginManager().callEvent(signEvent);
        if (signEvent.isCancelled()) {
            return false;
        }
        return onSignBreak(sign, user, getUsername(user), ess);
    } catch (SignException ex) {
        showError(ess, user.getSource(), ex, signName);
        return false;
    }
}
Also used : SignBreakEvent(net.ess3.api.events.SignBreakEvent)

Example 5 with MaxMoneyException

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

the class UserData method setMoney.

public void setMoney(BigDecimal value, boolean throwError) throws MaxMoneyException {
    BigDecimal maxMoney = ess.getSettings().getMaxMoney();
    BigDecimal minMoney = ess.getSettings().getMinMoney();
    if (value.compareTo(maxMoney) > 0) {
        if (throwError) {
            throw new MaxMoneyException();
        }
        money = maxMoney;
    } else {
        money = value;
    }
    if (money.compareTo(minMoney) < 0) {
        money = minMoney;
    }
    config.setProperty("money", money);
    stopTransaction();
}
Also used : MaxMoneyException(net.ess3.api.MaxMoneyException) BigDecimal(java.math.BigDecimal)

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