Search in sources :

Example 6 with InvalidUsage

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

the class Money method perform.

@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
    if (Constants.Nodes.useHoldingsPermission.getBoolean())
        if (!hasPermissions(sender, "money"))
            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);
    if (name.equals("0")) {
        if (isConsole(sender)) {
            Messaging.send(sender, "`rCannot check money on non-living organism.");
            return false;
        }
        Player player = (Player) sender;
        if (player == null)
            return false;
        Account account = new Account(player.getName());
        account.getHoldings().showBalance(null);
        return false;
    }
    if (!hasPermissions(sender, "money+"))
        throw new InvalidUsage("You do not have permission to do that.");
    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().showBalance(sender);
    return false;
}
Also used : InvalidUsage(com.iCo6.command.exceptions.InvalidUsage) Account(com.iCo6.system.Account) Player(org.bukkit.entity.Player)

Example 7 with InvalidUsage

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

the class Purge method perform.

@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
    if (!hasPermissions(sender, "purge"))
        throw new InvalidUsage("You do not have permission to do that.");
    Accounts.purge();
    String tag = template.color(Template.Node.TAG_MONEY);
    template.set(Template.Node.ACCOUNTS_PURGE);
    Messaging.send(sender, tag + template.parse());
    return false;
}
Also used : InvalidUsage(com.iCo6.command.exceptions.InvalidUsage)

Example 8 with InvalidUsage

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

the class Remove method perform.

@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
    if (!hasPermissions(sender, "remove"))
        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);
    if (name.equals("0"))
        throw new InvalidUsage("Missing <white>name<rose>: /money remove <name>");
    if (!Accounts.exists(name)) {
        template.set(Template.Node.ERROR_ACCOUNT);
        template.add("name", name);
        Messaging.send(sender, tag + template.parse());
        return false;
    }
    if (!Accounts.remove(name)) {
        template.set(Template.Node.ERROR_CREATE);
        template.add("name", name);
        Messaging.send(sender, tag + template.parse());
        return false;
    }
    template.set(Template.Node.ACCOUNTS_REMOVE);
    template.add("name", name);
    Messaging.send(sender, tag + template.parse());
    return false;
}
Also used : InvalidUsage(com.iCo6.command.exceptions.InvalidUsage)

Example 9 with InvalidUsage

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

the class Set method perform.

@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
    if (!hasPermissions(sender, "set"))
        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 set <name> <amount>");
    if (arguments.get("amount").getStringValue().equals("empty"))
        throw new InvalidUsage("Missing <white>amount<rose>: /money set <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().setBalance(amount);
    template.set(Template.Node.PLAYER_SET);
    template.add("name", name);
    template.add("amount", account.getHoldings().toString());
    Messaging.send(sender, tag + template.parse());
    return false;
}
Also used : InvalidUsage(com.iCo6.command.exceptions.InvalidUsage) Account(com.iCo6.system.Account)

Example 10 with InvalidUsage

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

the class Take method perform.

@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
    if (!hasPermissions(sender, "take"))
        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 name parameter: /money take <name> <amount>");
    if (arguments.get("amount").getStringValue().equals("empty"))
        throw new InvalidUsage("Missing amount parameter: /money take <name> <amount>");
    try {
        amount = arguments.get("amount").getDoubleValue();
    } catch (NumberFormatException e) {
        throw new InvalidUsage("Invalid amount parameter, must be double.");
    }
    if (Double.isInfinite(amount) || Double.isNaN(amount))
        throw new InvalidUsage("Invalid amount parameter, 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().subtract(amount);
    template.set(Template.Node.PLAYER_DEBIT);
    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)

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