Search in sources :

Example 6 with NotEnoughArgumentsException

use of com.earth2me.essentials.commands.NotEnoughArgumentsException in project Essentials by drtshock.

the class Worth method getAmount.

public int getAmount(IEssentials ess, User user, ItemStack is, String[] args, boolean isBulkSell) throws Exception {
    if (is == null || is.getType() == Material.AIR) {
        throw new Exception(tl("itemSellAir"));
    }
    int id = is.getTypeId();
    int amount = 0;
    if (args.length > 1) {
        try {
            amount = Integer.parseInt(args[1].replaceAll("[^0-9]", ""));
        } catch (NumberFormatException ex) {
            throw new NotEnoughArgumentsException(ex);
        }
        if (args[1].startsWith("-")) {
            amount = -amount;
        }
    }
    boolean stack = args.length > 1 && args[1].endsWith("s");
    boolean requireStack = ess.getSettings().isTradeInStacks(id);
    if (requireStack && !stack) {
        throw new Exception(tl("itemMustBeStacked"));
    }
    int max = 0;
    for (ItemStack s : user.getBase().getInventory().getContents()) {
        if (s == null || !s.isSimilar(is)) {
            continue;
        }
        max += s.getAmount();
    }
    if (stack) {
        amount *= is.getType().getMaxStackSize();
    }
    if (amount < 1) {
        amount += max;
    }
    if (requireStack) {
        amount -= amount % is.getType().getMaxStackSize();
    }
    if (amount > max || amount < 1) {
        if (!isBulkSell) {
            user.sendMessage(tl("itemNotEnough2"));
            user.sendMessage(tl("itemNotEnough3"));
            throw new Exception(tl("itemNotEnough1"));
        } else {
            return amount;
        }
    }
    return amount;
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) NotEnoughArgumentsException(com.earth2me.essentials.commands.NotEnoughArgumentsException) NotEnoughArgumentsException(com.earth2me.essentials.commands.NotEnoughArgumentsException)

Example 7 with NotEnoughArgumentsException

use of com.earth2me.essentials.commands.NotEnoughArgumentsException in project Essentials by drtshock.

the class Commandxmppspy method run.

@Override
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws NotEnoughArgumentsException {
    if (args.length < 1) {
        throw new NotEnoughArgumentsException();
    }
    final List<Player> matches = server.matchPlayer(args[0]);
    if (matches.isEmpty()) {
        sender.sendMessage("§cThere are no players matching that name.");
    }
    for (Player p : matches) {
        try {
            final boolean toggle = EssentialsXMPP.getInstance().toggleSpy(p);
            sender.sendMessage("XMPP Spy " + (toggle ? "enabled" : "disabled") + " for " + p.getDisplayName());
        } catch (Exception ex) {
            sender.sendMessage("Error: " + ex.getMessage());
        }
    }
}
Also used : Player(org.bukkit.entity.Player) NotEnoughArgumentsException(com.earth2me.essentials.commands.NotEnoughArgumentsException) NotEnoughArgumentsException(com.earth2me.essentials.commands.NotEnoughArgumentsException)

Example 8 with NotEnoughArgumentsException

use of com.earth2me.essentials.commands.NotEnoughArgumentsException in project Essentials by EssentialsX.

the class Commandspawn method run.

@Override
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
    if (args.length < 1) {
        throw new NotEnoughArgumentsException();
    }
    final User user = getPlayer(server, args, 0, true, false);
    respawn(sender, null, user, null);
    user.sendMessage(tl("teleportAtoB", Console.NAME, "spawn"));
}
Also used : User(com.earth2me.essentials.User) NotEnoughArgumentsException(com.earth2me.essentials.commands.NotEnoughArgumentsException)

Aggregations

NotEnoughArgumentsException (com.earth2me.essentials.commands.NotEnoughArgumentsException)8 ChargeException (com.earth2me.essentials.ChargeException)2 Trade (com.earth2me.essentials.Trade)2 User (com.earth2me.essentials.User)2 Commandrepair (com.earth2me.essentials.commands.Commandrepair)2 Player (org.bukkit.entity.Player)2 ItemStack (org.bukkit.inventory.ItemStack)2