Search in sources :

Example 1 with Economy

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

the class User method setMoney.

public void setMoney(final BigDecimal value, final UserBalanceUpdateEvent.Cause cause) 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();
    final UserBalanceUpdateEvent updateEvent = new UserBalanceUpdateEvent(this.getBase(), oldBalance, value, cause);
    ess.getServer().getPluginManager().callEvent(updateEvent);
    final BigDecimal newBalance = updateEvent.getNewBalance();
    final EconomyLayer layer = EconomyLayers.getSelectedLayer();
    if (layer != null && (layer.hasAccount(getBase()) || layer.createPlayerAccount(getBase()))) {
        layer.set(getBase(), newBalance);
    }
    super.setMoney(newBalance, true);
    Trade.log("Update", "Set", "API", getName(), new Trade(newBalance, ess), null, null, null, newBalance, ess);
}
Also used : EconomyLayer(com.earth2me.essentials.economy.EconomyLayer) UserBalanceUpdateEvent(net.ess3.api.events.UserBalanceUpdateEvent) BigDecimal(java.math.BigDecimal)

Example 2 with Economy

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

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 3 with Economy

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

the class User method _getMoney.

private BigDecimal _getMoney() {
    if (ess.getSettings().isEcoDisabled()) {
        if (ess.getSettings().isDebug()) {
            ess.getLogger().info("Internal economy functions disabled, aborting balance check.");
        }
        return BigDecimal.ZERO;
    }
    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());
            return BigDecimal.valueOf(account.balance());
        } catch (Exception ex) {
        }
    }
    return super.getMoney();
}
Also used : Method(com.earth2me.essentials.register.payment.Method) MaxMoneyException(net.ess3.api.MaxMoneyException)

Example 4 with Economy

use of net.ess3.api.Economy 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 5 with Economy

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

the class User method _getMoney.

private BigDecimal _getMoney() {
    if (ess.getSettings().isEcoDisabled()) {
        if (ess.getSettings().isDebug()) {
            ess.getLogger().info("Internal economy functions disabled, aborting balance check.");
        }
        return BigDecimal.ZERO;
    }
    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());
            return BigDecimal.valueOf(account.balance());
        } catch (Exception ex) {
        }
    }
    return super.getMoney();
}
Also used : Method(com.earth2me.essentials.register.payment.Method) MaxMoneyException(net.ess3.api.MaxMoneyException)

Aggregations

Method (com.earth2me.essentials.register.payment.Method)4 BigDecimal (java.math.BigDecimal)4 MaxMoneyException (net.ess3.api.MaxMoneyException)4 UserBalanceUpdateEvent (net.ess3.api.events.UserBalanceUpdateEvent)4 EconomyLayer (com.earth2me.essentials.economy.EconomyLayer)2