Search in sources :

Example 21 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 22 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)

Example 23 with Trade

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

the class Commandjump method run.

@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    if (args.length > 0 && args[0].contains("lock") && user.isAuthorized("essentials.jump.lock")) {
        if (user.isFlyClickJump()) {
            user.setRightClickJump(false);
            user.sendMessage("Flying wizard mode disabled");
        } else {
            user.setRightClickJump(true);
            user.sendMessage("Enabling flying wizard mode");
        }
        return;
    }
    Location loc;
    final Location cloc = user.getLocation();
    try {
        loc = LocationUtil.getTarget(user.getBase());
        loc.setYaw(cloc.getYaw());
        loc.setPitch(cloc.getPitch());
        loc.setY(loc.getY() + 1);
    } catch (NullPointerException ex) {
        throw new Exception(tl("jumpError"), ex);
    }
    final Trade charge = new Trade(this.getName(), ess);
    charge.isAffordableFor(user);
    user.getTeleport().teleport(loc, charge, TeleportCause.COMMAND);
    throw new NoChargeException();
}
Also used : Trade(com.earth2me.essentials.Trade) Location(org.bukkit.Location)

Example 24 with Trade

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

the class SignInfo 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, 3, ess);
    charge.isAffordableFor(player);
    String chapter = sign.getLine(1);
    String page = sign.getLine(2);
    final IText input;
    try {
        player.setDisplayNick();
        input = new TextInput(player.getSource(), "info", true, ess);
        final IText output = new KeywordReplacer(input, player.getSource(), ess);
        final TextPager pager = new TextPager(output);
        pager.showPage(chapter, page, null, player.getSource());
    } catch (IOException ex) {
        throw new SignException(ex.getMessage(), ex);
    }
    charge.charge(player);
    Trade.log("Sign", "Info", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
    return true;
}
Also used : KeywordReplacer(com.earth2me.essentials.textreader.KeywordReplacer) Trade(com.earth2me.essentials.Trade) TextPager(com.earth2me.essentials.textreader.TextPager) IText(com.earth2me.essentials.textreader.IText) IOException(java.io.IOException) TextInput(com.earth2me.essentials.textreader.TextInput)

Example 25 with Trade

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

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