Search in sources :

Example 11 with Trade

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

the class Commandrepair method repairItems.

private void repairItems(final ItemStack[] items, final IUser user, final List<String> repaired) {
    for (ItemStack item : items) {
        if (item == null || item.getType().isBlock() || item.getDurability() == 0) {
            continue;
        }
        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);
        try {
            charge.isAffordableFor(user);
        } catch (ChargeException ex) {
            user.sendMessage(ex.getMessage());
            continue;
        }
        if (!item.getEnchantments().isEmpty() && !ess.getSettings().getRepairEnchanted() && !user.isAuthorized("essentials.repair.enchanted")) {
            continue;
        }
        try {
            repairItem(item);
        } catch (Exception e) {
            continue;
        }
        try {
            charge.charge(user);
        } catch (ChargeException ex) {
            user.sendMessage(ex.getMessage());
        }
        repaired.add(itemName.replace('_', ' '));
    }
}
Also used : Trade(com.earth2me.essentials.Trade) ItemStack(org.bukkit.inventory.ItemStack) ChargeException(com.earth2me.essentials.ChargeException) ChargeException(com.earth2me.essentials.ChargeException)

Example 12 with Trade

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

the class Commandtpaccept method run.

@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    final User requester;
    try {
        requester = ess.getUser(user.getTeleportRequest());
    } catch (Exception ex) {
        throw new Exception(tl("noPendingRequest"));
    }
    if (!requester.getBase().isOnline()) {
        throw new Exception(tl("noPendingRequest"));
    }
    if (user.isTpRequestHere() && ((!requester.isAuthorized("essentials.tpahere") && !requester.isAuthorized("essentials.tpaall")) || (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + user.getWorld().getName())))) {
        throw new Exception(tl("noPendingRequest"));
    }
    if (!user.isTpRequestHere() && (!requester.isAuthorized("essentials.tpa") || (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + requester.getWorld().getName())))) {
        throw new Exception(tl("noPendingRequest"));
    }
    if (args.length > 0 && !requester.getName().contains(args[0])) {
        throw new Exception(tl("noPendingRequest"));
    }
    if (!user.hasOutstandingTeleportRequest()) {
        user.requestTeleport(null, false);
        throw new Exception(tl("requestTimedOut"));
    }
    final Trade charge = new Trade(this.getName(), ess);
    user.sendMessage(tl("requestAccepted"));
    requester.sendMessage(tl("requestAcceptedFrom", user.getDisplayName()));
    try {
        if (user.isTpRequestHere()) {
            final Location loc = user.getTpRequestLocation();
            Teleport teleport = requester.getTeleport();
            teleport.setTpType(Teleport.TeleportType.TPA);
            teleport.teleportPlayer(user, user.getTpRequestLocation(), charge, TeleportCause.COMMAND);
            requester.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
        } else {
            Teleport teleport = requester.getTeleport();
            teleport.setTpType(Teleport.TeleportType.TPA);
            teleport.teleport(user.getBase(), charge, TeleportCause.COMMAND);
        }
    } catch (Exception ex) {
        user.sendMessage(tl("pendingTeleportCancelled"));
        ess.showError(requester.getSource(), ex, commandLabel);
    }
    user.requestTeleport(null, false);
    throw new NoChargeException();
}
Also used : Trade(com.earth2me.essentials.Trade) User(com.earth2me.essentials.User) Teleport(com.earth2me.essentials.Teleport) Location(org.bukkit.Location)

Example 13 with Trade

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

the class Commandtphere method run.

@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    final User player = getPlayer(server, user, args, 0);
    if (!player.isTeleportEnabled()) {
        throw new Exception(tl("teleportDisabled", player.getDisplayName()));
    }
    if (user.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + user.getWorld().getName())) {
        throw new Exception(tl("noPerm", "essentials.worlds." + user.getWorld().getName()));
    }
    user.getTeleport().teleportPlayer(player, user.getBase(), new Trade(this.getName(), ess), TeleportCause.COMMAND);
    throw new NoChargeException();
}
Also used : Trade(com.earth2me.essentials.Trade) User(com.earth2me.essentials.User)

Example 14 with Trade

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

the class Commandtppos method run.

@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    if (args.length < 3) {
        throw new NotEnoughArgumentsException();
    }
    final double x = args[0].startsWith("~") ? user.getLocation().getX() + (args[0].length() > 1 ? Integer.parseInt(args[0].substring(1)) : 0) : Integer.parseInt(args[0]);
    final double y = args[1].startsWith("~") ? user.getLocation().getY() + (args[1].length() > 1 ? Integer.parseInt(args[1].substring(1)) : 0) : Integer.parseInt(args[1]);
    final double z = args[2].startsWith("~") ? user.getLocation().getZ() + (args[2].length() > 1 ? Integer.parseInt(args[2].substring(1)) : 0) : Integer.parseInt(args[2]);
    final Location loc = new Location(user.getWorld(), x, y, z, user.getLocation().getYaw(), user.getLocation().getPitch());
    if (args.length == 4) {
        loc.setWorld(ess.getWorld(args[3]));
    }
    if (args.length > 4) {
        loc.setYaw((FloatUtil.parseFloat(args[3]) + 360) % 360);
        loc.setPitch(FloatUtil.parseFloat(args[4]));
    }
    if (args.length > 5) {
        loc.setWorld(ess.getWorld(args[5]));
    }
    if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000) {
        throw new NotEnoughArgumentsException(tl("teleportInvalidLocation"));
    }
    final Trade charge = new Trade(this.getName(), ess);
    charge.isAffordableFor(user);
    user.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
    user.getTeleport().teleport(loc, charge, TeleportCause.COMMAND);
    throw new NoChargeException();
}
Also used : Trade(com.earth2me.essentials.Trade) Location(org.bukkit.Location)

Example 15 with Trade

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

the class SignWeather 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);
    final String weatherString = sign.getLine(1);
    if ("§2Sun".equalsIgnoreCase(weatherString)) {
        player.getWorld().setStorm(false);
        charge.charge(player);
        Trade.log("Sign", "WeatherSun", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
        return true;
    }
    if ("§2Storm".equalsIgnoreCase(weatherString)) {
        player.getWorld().setStorm(true);
        charge.charge(player);
        Trade.log("Sign", "WeatherStorm", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
        return true;
    }
    throw new SignException(tl("onlySunStorm"));
}
Also used : Trade(com.earth2me.essentials.Trade)

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