Search in sources :

Example 46 with Trade

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

the class SignTrade method getTrade.

protected final Trade getTrade(final ISign sign, final int index, final AmountType amountType, final boolean notEmpty, final IEssentials ess) throws SignException {
    final String line = sign.getLine(index).trim();
    if (line.isEmpty()) {
        throw new SignException("Empty line");
    }
    final String[] split = line.split("[ :]+");
    if (split.length == 2) {
        try {
            final BigDecimal money = getMoney(split[0]);
            final BigDecimal amount = notEmpty ? getBigDecimalPositive(split[1]) : getBigDecimal(split[1]);
            if (money != null && amount != null) {
                return new Trade(amountType == AmountType.COST ? money : amount, ess);
            }
        } catch (SignException e) {
            throw new SignException(tl("tradeSignEmpty"), e);
        }
    }
    if (split.length == 3) {
        if (split[1].equalsIgnoreCase("exp") || split[1].equalsIgnoreCase("xp")) {
            final int stackamount = getIntegerPositive(split[0]);
            int amount = getInteger(split[2]);
            if (amountType == AmountType.ROUNDED) {
                amount -= amount % stackamount;
            }
            if (notEmpty && (amount < 1 || stackamount < 1)) {
                throw new SignException(tl("tradeSignEmpty"));
            }
            return new Trade((amountType == AmountType.COST ? stackamount : amount), ess);
        } else {
            final int stackamount = getIntegerPositive(split[0]);
            final ItemStack item = getItemStack(split[1], stackamount, ess);
            int amount = getInteger(split[2]);
            if (amountType == AmountType.ROUNDED) {
                amount -= amount % stackamount;
            }
            if (notEmpty && (amount < 1 || stackamount < 1 || item.getType() == Material.AIR || amount < stackamount)) {
                throw new SignException(tl("tradeSignEmpty"));
            }
            item.setAmount(amountType == AmountType.COST ? stackamount : amount);
            return new Trade(item, ess);
        }
    }
    throw new SignException(tl("invalidSignLine", index + 1));
}
Also used : Trade(com.earth2me.essentials.Trade) ItemStack(org.bukkit.inventory.ItemStack) BigDecimal(java.math.BigDecimal)

Example 47 with Trade

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

the class SignWarp method onSignInteract.

@Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException {
    final String warpName = sign.getLine(1);
    final String group = sign.getLine(2);
    if ((!group.isEmpty() && ("ยง2Everyone".equals(group) || player.inGroup(group))) || (group.isEmpty() && (!ess.getSettings().getPerWarpPermission() || player.isAuthorized("essentials.warps." + warpName)))) {
        final Trade charge = getTrade(sign, 3, ess);
        try {
            player.getTeleport().warp(player, warpName, charge, TeleportCause.PLUGIN);
            Trade.log("Sign", "Warp", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
        } catch (Exception ex) {
            throw new SignException(ex.getMessage(), ex);
        }
        return true;
    }
    return false;
}
Also used : Trade(com.earth2me.essentials.Trade) ChargeException(com.earth2me.essentials.ChargeException)

Example 48 with Trade

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

the class Commandcondense method condenseStack.

private boolean condenseStack(final User user, final ItemStack stack, final boolean validateReverse) throws ChargeException, MaxMoneyException {
    final SimpleRecipe condenseType = getCondenseType(stack);
    if (condenseType != null) {
        final ItemStack input = condenseType.getInput();
        final ItemStack result = condenseType.getResult();
        if (validateReverse) {
            boolean pass = false;
            for (Recipe revRecipe : ess.getServer().getRecipesFor(input)) {
                if (getStackOnRecipeMatch(revRecipe, result) != null) {
                    pass = true;
                    break;
                }
            }
            if (!pass) {
                return false;
            }
        }
        int amount = 0;
        for (final ItemStack contents : user.getBase().getInventory().getContents()) {
            if (contents != null && contents.isSimilar(stack)) {
                amount += contents.getAmount();
            }
        }
        int output = ((amount / input.getAmount()) * result.getAmount());
        amount -= amount % input.getAmount();
        if (amount > 0) {
            input.setAmount(amount);
            result.setAmount(output);
            final Trade remove = new Trade(input, ess);
            final Trade add = new Trade(result, ess);
            remove.charge(user);
            add.pay(user, OverflowType.DROP);
            return true;
        }
    }
    return false;
}
Also used : Trade(com.earth2me.essentials.Trade) ShapelessRecipe(org.bukkit.inventory.ShapelessRecipe) ShapedRecipe(org.bukkit.inventory.ShapedRecipe) Recipe(org.bukkit.inventory.Recipe) ItemStack(org.bukkit.inventory.ItemStack)

Example 49 with Trade

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

the class Economy method multiply.

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

Example 50 with Trade

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

the class Economy method add.

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

Aggregations

Trade (com.earth2me.essentials.Trade)86 ItemStack (org.bukkit.inventory.ItemStack)26 ChargeException (com.earth2me.essentials.ChargeException)20 BigDecimal (java.math.BigDecimal)18 Location (org.bukkit.Location)18 User (com.earth2me.essentials.User)14 NoChargeException (com.earth2me.essentials.commands.NoChargeException)4 MaxMoneyException (net.ess3.api.MaxMoneyException)4 World (org.bukkit.World)4 Kit (com.earth2me.essentials.Kit)2 Mob (com.earth2me.essentials.Mob)2 Teleport (com.earth2me.essentials.Teleport)2 Commandrepair (com.earth2me.essentials.commands.Commandrepair)2 NotEnoughArgumentsException (com.earth2me.essentials.commands.NotEnoughArgumentsException)2 IText (com.earth2me.essentials.textreader.IText)2 KeywordReplacer (com.earth2me.essentials.textreader.KeywordReplacer)2 TextInput (com.earth2me.essentials.textreader.TextInput)2 TextPager (com.earth2me.essentials.textreader.TextPager)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2