Search in sources :

Example 6 with Arguments

use of com.iCo6.IO.mini.Arguments 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 7 with Arguments

use of com.iCo6.IO.mini.Arguments 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 8 with Arguments

use of com.iCo6.IO.mini.Arguments in project Core by iConomy.

the class MoneyComparator method createAccount.

static boolean createAccount(String name, Double balance, Integer status) {
    Boolean created = false;
    if (useMiniDB() || useInventoryDB() || useOrbDB()) {
        if (hasAccount(name))
            return false;
        if (useOrbDB())
            if (iConomy.Server.getPlayer(name) != null)
                return false;
        if (useInventoryDB())
            if (inventory.dataExists(name))
                return false;
        Arguments Row = new Arguments(name);
        Row.setValue("balance", balance);
        Row.setValue("status", status);
        database.addIndex(Row.getKey(), Row);
        database.update();
        return true;
    }
    try {
        QueryRunner run = new QueryRunner();
        Connection c = iConomy.Database.getConnection();
        try {
            String t = Constants.Nodes.DatabaseTable.toString();
            Integer amount = run.update(c, "INSERT INTO " + t + "(username, balance, status) values (?, ?, ?)", name.toLowerCase(), balance, status);
            if (amount > 0)
                created = true;
        } 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);
    }
    return false;
}
Also used : SQLException(java.sql.SQLException) Arguments(com.iCo6.IO.mini.Arguments) Connection(java.sql.Connection) QueryRunner(com.iCo6.util.org.apache.commons.dbutils.QueryRunner)

Example 9 with Arguments

use of com.iCo6.IO.mini.Arguments in project Core by iConomy.

the class Mini method read.

private void read(boolean pushed) {
    this.Database = new Manager(this.folder, this.database, true);
    this.Database.removeDuplicates();
    this.Database.read();
    this.Indexes = new LinkedHashMap<String, Arguments>();
    if (pushed)
        this.pushedIndexes = new LinkedHashMap<String, Arguments>();
    for (String line : this.Database.getLines()) {
        if (line.trim().isEmpty())
            continue;
        String[] parsed = trim(line.trim().split(Dict.SPACER));
        if (parsed[0].contains(Dict.ARGUMENT_SPLIT) || parsed[0].isEmpty())
            continue;
        Arguments entry = new Arguments(parseIndice(parsed[0]));
        for (String item : parsed) {
            if (!item.contains(Dict.ARGUMENT_SPLIT))
                continue;
            String[] map = trim(item.split(Dict.ARGUMENT_SPLIT, 2));
            String key = map[0], value = map[1];
            if (key == null)
                continue;
            entry.setValue(key, value);
        }
        this.Indexes.put(parseIndice(parsed[0]), entry);
    }
}
Also used : Manager(com.iCo6.IO.mini.file.Manager) LinkedHashMap(java.util.LinkedHashMap)

Example 10 with Arguments

use of com.iCo6.IO.mini.Arguments in project Core by iConomy.

the class Transactions method insert.

/**
     * Insert a balance transaction change or update.
     *
     * @param data Transaction class
     */
public static void insert(Transaction data) {
    if (!Constants.Nodes.Logging.getBoolean())
        return;
    if (Common.matches(iConomy.Database.getType().toString(), "inventorydb", "minidb", "orbdb")) {
        Mini database = iConomy.Database.getTransactionDatabase();
        if (database == null)
            return;
        Arguments entry = new Arguments(data.time);
        entry.setValue("where", data.where);
        entry.setValue("from", data.from);
        entry.setValue("to", data.to);
        entry.setValue("from_balance", data.fromBalance);
        entry.setValue("to_balance", data.toBalance);
        entry.setValue("gain", data.gain);
        entry.setValue("loss", data.loss);
        entry.setValue("set", data.set);
        database.addIndex(entry);
        database.update();
        return;
    }
}
Also used : Mini(com.iCo6.IO.mini.Mini) Arguments(com.iCo6.IO.mini.Arguments)

Aggregations

InvalidUsage (com.iCo6.command.exceptions.InvalidUsage)12 Account (com.iCo6.system.Account)7 Player (org.bukkit.entity.Player)3 Arguments (com.iCo6.IO.mini.Arguments)2 Mini (com.iCo6.IO.mini.Mini)1 Manager (com.iCo6.IO.mini.file.Manager)1 Holdings (com.iCo6.system.Holdings)1 QueryRunner (com.iCo6.util.org.apache.commons.dbutils.QueryRunner)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 LinkedHashMap (java.util.LinkedHashMap)1