Search in sources :

Example 6 with ChargeException

use of com.earth2me.essentials.ChargeException 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 7 with ChargeException

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

the class SignRepair method onSignInteract.

@Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException {
    final Trade charge = getTrade(sign, 2, ess);
    charge.isAffordableFor(player);
    Commandrepair command = new Commandrepair();
    command.setEssentials(ess);
    try {
        if (sign.getLine(1).equalsIgnoreCase("hand")) {
            command.repairHand(player);
        } else if (sign.getLine(1).equalsIgnoreCase("all")) {
            command.repairAll(player);
        } else {
            throw new NotEnoughArgumentsException();
        }
    } catch (Exception ex) {
        throw new SignException(ex.getMessage(), ex);
    }
    charge.charge(player);
    Trade.log("Sign", "Repair", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
    return true;
}
Also used : Trade(com.earth2me.essentials.Trade) Commandrepair(com.earth2me.essentials.commands.Commandrepair) NotEnoughArgumentsException(com.earth2me.essentials.commands.NotEnoughArgumentsException) NotEnoughArgumentsException(com.earth2me.essentials.commands.NotEnoughArgumentsException) ChargeException(com.earth2me.essentials.ChargeException)

Example 8 with ChargeException

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

the class SignEnchant method onSignInteract.

@Override
protected boolean onSignInteract(ISign sign, User player, String username, IEssentials ess) throws SignException, ChargeException {
    final ItemStack search = sign.getLine(1).equals("*") || sign.getLine(1).equalsIgnoreCase("any") ? null : getItemStack(sign.getLine(1), 1, ess);
    final Trade charge = getTrade(sign, 3, ess);
    charge.isAffordableFor(player);
    final String[] enchantLevel = sign.getLine(2).split(":");
    if (enchantLevel.length != 2) {
        throw new SignException(tl("invalidSignLine", 3));
    }
    final Enchantment enchantment = Enchantments.getByName(enchantLevel[0]);
    if (enchantment == null) {
        throw new SignException(tl("enchantmentNotFound"));
    }
    int level;
    try {
        level = Integer.parseInt(enchantLevel[1]);
    } catch (NumberFormatException ex) {
        level = enchantment.getMaxLevel();
    }
    final ItemStack playerHand = player.getBase().getItemInHand();
    if (playerHand == null || playerHand.getAmount() != 1 || (playerHand.containsEnchantment(enchantment) && playerHand.getEnchantmentLevel(enchantment) == level)) {
        throw new SignException(tl("missingItems", 1, sign.getLine(1)));
    }
    if (search != null && playerHand.getType() != search.getType()) {
        throw new SignException(tl("missingItems", 1, search.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' ')));
    }
    final ItemStack toEnchant = playerHand;
    try {
        if (level == 0) {
            toEnchant.removeEnchantment(enchantment);
        } else {
            if (ess.getSettings().allowUnsafeEnchantments() && player.isAuthorized("essentials.signs.enchant.allowunsafe")) {
                toEnchant.addUnsafeEnchantment(enchantment, level);
            } else {
                toEnchant.addEnchantment(enchantment, level);
            }
        }
    } catch (Exception ex) {
        throw new SignException(ex.getMessage(), ex);
    }
    final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
    if (level == 0) {
        player.sendMessage(tl("enchantmentRemoved", enchantmentName.replace('_', ' ')));
    } else {
        player.sendMessage(tl("enchantmentApplied", enchantmentName.replace('_', ' ')));
    }
    charge.charge(player);
    Trade.log("Sign", "Enchant", "Interact", username, charge, username, charge, sign.getBlock().getLocation(), ess);
    player.getBase().updateInventory();
    return true;
}
Also used : Trade(com.earth2me.essentials.Trade) ItemStack(org.bukkit.inventory.ItemStack) Enchantment(org.bukkit.enchantments.Enchantment) ChargeException(com.earth2me.essentials.ChargeException)

Example 9 with ChargeException

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

the class SignSpawnmob method onSignInteract.

@Override
protected boolean onSignInteract(ISign sign, User player, String username, IEssentials ess) throws SignException, ChargeException {
    final Trade charge = getTrade(sign, 3, ess);
    charge.isAffordableFor(player);
    try {
        List<String> mobParts = SpawnMob.mobParts(sign.getLine(2));
        List<String> mobData = SpawnMob.mobData(sign.getLine(2));
        SpawnMob.spawnmob(ess, ess.getServer(), player.getSource(), player, mobParts, mobData, Integer.parseInt(sign.getLine(1)));
    } catch (Exception ex) {
        throw new SignException(ex.getMessage(), ex);
    }
    charge.charge(player);
    Trade.log("Sign", "Spawnmob", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
    return true;
}
Also used : Trade(com.earth2me.essentials.Trade) ChargeException(com.earth2me.essentials.ChargeException)

Example 10 with ChargeException

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

Aggregations

ChargeException (com.earth2me.essentials.ChargeException)10 Trade (com.earth2me.essentials.Trade)9 ItemStack (org.bukkit.inventory.ItemStack)4 BigDecimal (java.math.BigDecimal)2 MaxMoneyException (net.ess3.api.MaxMoneyException)2 Kit (com.earth2me.essentials.Kit)1 User (com.earth2me.essentials.User)1 Commandrepair (com.earth2me.essentials.commands.Commandrepair)1 NoChargeException (com.earth2me.essentials.commands.NoChargeException)1 NotEnoughArgumentsException (com.earth2me.essentials.commands.NotEnoughArgumentsException)1 Enchantment (org.bukkit.enchantments.Enchantment)1