Search in sources :

Example 81 with Trade

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

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 82 with Trade

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

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 83 with Trade

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

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) {
        World w = ess.getWorld(args[3]);
        if (user.getWorld() != w && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + w.getName())) {
            throw new Exception(tl("noPerm", "essentials.worlds." + w.getName()));
        }
        loc.setWorld(w);
    }
    if (args.length > 4) {
        loc.setYaw((FloatUtil.parseFloat(args[3]) + 360) % 360);
        loc.setPitch(FloatUtil.parseFloat(args[4]));
    }
    if (args.length > 5) {
        World w = ess.getWorld(args[5]);
        if (user.getWorld() != w && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + w.getName())) {
            throw new Exception(tl("noPerm", "essentials.worlds." + w.getName()));
        }
        loc.setWorld(w);
    }
    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) World(org.bukkit.World) Location(org.bukkit.Location)

Example 84 with Trade

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

the class Economy method resetBalance.

/**
 * Resets the balance of a user to the starting balance
 *
 * @param name Name of the user
 *
 * @throws UserDoesNotExistException If a user by that name does not exists
 * @throws NoLoanPermittedException  If the user is not allowed to have a negative balance
 */
public static void resetBalance(String name) throws UserDoesNotExistException, NoLoanPermittedException {
    if (ess == null) {
        throw new RuntimeException(noCallBeforeLoad);
    }
    setMoney(name, ess.getSettings().getStartingBalance());
    Trade.log("API", "Reset", "API", name, new Trade(BigDecimal.ZERO, ess), null, null, null, ess);
}
Also used : Trade(com.earth2me.essentials.Trade)

Example 85 with Trade

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

the class Economy method setMoney.

public static void setMoney(String name, BigDecimal balance) throws UserDoesNotExistException, NoLoanPermittedException {
    User user = getUserByName(name);
    if (user == null) {
        throw new UserDoesNotExistException(name);
    }
    if (balance.compareTo(ess.getSettings().getMinMoney()) < 0) {
        throw new NoLoanPermittedException();
    }
    if (balance.signum() < 0 && !user.isAuthorized("essentials.eco.loan")) {
        throw new NoLoanPermittedException();
    }
    try {
        user.setMoney(balance);
    } catch (MaxMoneyException ex) {
    // TODO: Update API to show max balance errors
    }
    Trade.log("API", "Set", "API", name, new Trade(balance, ess), null, null, null, ess);
}
Also used : Trade(com.earth2me.essentials.Trade) User(com.earth2me.essentials.User) MaxMoneyException(net.ess3.api.MaxMoneyException)

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