Search in sources :

Example 36 with Trade

use of com.earth2me.essentials.Trade 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)

Example 37 with Trade

use of com.earth2me.essentials.Trade in project Essentials by drtshock.

the class Economy method substract.

public static void substract(String name, BigDecimal amount) throws UserDoesNotExistException, NoLoanPermittedException, ArithmeticException {
    BigDecimal result = getMoneyExact(name).subtract(amount, MATH_CONTEXT);
    setMoney(name, result);
    Trade.log("API", "Subtract", "API", name, new Trade(amount, ess), null, null, null, ess);
}
Also used : Trade(com.earth2me.essentials.Trade) BigDecimal(java.math.BigDecimal)

Example 38 with Trade

use of com.earth2me.essentials.Trade in project Essentials by drtshock.

the class Commandspawn method run.

@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    final Trade charge = new Trade(this.getName(), ess);
    charge.isAffordableFor(user);
    if (args.length > 0 && user.isAuthorized("essentials.spawn.others")) {
        final User otherUser = getPlayer(server, user, args, 0);
        respawn(user.getSource(), user, otherUser, charge);
        if (!otherUser.equals(user)) {
            otherUser.sendMessage(tl("teleportAtoB", user.getDisplayName(), "spawn"));
        }
    } else {
        respawn(user.getSource(), user, user, charge);
    }
    throw new NoChargeException();
}
Also used : Trade(com.earth2me.essentials.Trade) NoChargeException(com.earth2me.essentials.commands.NoChargeException) User(com.earth2me.essentials.User)

Example 39 with Trade

use of com.earth2me.essentials.Trade in project Essentials by drtshock.

the class Commandpay method updatePlayer.

@Override
protected void updatePlayer(final Server server, final CommandSource sender, final User player, final String[] args) throws ChargeException {
    User user = ess.getUser(sender.getPlayer());
    try {
        if (!player.isAcceptingPay()) {
            sender.sendMessage(tl("notAcceptingPay", player.getDisplayName()));
            return;
        }
        if (user.isPromptingPayConfirm() && !amount.equals(user.getConfirmingPayments().get(player))) {
            // Used to reset confirmations and inform to confirm when a new pay command has been inserted.
            if (!informToConfirm) {
                // User hasnt been asked to confirm payment to this player, reset all confirmed payments and ask to confirm again.
                // Clear previous confirmations to ensure that a new confirmation message is brought up.
                user.getConfirmingPayments().clear();
                this.informToConfirm = true;
            }
            user.getConfirmingPayments().put(player, amount);
            return;
        }
        user.payUser(player, amount);
        user.getConfirmingPayments().remove(player);
        Trade.log("Command", "Pay", "Player", user.getName(), new Trade(amount, ess), player.getName(), new Trade(amount, ess), user.getLocation(), ess);
    } catch (MaxMoneyException ex) {
        sender.sendMessage(tl("maxMoney"));
        try {
            user.setMoney(user.getMoney().add(amount));
        } catch (MaxMoneyException ignored) {
        // this should never happen
        }
    } catch (Exception e) {
        sender.sendMessage(e.getMessage());
    }
}
Also used : Trade(com.earth2me.essentials.Trade) User(com.earth2me.essentials.User) MaxMoneyException(net.ess3.api.MaxMoneyException) ChargeException(com.earth2me.essentials.ChargeException) MaxMoneyException(net.ess3.api.MaxMoneyException)

Example 40 with Trade

use of com.earth2me.essentials.Trade in project Essentials by drtshock.

the class Commandsell method sellItem.

private BigDecimal sellItem(User user, ItemStack is, String[] args, boolean isBulkSell) throws Exception {
    int amount = ess.getWorth().getAmount(ess, user, is, args, isBulkSell);
    BigDecimal worth = ess.getWorth().getPrice(is);
    if (worth == null) {
        throw new Exception(tl("itemCannotBeSold"));
    }
    if (amount <= 0) {
        if (!isBulkSell) {
            user.sendMessage(tl("itemSold", NumberUtil.displayCurrency(BigDecimal.ZERO, ess), BigDecimal.ZERO, is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(worth, ess)));
        }
        return BigDecimal.ZERO;
    }
    BigDecimal result = worth.multiply(BigDecimal.valueOf(amount));
    //TODO: Prices for Enchantments
    final ItemStack ris = is.clone();
    ris.setAmount(amount);
    if (!user.getBase().getInventory().containsAtLeast(ris, amount)) {
        // This should never happen.
        throw new IllegalStateException("Trying to remove more items than are available.");
    }
    user.getBase().getInventory().removeItem(ris);
    user.getBase().updateInventory();
    Trade.log("Command", "Sell", "Item", user.getName(), new Trade(ris, ess), user.getName(), new Trade(result, ess), user.getLocation(), ess);
    user.giveMoney(result);
    user.sendMessage(tl("itemSold", NumberUtil.displayCurrency(result, ess), amount, is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(worth, ess)));
    logger.log(Level.INFO, tl("itemSoldConsole", user.getDisplayName(), is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess)));
    return result;
}
Also used : Trade(com.earth2me.essentials.Trade) ItemStack(org.bukkit.inventory.ItemStack) BigDecimal(java.math.BigDecimal)

Aggregations

Trade (com.earth2me.essentials.Trade)43 ItemStack (org.bukkit.inventory.ItemStack)13 ChargeException (com.earth2me.essentials.ChargeException)10 BigDecimal (java.math.BigDecimal)9 Location (org.bukkit.Location)9 User (com.earth2me.essentials.User)7 NoChargeException (com.earth2me.essentials.commands.NoChargeException)2 MaxMoneyException (net.ess3.api.MaxMoneyException)2 Kit (com.earth2me.essentials.Kit)1 Mob (com.earth2me.essentials.Mob)1 Teleport (com.earth2me.essentials.Teleport)1 Commandrepair (com.earth2me.essentials.commands.Commandrepair)1 NotEnoughArgumentsException (com.earth2me.essentials.commands.NotEnoughArgumentsException)1 IText (com.earth2me.essentials.textreader.IText)1 KeywordReplacer (com.earth2me.essentials.textreader.KeywordReplacer)1 TextInput (com.earth2me.essentials.textreader.TextInput)1 TextPager (com.earth2me.essentials.textreader.TextPager)1 IOException (java.io.IOException)1 List (java.util.List)1 World (org.bukkit.World)1