Search in sources :

Example 51 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 52 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 53 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 54 with Trade

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

the class Commandspawner method run.

@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    if (args.length < 1 || args[0].length() < 2) {
        throw new NotEnoughArgumentsException(tl("mobsAvailable", StringUtil.joinList(Mob.getMobList())));
    }
    final Location target = LocationUtil.getTarget(user.getBase());
    if (target == null || target.getBlock().getType() != Material.MOB_SPAWNER) {
        throw new Exception(tl("mobSpawnTarget"));
    }
    String name = args[0];
    int delay = 0;
    Mob mob = null;
    mob = Mob.fromName(name);
    if (mob == null) {
        throw new Exception(tl("invalidMob"));
    }
    if (ess.getSettings().getProtectPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH))) {
        throw new Exception(tl("disabledToSpawnMob"));
    }
    if (!user.isAuthorized("essentials.spawner." + mob.name.toLowerCase(Locale.ENGLISH))) {
        throw new Exception(tl("noPermToSpawnMob"));
    }
    if (args.length > 1) {
        if (NumberUtil.isInt(args[1])) {
            delay = Integer.parseInt(args[1]);
        }
    }
    final Trade charge = new Trade("spawner-" + mob.name.toLowerCase(Locale.ENGLISH), ess);
    charge.isAffordableFor(user);
    try {
        CreatureSpawner spawner = (CreatureSpawner) target.getBlock().getState();
        spawner.setSpawnedType(mob.getType());
        spawner.setDelay(delay);
        spawner.update();
    } catch (Throwable ex) {
        throw new Exception(tl("mobSpawnError"), ex);
    }
    charge.charge(user);
    user.sendMessage(tl("setSpawner", mob.name));
}
Also used : Mob(com.earth2me.essentials.Mob) Trade(com.earth2me.essentials.Trade) Location(org.bukkit.Location) CreatureSpawner(org.bukkit.block.CreatureSpawner)

Example 55 with Trade

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

the class Commandrepair method repairHand.

public void repairHand(User user) throws Exception {
    final ItemStack item = user.getBase().getItemInHand();
    if (item == null || item.getType().isBlock() || item.getDurability() == 0) {
        throw new Exception(tl("repairInvalidType"));
    }
    if (!item.getEnchantments().isEmpty() && !ess.getSettings().getRepairEnchanted() && !user.isAuthorized("essentials.repair.enchanted")) {
        throw new Exception(tl("repairEnchanted"));
    }
    final String itemName = item.getType().toString().toLowerCase(Locale.ENGLISH);
    final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), new Trade("repair-" + item.getTypeId(), new Trade("repair-item", ess), ess), ess);
    charge.isAffordableFor(user);
    repairItem(item);
    charge.charge(user);
    user.getBase().updateInventory();
    user.sendMessage(tl("repair", itemName.replace('_', ' ')));
}
Also used : Trade(com.earth2me.essentials.Trade) ItemStack(org.bukkit.inventory.ItemStack) ChargeException(com.earth2me.essentials.ChargeException)

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