Example #1
0
 public void writeAuditLog(String account, String action, Double amount, String economy) {
   String statement = "";
   if (hc.s().gB("sql-connection.use-mysql")) {
     statement =
         "Insert Into hyperconomy_audit_log (TIME, ACCOUNT, ACTION, AMOUNT, ECONOMY) Values (NOW(),'"
             + account
             + "','"
             + action
             + "','"
             + amount
             + "','"
             + economy
             + "')";
   } else {
     statement =
         "Insert Into hyperconomy_audit_log (TIME, ACCOUNT, ACTION, AMOUNT, ECONOMY) Values (datetime('NOW', 'localtime'),'"
             + account
             + "','"
             + action
             + "','"
             + amount
             + "','"
             + economy
             + "')";
   }
   hc.getSQLWrite().executeSQL(statement);
 }
Example #2
0
 public void writeSQLLog(
     String playername,
     String action,
     String object,
     Double amount,
     Double money,
     Double tax,
     String store,
     String type) {
   String statement = "";
   if (hc.s().gB("sql-connection.use-mysql")) {
     statement =
         "Insert Into hyperconomy_log (TIME, CUSTOMER, ACTION, OBJECT, AMOUNT, MONEY, TAX, STORE, TYPE)"
             + " Values (NOW(),'"
             + playername
             + "','"
             + action
             + "','"
             + object
             + "','"
             + amount
             + "','"
             + hc.getCalculation().twoDecimals(money)
             + "','"
             + hc.getCalculation().twoDecimals(tax)
             + "','"
             + store
             + "','"
             + type
             + "')";
   } else {
     statement =
         "Insert Into hyperconomy_log (TIME, CUSTOMER, ACTION, OBJECT, AMOUNT, MONEY, TAX, STORE, TYPE)"
             + " Values (datetime('NOW', 'localtime'),'"
             + playername
             + "','"
             + action
             + "','"
             + object
             + "','"
             + amount
             + "','"
             + hc.getCalculation().twoDecimals(money)
             + "','"
             + hc.getCalculation().twoDecimals(tax)
             + "','"
             + store
             + "','"
             + type
             + "')";
   }
   hc.getSQLWrite().executeSQL(statement);
 }
  public void createEconomyFromYml(String econ, boolean restart) {
    if (hc.gYH().gFC("config").getBoolean("config.run-automatic-backups")) {
      new Backup();
    }
    FileConfiguration objects = hc.gYH().gFC("objects");
    SQLWrite sw = hc.getSQLWrite();
    Iterator<String> it = objects.getKeys(false).iterator();
    while (it.hasNext()) {
      String itemname = it.next().toString();
      String category = objects.getString(itemname + ".information.category");
      if (category == null) {
        category = "unknown";
      }

      HashMap<String, String> values = new HashMap<String, String>();
      values.put("NAME", itemname);
      values.put("ECONOMY", econ);
      values.put("DISPLAY_NAME", objects.getString(itemname + ".name.display"));
      values.put("ALIASES", objects.getString(itemname + ".name.aliases"));
      values.put("TYPE", objects.getString(itemname + ".information.type"));
      values.put("VALUE", objects.getDouble(itemname + ".value") + "");
      values.put("STATIC", objects.getString(itemname + ".price.static"));
      values.put("STATICPRICE", objects.getDouble(itemname + ".price.staticprice") + "");
      values.put("STOCK", objects.getDouble(itemname + ".stock.stock") + "");
      values.put("MEDIAN", objects.getDouble(itemname + ".stock.median") + "");
      values.put("INITIATION", objects.getString(itemname + ".initiation.initiation"));
      values.put("STARTPRICE", objects.getDouble(itemname + ".initiation.startprice") + "");
      values.put("CEILING", objects.getDouble(itemname + ".price.ceiling") + "");
      values.put("FLOOR", objects.getDouble(itemname + ".price.floor") + "");
      values.put("MAXSTOCK", objects.getDouble(itemname + ".stock.maxstock") + "");
      if (objects.getString(itemname + ".information.type").equalsIgnoreCase("item")) {
        values.put("MATERIAL", objects.getString(itemname + ".information.material"));
        values.put("DATA", objects.getInt(itemname + ".information.data") + "");
        values.put("DURABILITY", objects.getInt(itemname + ".information.data") + "");
      } else if (objects
          .getString(itemname + ".information.type")
          .equalsIgnoreCase("enchantment")) {
        values.put("MATERIAL", objects.getString(itemname + ".information.material"));
        values.put("DATA", "-1");
        values.put("DURABILITY", "-1");
      } else if (objects.getString(itemname + ".information.type").equalsIgnoreCase("experience")) {
        values.put("MATERIAL", "none");
        values.put("DATA", "-1");
        values.put("DURABILITY", "-1");
      }
      sw.performInsert("hyperconomy_objects", values);
    }
    if (restart) {
      hc.restart();
    }
  }
 public void createNewEconomy(String economy) {
   HyperEconomy defaultEconomy = getEconomy("default");
   SQLWrite sw = hc.getSQLWrite();
   for (HyperObject ho : defaultEconomy.getHyperObjects()) {
     HashMap<String, String> values = new HashMap<String, String>();
     values.put("NAME", ho.getName());
     values.put("DISPLAY_NAME", ho.getDisplayName());
     values.put("ALIASES", ho.getAliasesString());
     values.put("ECONOMY", economy);
     values.put("TYPE", ho.getType().toString());
     values.put("VALUE", ho.getValue() + "");
     values.put("STATIC", ho.getIsstatic());
     values.put("STATICPRICE", ho.getStaticprice() + "");
     values.put("STOCK", 0 + "");
     values.put("MEDIAN", ho.getMedian() + "");
     values.put("INITIATION", ho.getInitiation());
     values.put("STARTPRICE", ho.getStartprice() + "");
     values.put("CEILING", ho.getCeiling() + "");
     values.put("FLOOR", ho.getFloor() + "");
     values.put("MAXSTOCK", ho.getMaxstock() + "");
     if (ho instanceof HyperItem) {
       HyperItem hi = (HyperItem) ho;
       values.put("MATERIAL", hi.getMaterial());
       values.put("DATA", hi.getData() + "");
       values.put("DURABILITY", hi.getDurability() + "");
     } else if (ho instanceof HyperEnchant) {
       HyperEnchant he = (HyperEnchant) ho;
       values.put("MATERIAL", he.getEnchantmentName());
       values.put("DATA", "-1");
       values.put("DURABILITY", "-1");
     } else {
       values.put("MATERIAL", "none");
       values.put("DATA", "-1");
       values.put("DURABILITY", "-1");
     }
     sw.performInsert("hyperconomy_objects", values);
   }
   hc.restart();
 }
  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 deleteEconomy(String economy) {
   hc.getSQLWrite().addToQueue("DELETE FROM hyperconomy_objects WHERE ECONOMY='" + economy + "'");
   hc.restart();
 }
 public void load3(QueryResult qr) {
   if (!qr.next()) {
     HyperConomy.hc.getEconomyManager().createEconomyFromYml("default", false);
   }
   hc.getSQLWrite().afterWrite(this, "load4");
 }