Search in sources :

Example 1 with Trade

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

the class Commandback method run.

@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    if (user.getLastLocation() == null) {
        throw new Exception(tl("noLocationFound"));
    }
    if (user.getWorld() != user.getLastLocation().getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + user.getLastLocation().getWorld().getName())) {
        throw new Exception(tl("noPerm", "essentials.worlds." + user.getLastLocation().getWorld().getName()));
    }
    final Trade charge = new Trade(this.getName(), ess);
    charge.isAffordableFor(user);
    user.getTeleport().back(charge);
    throw new NoChargeException();
}
Also used : Trade(com.earth2me.essentials.Trade)

Example 2 with Trade

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

the class SignKit method onSignInteract.

@Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException {
    final String kitName = sign.getLine(1).toLowerCase(Locale.ENGLISH).trim();
    final String group = sign.getLine(2).trim();
    if ((!group.isEmpty() && ("ยง2Everyone".equals(group) || player.inGroup(group))) || (group.isEmpty() && (player.isAuthorized("essentials.kits." + kitName)))) {
        final Trade charge = getTrade(sign, 3, ess);
        charge.isAffordableFor(player);
        try {
            final Kit kit = new Kit(kitName, ess);
            kit.checkDelay(player);
            kit.setTime(player);
            kit.expandItems(player);
            charge.charge(player);
            Trade.log("Sign", "Kit", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
        } catch (NoChargeException ex) {
            return false;
        } catch (Exception ex) {
            throw new SignException(ex.getMessage(), ex);
        }
        return true;
    } else {
        if (group.isEmpty()) {
            throw new SignException(tl("noKitPermission", "essentials.kits." + kitName));
        } else {
            throw new SignException(tl("noKitGroup", group));
        }
    }
}
Also used : Trade(com.earth2me.essentials.Trade) NoChargeException(com.earth2me.essentials.commands.NoChargeException) Kit(com.earth2me.essentials.Kit) NoChargeException(com.earth2me.essentials.commands.NoChargeException) ChargeException(com.earth2me.essentials.ChargeException)

Example 3 with Trade

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

the class SignProtection method checkIfSignsAreBroken.

private void checkIfSignsAreBroken(final Block block, final User player, final String username, final IEssentials ess) throws MaxMoneyException {
    final Map<Location, SignProtectionState> signs = getConnectedSigns(block, player, username, false);
    for (Map.Entry<Location, SignProtectionState> entry : signs.entrySet()) {
        if (entry.getValue() != SignProtectionState.NOSIGN) {
            final Block sign = entry.getKey().getBlock();
            if (!hasAdjacentBlock(sign, block)) {
                block.setType(Material.AIR);
                final Trade trade = new Trade(new ItemStack(Material.SIGN, 1), ess);
                trade.pay(player, OverflowType.DROP);
            }
        }
    }
}
Also used : Trade(com.earth2me.essentials.Trade) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location)

Example 4 with Trade

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

the class Commandworld method run.

@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    World world;
    if (args.length < 1) {
        World nether = null;
        final List<World> worlds = server.getWorlds();
        for (World world2 : worlds) {
            if (world2.getEnvironment() == World.Environment.NETHER) {
                nether = world2;
                break;
            }
        }
        if (nether == null) {
            return;
        }
        world = user.getWorld() == nether ? worlds.get(0) : nether;
    } else {
        world = ess.getWorld(getFinalArg(args, 0));
        if (world == null) {
            user.sendMessage(tl("invalidWorld"));
            user.sendMessage(tl("possibleWorlds", server.getWorlds().size() - 1));
            user.sendMessage(tl("typeWorldName"));
            throw new NoChargeException();
        }
    }
    if (ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + world.getName())) {
        throw new Exception(tl("noPerm", "essentials.worlds." + world.getName()));
    }
    double factor;
    if (user.getWorld().getEnvironment() == World.Environment.NETHER && world.getEnvironment() == World.Environment.NORMAL) {
        factor = 8.0;
    } else if (user.getWorld().getEnvironment() == World.Environment.NORMAL && world.getEnvironment() == World.Environment.NETHER) {
        factor = 1.0 / 8.0;
    } else {
        factor = 1.0;
    }
    final Location loc = user.getLocation();
    final Location target = new Location(world, loc.getBlockX() * factor + .5, loc.getBlockY(), loc.getBlockZ() * factor + .5);
    final Trade charge = new Trade(this.getName(), ess);
    charge.isAffordableFor(user);
    user.getTeleport().teleport(target, charge, TeleportCause.COMMAND);
    throw new NoChargeException();
}
Also used : Trade(com.earth2me.essentials.Trade) World(org.bukkit.World) Location(org.bukkit.Location)

Example 5 with Trade

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

the class SignSell method onSignInteract.

@Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException, MaxMoneyException {
    Trade charge = getTrade(sign, 1, 2, player, ess);
    Trade money = getTrade(sign, 3, ess);
    // Check if the player is trying to sell in bulk.
    if (ess.getSettings().isAllowBulkBuySell() && player.getBase().isSneaking()) {
        ItemStack heldItem = player.getItemInHand();
        if (charge.getItemStack().isSimilar(heldItem)) {
            int initialItemAmount = charge.getItemStack().getAmount();
            int newItemAmount = heldItem.getAmount();
            ItemStack item = charge.getItemStack();
            item.setAmount(newItemAmount);
            charge = new Trade(item, ess);
            BigDecimal chargeAmount = money.getMoney();
            BigDecimal pricePerSingleItem = chargeAmount.divide(new BigDecimal(initialItemAmount));
            pricePerSingleItem = pricePerSingleItem.multiply(new BigDecimal(newItemAmount));
            money = new Trade(pricePerSingleItem, ess);
        }
    }
    charge.isAffordableFor(player);
    money.pay(player, OverflowType.DROP);
    charge.charge(player);
    Trade.log("Sign", "Sell", "Interact", username, charge, username, money, sign.getBlock().getLocation(), ess);
    return true;
}
Also used : Trade(com.earth2me.essentials.Trade) ItemStack(org.bukkit.inventory.ItemStack) BigDecimal(java.math.BigDecimal)

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