Search in sources :

Example 6 with Account

use of com.iCo6.system.Account 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 Account

use of com.iCo6.system.Account in project Core by iConomy.

the class MoneyComparator method topAccounts.

static List<Account> topAccounts(int amount) {
    Accounts Accounts = new Accounts();
    List<Account> accounts = new ArrayList<Account>();
    List<Account> finals = new ArrayList<Account>();
    List<String> total = new ArrayList<String>();
    if (useMiniDB() || useInventoryDB() || useOrbDB()) {
        if (useInventoryDB())
            total.addAll(inventory.getAllPlayers());
        if (useOrbDB())
            for (Player p : iConomy.Server.getOnlinePlayers()) total.add(p.getName());
        total.addAll(database.getIndices().keySet());
    } else {
        try {
            QueryRunner run = new QueryRunner();
            Connection c = iConomy.Database.getConnection();
            try {
                String t = Constants.Nodes.DatabaseTable.toString();
                total = run.query(c, "SELECT username FROM " + t + " WHERE status <> 1 ORDER BY balance DESC LIMIT " + amount, returnList);
            } catch (SQLException ex) {
                System.out.println("[iConomy] Error issueing SQL query: " + ex);
            } finally {
                DbUtils.close(c);
            }
        } catch (SQLException ex) {
            System.out.println("[iConomy] Database Error: " + ex);
        }
    }
    for (Iterator<String> it = total.iterator(); it.hasNext(); ) {
        String player = it.next();
        if (useMiniDB() || useInventoryDB() || useOrbDB()) {
            accounts.add(Accounts.get(player));
        } else {
            finals.add(new Account(player));
        }
    }
    if (useMiniDB() || useInventoryDB() || useOrbDB()) {
        Collections.sort(accounts, new MoneyComparator());
        if (amount > accounts.size())
            amount = accounts.size();
        for (int i = 0; i < amount; i++) {
            if (accounts.get(i).getStatus() == 1) {
                i--;
                continue;
            }
            finals.add(accounts.get(i));
        }
    }
    return finals;
}
Also used : Player(org.bukkit.entity.Player) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) QueryRunner(com.iCo6.util.org.apache.commons.dbutils.QueryRunner)

Example 8 with Account

use of com.iCo6.system.Account 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 9 with Account

use of com.iCo6.system.Account 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)

Example 10 with Account

use of com.iCo6.system.Account in project Core by iConomy.

the class Payment method perform.

@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
    if (!hasPermissions(sender, "pay"))
        return false;
    if (isConsole(sender)) {
        Messaging.send(sender, "`rCannot remove money from a non-living organism.");
        return false;
    }
    Player from = (Player) sender;
    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 pay <name> <amount>");
    if (arguments.get("amount").getStringValue().equals("empty"))
        throw new InvalidUsage("Missing <white>amount<rose>: /money pay <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 (amount < 0.1)
        throw new InvalidUsage("Invalid <white>amount<rose>, cannot be less than 0.1");
    if (Common.matches(from.getName(), name)) {
        template.set(Template.Node.PAYMENT_SELF);
        Messaging.send(sender, template.parse());
        return false;
    }
    if (!Accounts.exists(name)) {
        template.set(Template.Node.ERROR_ACCOUNT);
        template.add("name", name);
        Messaging.send(sender, tag + template.parse());
        return false;
    }
    Account holder = new Account(from.getName());
    Holdings holdings = holder.getHoldings();
    if (holdings.getBalance() < amount) {
        template.set(Template.Node.ERROR_FUNDS);
        Messaging.send(sender, tag + template.parse());
        return false;
    }
    Account account = new Account(name);
    holdings.subtract(amount);
    account.getHoldings().add(amount);
    template.set(Template.Node.PAYMENT_TO);
    template.add("name", name);
    template.add("amount", iConomy.format(amount));
    Messaging.send(sender, tag + template.parse());
    Player to = iConomy.Server.getPlayer(name);
    if (to != null) {
        template.set(Template.Node.PAYMENT_FROM);
        template.add("name", from.getName());
        template.add("amount", iConomy.format(amount));
        Messaging.send(to, tag + template.parse());
    }
    return false;
}
Also used : InvalidUsage(com.iCo6.command.exceptions.InvalidUsage) Account(com.iCo6.system.Account) Player(org.bukkit.entity.Player) Holdings(com.iCo6.system.Holdings)

Aggregations

Account (com.iCo6.system.Account)8 InvalidUsage (com.iCo6.command.exceptions.InvalidUsage)7 Player (org.bukkit.entity.Player)4 QueryRunner (com.iCo6.util.org.apache.commons.dbutils.QueryRunner)3 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 ResultSet (java.sql.ResultSet)2 Drivers (com.iCo6.Constants.Drivers)1 Database (com.iCo6.IO.Database)1 Type (com.iCo6.IO.Database.Type)1 MissingDriver (com.iCo6.IO.exceptions.MissingDriver)1 com.iCo6.listeners.players (com.iCo6.listeners.players)1 Holdings (com.iCo6.system.Holdings)1 Interest (com.iCo6.system.Interest)1 Template (com.iCo6.util.Template)1 ResultSetHandler (com.iCo6.util.org.apache.commons.dbutils.ResultSetHandler)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1