Beispiel #1
0
  public boolean init() {
    database = getNewDatabase();

    database.open();

    if (!database.checkConnection()) {
      return false;
    }

    if (!database.createTable(
        "CREATE TABLE IF NOT EXISTS "
            + accounts
            + "("
            + pname
            + "  varchar(64), "
            + pbalance
            + " double);")) {
      return false;
    }

    if (supportsModification) {
      database.query("ALTER TABLE " + accounts + " MODIFY " + pname + " varchar(64)");
    }

    return true;
  }
Beispiel #2
0
  public List<Account> getTopAccounts() {
    String sql =
        "SELECT " + pname + " FROM " + accounts + " ORDER BY " + pbalance + " DESC limit 5";

    List<Account> topAccounts = new ArrayList<Account>();

    ResultSet set = database.query(sql);

    try {
      while (set.next()) {
        topAccounts.add(getAccount(set.getString(pname)));
      }
    } catch (SQLException e) {

    }

    return topAccounts;
  }
Beispiel #3
0
  public void clean() {
    String sql = "SELECT * FROM " + accounts + " WHERE " + pbalance + "=?";

    try {
      PreparedStatement prest = database.prepare(sql);

      prest.setDouble(1, plugin.getAPI().getDefaultHoldings());

      ResultSet set = prest.executeQuery();

      boolean executeQuery = false;

      String deleteQuery = "DELETE FROM " + accounts + " WHERE " + pname + " IN (";

      while (set.next()) {
        String name = set.getString(pname);

        if (plugin.getServer().getPlayerExact(name) != null) {
          continue;
        }

        executeQuery = true;

        deleteQuery += "'" + name + "', ";
      }

      prest.close();

      deleteQuery = deleteQuery.substring(0, deleteQuery.length() - 2) + ")";

      if (executeQuery) {
        database.query(deleteQuery);
      }
    } catch (SQLException e) {

    }
  }