Search in sources :

Example 31 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 32 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 33 with Trade

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

the class Economy method resetBalance.

/**
     * Resets the balance of a user to the starting balance
     *
     * @param name Name of the user
     *
     * @throws UserDoesNotExistException If a user by that name does not exists
     * @throws NoLoanPermittedException  If the user is not allowed to have a negative balance
     */
public static void resetBalance(String name) throws UserDoesNotExistException, NoLoanPermittedException {
    if (ess == null) {
        throw new RuntimeException(noCallBeforeLoad);
    }
    setMoney(name, ess.getSettings().getStartingBalance());
    Trade.log("API", "Reset", "API", name, new Trade(BigDecimal.ZERO, ess), null, null, null, ess);
}
Also used : Trade(com.earth2me.essentials.Trade)

Example 34 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 35 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)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