Example #1
0
 /**
  * This function must be called from an asynchronous thread!
  *
  * @param account
  * @return returns the theoretical amount of money an account should have after all logged
  *     transactions in the hyperconomy_audit_log
  */
 private Double getAuditLogTotal(String account) {
   HyperConomy hc = HyperConomy.hc;
   SQLRead sr = hc.getSQLRead();
   QueryResult result =
       sr.aSyncSelect(
           "SELECT * FROM hyperconomy_audit_log WHERE ACCOUNT = '"
               + account
               + "' ORDER BY TIME ASC");
   double tBalance = 0.0;
   // double lastSetBalance = -1;
   while (result.next()) {
     String action = result.getString("ACTION");
     double amount = result.getDouble("AMOUNT");
     if (action.equalsIgnoreCase("deposit")) {
       tBalance += amount;
     } else if (action.equalsIgnoreCase("withdrawal")) {
       tBalance -= amount;
     } else if (action.equalsIgnoreCase("setbalance")) {
       tBalance = amount;
     } else if (action.equalsIgnoreCase("initialization")) {
       tBalance = amount;
     }
   }
   result.close();
   return tBalance;
 }
Example #2
0
 /**
  * This function must be called from an asynchronous thread!
  *
  * @param account
  * @param type
  * @return returns the theoretical amount of money an account should have after all logged (buy or
  *     sell individually) transactions in the hyperconomy_log
  */
 private Double getHyperLogTotal(String account, String type) {
   HyperConomy hc = HyperConomy.hc;
   SQLRead sr = hc.getSQLRead();
   String query = "";
   if (type.equalsIgnoreCase("sale")) {
     query =
         "SELECT SUM(MONEY) AS total FROM hyperconomy_log WHERE CUSTOMER = '"
             + account
             + "' AND ACTION = 'sale'";
   } else if (type.equalsIgnoreCase("purchase")) {
     query =
         "SELECT SUM(MONEY) AS total FROM hyperconomy_log WHERE CUSTOMER = '"
             + account
             + "' AND ACTION = 'purchase'";
   }
   QueryResult result = sr.aSyncSelect(query);
   double amount = 0.0;
   if (result.next()) {
     amount = result.getDouble("total");
   }
   result.close();
   return amount;
 }
  public void load1(QueryResult qr) {
    hc = HyperConomy.hc;
    hc.getSQLRead().setErrorLogging(true);
    if (qr.next()) {
      double version = Double.parseDouble(qr.getString("VALUE"));
      if (version < 1.2) {
        // update adds hyperconomy_shop_objects table
        hc.getLogger().info("[HyperConomy]Updating HyperConomy database to version 1.2.");
        hc.getSQLWrite()
            .convertExecuteSynchronously(
                "CREATE TABLE IF NOT EXISTS hyperconomy_shop_objects (ID INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, SHOP VARCHAR(255) NOT NULL, HYPEROBJECT VARCHAR(255) NOT NULL, QUANTITY DOUBLE NOT NULL, PRICE DOUBLE NOT NULL, STATUS VARCHAR(255) NOT NULL)");
        hc.getSQLWrite()
            .executeSynchronously(
                "UPDATE hyperconomy_settings SET VALUE = '1.2' WHERE SETTING = 'version'");
      }
      if (version < 1.21) {
        // update removes unnecessary fields from hyperconomy_objects (id, category)
        hc.getLogger().info("[HyperConomy]Updating HyperConomy database to version 1.21.");
        hc.getSQLWrite()
            .convertExecuteSynchronously(
                "CREATE TABLE IF NOT EXISTS hyperconomy_objects_temp (NAME VARCHAR(255) NOT NULL, ECONOMY VARCHAR(255) NOT NULL, TYPE TINYTEXT, MATERIAL TINYTEXT, DATA INTEGER, DURABILITY INTEGER, VALUE DOUBLE, STATIC TINYTEXT, STATICPRICE DOUBLE, STOCK DOUBLE, MEDIAN DOUBLE, INITIATION TINYTEXT, STARTPRICE DOUBLE, CEILING DOUBLE, FLOOR DOUBLE, MAXSTOCK DOUBLE NOT NULL DEFAULT '1000000', PRIMARY KEY (NAME, ECONOMY))");
        hc.getSQLWrite()
            .executeSynchronously(
                "INSERT INTO hyperconomy_objects_temp (NAME, ECONOMY, TYPE, MATERIAL, DATA, DURABILITY, VALUE, STATIC, STATICPRICE, STOCK, MEDIAN, INITIATION, STARTPRICE, CEILING, FLOOR, MAXSTOCK) SELECT NAME, ECONOMY, TYPE, MATERIAL, DATA, DURABILITY, VALUE, STATIC, STATICPRICE, STOCK, MEDIAN, INITIATION, STARTPRICE, CEILING, FLOOR, MAXSTOCK FROM hyperconomy_objects");
        hc.getSQLWrite().executeSynchronously("DROP TABLE hyperconomy_objects");
        hc.getSQLWrite()
            .convertExecuteSynchronously(
                "CREATE TABLE IF NOT EXISTS hyperconomy_objects (NAME VARCHAR(255) NOT NULL, ECONOMY VARCHAR(255) NOT NULL, TYPE TINYTEXT, MATERIAL TINYTEXT, DATA INTEGER, DURABILITY INTEGER, VALUE DOUBLE, STATIC TINYTEXT, STATICPRICE DOUBLE, STOCK DOUBLE, MEDIAN DOUBLE, INITIATION TINYTEXT, STARTPRICE DOUBLE, CEILING DOUBLE, FLOOR DOUBLE, MAXSTOCK DOUBLE NOT NULL DEFAULT '1000000', PRIMARY KEY (NAME, ECONOMY))");
        hc.getSQLWrite()
            .executeSynchronously(
                "INSERT INTO hyperconomy_objects (NAME, ECONOMY, TYPE, MATERIAL, DATA, DURABILITY, VALUE, STATIC, STATICPRICE, STOCK, MEDIAN, INITIATION, STARTPRICE, CEILING, FLOOR, MAXSTOCK) SELECT NAME, ECONOMY, TYPE, MATERIAL, DATA, DURABILITY, VALUE, STATIC, STATICPRICE, STOCK, MEDIAN, INITIATION, STARTPRICE, CEILING, FLOOR, MAXSTOCK FROM hyperconomy_objects_temp");
        hc.getSQLWrite().executeSynchronously("DROP TABLE hyperconomy_objects_temp");
        hc.getSQLWrite()
            .executeSynchronously(
                "UPDATE hyperconomy_settings SET VALUE = '1.21' WHERE SETTING = 'version'");
      }
      if (version < 1.22) {
        // update adds frame shop table
        hc.getLogger().info("[HyperConomy]Updating HyperConomy database to version 1.22.");
        hc.getSQLWrite()
            .convertExecuteSynchronously(
                "CREATE TABLE IF NOT EXISTS hyperconomy_frame_shops (ID INTEGER NOT NULL PRIMARY KEY, HYPEROBJECT VARCHAR(255) NOT NULL, ECONOMY TINYTEXT, SHOP VARCHAR(255), X DOUBLE NOT NULL DEFAULT '0', Y DOUBLE NOT NULL DEFAULT '0', Z DOUBLE NOT NULL DEFAULT '0', WORLD TINYTEXT NOT NULL)");
        hc.getSQLWrite()
            .executeSynchronously(
                "UPDATE hyperconomy_settings SET VALUE = '1.22' WHERE SETTING = 'version'");
      }
      if (version < 1.23) {
        // update adds new fields ALIASES and DISPLAY_NAME to hyperconomy_objects, backs up
        // composites.yml and objects.yml and replaces them with the new ones
        // and then calls an after load update to update the names, aliases, and display names in
        // the database
        hc.getLogger().info("[HyperConomy]Updating HyperConomy database to version 1.23.");
        hc.getSQLWrite()
            .convertExecuteSynchronously(
                "CREATE TABLE IF NOT EXISTS hyperconomy_objects_temp (NAME VARCHAR(255) NOT NULL, ECONOMY VARCHAR(255) NOT NULL, DISPLAY_NAME VARCHAR(255), ALIASES VARCHAR(1000), TYPE TINYTEXT, MATERIAL TINYTEXT, DATA INTEGER, DURABILITY INTEGER, VALUE DOUBLE, STATIC TINYTEXT, STATICPRICE DOUBLE, STOCK DOUBLE, MEDIAN DOUBLE, INITIATION TINYTEXT, STARTPRICE DOUBLE, CEILING DOUBLE, FLOOR DOUBLE, MAXSTOCK DOUBLE NOT NULL DEFAULT '1000000', PRIMARY KEY (NAME, ECONOMY))");
        hc.getSQLWrite()
            .executeSynchronously(
                "INSERT INTO hyperconomy_objects_temp (NAME, ECONOMY, TYPE, MATERIAL, DATA, DURABILITY, VALUE, STATIC, STATICPRICE, STOCK, MEDIAN, INITIATION, STARTPRICE, CEILING, FLOOR, MAXSTOCK) SELECT NAME, ECONOMY, TYPE, MATERIAL, DATA, DURABILITY, VALUE, STATIC, STATICPRICE, STOCK, MEDIAN, INITIATION, STARTPRICE, CEILING, FLOOR, MAXSTOCK FROM hyperconomy_objects");
        hc.getSQLWrite().executeSynchronously("DROP TABLE hyperconomy_objects");
        hc.getSQLWrite()
            .convertExecuteSynchronously(
                "CREATE TABLE IF NOT EXISTS hyperconomy_objects (NAME VARCHAR(255) NOT NULL, ECONOMY VARCHAR(255) NOT NULL, DISPLAY_NAME VARCHAR(255), ALIASES VARCHAR(1000), TYPE TINYTEXT, MATERIAL TINYTEXT, DATA INTEGER, DURABILITY INTEGER, VALUE DOUBLE, STATIC TINYTEXT, STATICPRICE DOUBLE, STOCK DOUBLE, MEDIAN DOUBLE, INITIATION TINYTEXT, STARTPRICE DOUBLE, CEILING DOUBLE, FLOOR DOUBLE, MAXSTOCK DOUBLE NOT NULL DEFAULT '1000000', PRIMARY KEY (NAME, ECONOMY))");
        hc.getSQLWrite()
            .executeSynchronously(
                "INSERT INTO hyperconomy_objects (NAME, ECONOMY, DISPLAY_NAME, ALIASES, TYPE, MATERIAL, DATA, DURABILITY, VALUE, STATIC, STATICPRICE, STOCK, MEDIAN, INITIATION, STARTPRICE, CEILING, FLOOR, MAXSTOCK) SELECT NAME, ECONOMY, DISPLAY_NAME, ALIASES, TYPE, MATERIAL, DATA, DURABILITY, VALUE, STATIC, STATICPRICE, STOCK, MEDIAN, INITIATION, STARTPRICE, CEILING, FLOOR, MAXSTOCK FROM hyperconomy_objects_temp");
        hc.getSQLWrite().executeSynchronously("DROP TABLE hyperconomy_objects_temp");
        new Backup();
        YamlHandler yh = hc.getYamlHandler();
        yh.unRegisterFileConfiguration("composites");
        yh.unRegisterFileConfiguration("objects");
        yh.deleteConfigFile("composites");
        yh.deleteConfigFile("objects");
        yh.copyFromJar("composites");
        yh.copyFromJar("objects");
        yh.registerFileConfiguration("composites");
        yh.registerFileConfiguration("objects");
        hc.getEconomyManager().addUpdateAfterLoad(1.23);
        ;
        hc.getSQLWrite()
            .executeSynchronously(
                "UPDATE hyperconomy_settings SET VALUE = '1.23' WHERE SETTING = 'version'");
      }
      if (version < 1.24) {}

    } else {
      createTables(hc.getSQLWrite());
    }
    String query = "SELECT NAME FROM hyperconomy_objects WHERE ECONOMY='default'";
    hc.getSQLRead().syncRead(this, "load3", query, null);
  }
 public void load3(QueryResult qr) {
   if (!qr.next()) {
     HyperConomy.hc.getEconomyManager().createEconomyFromYml("default", false);
   }
   hc.getSQLWrite().afterWrite(this, "load4");
 }