Search in sources :

Example 1 with InvalidUsage

use of com.iCo6.command.exceptions.InvalidUsage in project Core by iConomy.

the class Status method perform.

@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
    if (!hasPermissions(sender, "status"))
        throw new InvalidUsage("You do not have permission to do that.");
    String name = arguments.get("name").getStringValue();
    String tag = template.color(Template.Node.TAG_MONEY);
    boolean self = false;
    if (!isConsole(sender))
        if (((Player) sender).getName().equalsIgnoreCase(name))
            self = true;
    if (name.equals("0"))
        throw new InvalidUsage("Missing <white>name<rose>: /money status <name> (new status)");
    if (!Accounts.exists(name)) {
        template.set(Template.Node.ERROR_ACCOUNT);
        template.add("name", name);
        Messaging.send(sender, tag + template.parse());
        return false;
    }
    Account account = new Account(name);
    if (arguments.get("status").getStringValue().equalsIgnoreCase("empty")) {
        int current = account.getStatus();
        if (self)
            template.set(Template.Node.PERSONAL_STATUS);
        else {
            template.set(Template.Node.PLAYER_STATUS);
            template.add("name", name);
        }
        template.add("status", current);
        Messaging.send(sender, tag + template.parse());
    } else {
        if (!hasPermissions(sender, "status+"))
            throw new InvalidUsage("You do not have permission to do that.");
        int status = arguments.get("status").getIntegerValue();
        account.setStatus(status);
        template.set(Template.Node.ACCOUNTS_STATUS);
        template.add("status", status);
        Messaging.send(sender, tag + template.parse());
    }
    return false;
}
Also used : InvalidUsage(com.iCo6.command.exceptions.InvalidUsage) Account(com.iCo6.system.Account) Player(org.bukkit.entity.Player)

Example 2 with InvalidUsage

use of com.iCo6.command.exceptions.InvalidUsage in project Core by iConomy.

the class Top method perform.

@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
    if (!hasPermissions(sender, "top"))
        throw new InvalidUsage("You do not have permission to do that.");
    template.set(Template.Node.TOP_OPENING);
    Messaging.send(sender, template.parse());
    template.set(Template.Node.TOP_ITEM);
    List<Account> top = Accounts.getTopAccounts(5);
    for (int i = 0; i < top.size(); i++) {
        Account account = top.get(i);
        template.add("i", i + 1);
        template.add("name", account.name);
        template.add("amount", account.getHoldings().toString());
        Messaging.send(sender, template.parse());
    }
    return false;
}
Also used : InvalidUsage(com.iCo6.command.exceptions.InvalidUsage) Account(com.iCo6.system.Account)

Example 3 with InvalidUsage

use of com.iCo6.command.exceptions.InvalidUsage in project Core by iConomy.

the class iConomy method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    Handler handler = Commands.getHandler(command.getName());
    String split = "/" + command.getName().toLowerCase();
    for (int i = 0; i < args.length; i++) {
        split = split + " " + args[i];
    }
    Messaging.save(sender);
    Commands.save(split);
    Commands.parse();
    if (Commands.getHandler() != null)
        handler = Commands.getHandler();
    if (handler == null)
        return false;
    try {
        return handler.perform(sender, Commands.getArguments());
    } catch (InvalidUsage ex) {
        Messaging.send(sender, ex.getMessage());
        return false;
    }
}
Also used : InvalidUsage(com.iCo6.command.exceptions.InvalidUsage) ResultSetHandler(com.iCo6.util.org.apache.commons.dbutils.ResultSetHandler) Handler(com.iCo6.command.Handler)

Example 4 with InvalidUsage

use of com.iCo6.command.exceptions.InvalidUsage in project Core by iConomy.

the class Give method perform.

@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
    if (!hasPermissions(sender, "give"))
        throw new InvalidUsage("You do not have permission to do that.");
    String name = arguments.get("name").getStringValue();
    String tag = template.color(Template.Node.TAG_MONEY);
    Double amount;
    if (name.equals("0"))
        throw new InvalidUsage("Missing <white>name<rose>: /money give <name> <amount>");
    if (arguments.get("amount").getStringValue().equals("empty"))
        throw new InvalidUsage("Missing <white>amount<rose>: /money give <name> <amount>");
    try {
        amount = arguments.get("amount").getDoubleValue();
    } catch (NumberFormatException e) {
        throw new InvalidUsage("Invalid <white>amount<rose>, must be double.");
    }
    if (Double.isInfinite(amount) || Double.isNaN(amount))
        throw new InvalidUsage("Invalid <white>amount<rose>, must be double.");
    if (!Accounts.exists(name)) {
        template.set(Template.Node.ERROR_ACCOUNT);
        template.add("name", name);
        Messaging.send(sender, tag + template.parse());
        return false;
    }
    Account account = new Account(name);
    account.getHoldings().add(amount);
    template.set(Template.Node.PLAYER_CREDIT);
    template.add("name", name);
    template.add("amount", iConomy.format(amount));
    Messaging.send(sender, tag + template.parse());
    return false;
}
Also used : InvalidUsage(com.iCo6.command.exceptions.InvalidUsage) Account(com.iCo6.system.Account)

Example 5 with InvalidUsage

use of com.iCo6.command.exceptions.InvalidUsage in project Core by iConomy.

the class Help method perform.

@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
    if (!hasPermissions(sender, "help"))
        throw new InvalidUsage("You do not have permission to do that.");
    // TODO: add support for checking help on single command.
    Messaging.send(sender, "`w ");
    Messaging.send(sender, "`w iConomy (`y" + Constants.Nodes.CodeName.toString() + "`w)");
    Messaging.send(sender, "`w ");
    Messaging.send(sender, "`S [] `wRequired, `S() `sOptional");
    Messaging.send(sender, "`w ");
    for (String action : plugin.Commands.getHelp().keySet()) {
        if (!hasPermissions(sender, action))
            continue;
        String description = plugin.Commands.getHelp(action)[1];
        String command = "";
        if (action.equalsIgnoreCase("money") || action.equalsIgnoreCase("money+"))
            command = "/money `w" + plugin.Commands.getHelp(action)[0] + "`s";
        else
            command = "/money `w" + action + plugin.Commands.getHelp(action)[0] + "`s";
        command = command.replace("[", "`S[`s").replace("]", "`S]").replace("(", "`S(");
        Messaging.send(sender, String.format("   %1$s `Y-`y %2$s", command, description));
    }
    return false;
}
Also used : InvalidUsage(com.iCo6.command.exceptions.InvalidUsage)

Aggregations

InvalidUsage (com.iCo6.command.exceptions.InvalidUsage)13 Account (com.iCo6.system.Account)7 Player (org.bukkit.entity.Player)3 Handler (com.iCo6.command.Handler)1 Holdings (com.iCo6.system.Holdings)1 ResultSetHandler (com.iCo6.util.org.apache.commons.dbutils.ResultSetHandler)1