예제 #1
0
  Seteconomy(_Command command, String args[], CommandSender sender, Player player) {
    HyperConomy hc = HyperConomy.hc;
    EconomyManager em = hc.getEconomyManager();
    LanguageFile L = hc.getLanguageFile();
    try {
      if (args.length == 1) {
        String economy = args[0];
        if (em.economyExists(economy)) {
          if (player != null) {
            em.getHyperPlayer(player.getName()).setEconomy(economy);
            sender.sendMessage(L.get("ECONOMY_SET"));
          } else {
            command.setNonPlayerEconomy(economy);
            hc.getConsoleSettings().setConsoleEconomy(economy);
            sender.sendMessage(L.get("ECONOMY_SET"));
          }
        } else {
          sender.sendMessage(L.get("ECONOMY_NOT_EXIST"));
        }

      } else {
        sender.sendMessage(L.get("SETECONOMY_INVALID"));
      }
    } catch (Exception e) {
      sender.sendMessage(L.get("SETECONOMY_INVALID"));
    }
  }
예제 #2
0
 public void createGlobalShopAccount() {
   HyperConomy hc = HyperConomy.hc;
   Log l = hc.getLog();
   String globalaccount = hc.gYH().gFC("config").getString("config.global-shop-account");
   if (hc.useExternalEconomy()) {
     if (!hc.getEconomy().hasAccount(globalaccount)) {
       getHyperPlayer(globalaccount)
           .setBalance(hc.gYH().gFC("config").getDouble("config.initialshopbalance"));
       l.writeAuditLog(
           globalaccount,
           "setbalance",
           hc.gYH().gFC("config").getDouble("config.initialshopbalance"),
           hc.getEconomy().getName());
     }
   } else {
     if (!hasAccount(globalaccount)) {
       createPlayerAccount(globalaccount);
       getHyperPlayer(globalaccount)
           .setBalance(hc.gYH().gFC("config").getDouble("config.initialshopbalance"));
       l.writeAuditLog(
           globalaccount,
           "setbalance",
           hc.gYH().gFC("config").getDouble("config.initialshopbalance"),
           "HyperConomy");
     }
   }
 }
예제 #3
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;
 }
예제 #4
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);
 }
예제 #5
0
 private void loadShops() {
   stopShopCheck();
   shops.clear();
   FileConfiguration sh = hc.gYH().gFC("shops");
   if (!useShops) {
     Shop shop =
         new ServerShop("GlobalShop", getGlobalShopAccount().getEconomy(), getGlobalShopAccount());
     shop.setGlobal();
     shops.put("GlobalShop", shop);
     return;
   }
   Iterator<String> it = sh.getKeys(false).iterator();
   while (it.hasNext()) {
     Object element = it.next();
     String name = element.toString();
     if (name.equalsIgnoreCase("GlobalShop")) {
       continue;
     }
     String owner = sh.getString(name + ".owner");
     String economy = sh.getString(name + ".economy");
     if (owner == null) {
       owner = getGlobalShopAccount().getName();
     }
     if (owner.equalsIgnoreCase(getGlobalShopAccount().getName())) {
       Shop shop = new ServerShop(name, economy, getHyperPlayer(owner));
       shop.setPoint1(
           sh.getString(name + ".world"),
           sh.getInt(name + ".p1.x"),
           sh.getInt(name + ".p1.y"),
           sh.getInt(name + ".p1.z"));
       shop.setPoint2(
           sh.getString(name + ".world"),
           sh.getInt(name + ".p2.x"),
           sh.getInt(name + ".p2.y"),
           sh.getInt(name + ".p2.z"));
       shop.setMessage1(sh.getString(name + ".shopmessage1"));
       shop.setMessage2(sh.getString(name + ".shopmessage2"));
       shops.put(name, shop);
     } else {
       if (hc.gYH().gFC("config").getBoolean("config.use-player-shops")) {
         Shop shop = new PlayerShop(name, economy, getHyperPlayer(owner));
         shop.setPoint1(
             sh.getString(name + ".world"),
             sh.getInt(name + ".p1.x"),
             sh.getInt(name + ".p1.y"),
             sh.getInt(name + ".p1.z"));
         shop.setPoint2(
             sh.getString(name + ".world"),
             sh.getInt(name + ".p2.x"),
             sh.getInt(name + ".p2.y"),
             sh.getInt(name + ".p2.z"));
         shop.setMessage1(sh.getString(name + ".shopmessage1"));
         shop.setMessage2(sh.getString(name + ".shopmessage2"));
         shops.put(name, shop);
       }
     }
   }
   startShopCheck();
 }
예제 #6
0
 public EconomyManager() {
   hc = HyperConomy.hc;
   dataLoaded = false;
   loadActive = false;
   economiesLoaded = false;
   useShops = hc.gYH().gFC("config").getBoolean("config.use-shops");
   shopinterval = hc.gYH().gFC("config").getLong("config.shopcheckinterval");
   hc.getServer().getPluginManager().registerEvents(this, hc);
 }
예제 #7
0
  Audit(String args[], CommandSender csender) {
    sender = csender;
    hc = HyperConomy.hc;
    L = hc.getLanguageFile();
    em = hc.getEconomyManager();
    try {
      account = args[0];
      if (!em.hasAccount(account)) {
        sender.sendMessage(L.get("ACCOUNT_NOT_FOUND"));
        return;
      }

      hc.getServer()
          .getScheduler()
          .runTaskAsynchronously(
              hc,
              new Runnable() {
                public void run() {
                  HyperPlayer hp = em.getHyperPlayer(account);
                  account = hp.getName();
                  cbalance = hp.getBalance();
                  logbalance =
                      getHyperLogTotal(account, "sale") - getHyperLogTotal(account, "purchase");
                  auditbalance = getAuditLogTotal(account);
                  hc.getServer()
                      .getScheduler()
                      .runTask(
                          hc,
                          new Runnable() {
                            public void run() {
                              CommonFunctions cf = hc.gCF();
                              sender.sendMessage(L.get("LINE_BREAK"));
                              sender.sendMessage(L.f(L.get("AUDIT_TRUE"), cbalance));
                              sender.sendMessage(
                                  L.f(L.get("AUDIT_THEORETICAL1"), cf.twoDecimals(logbalance)));
                              sender.sendMessage(
                                  L.f(L.get("AUDIT_THEORETICAL2"), cf.twoDecimals(auditbalance)));
                              // sender.sendMessage("True balance: " + cbalance);
                              // sender.sendMessage("Theoretical balance condsidering only
                              // sales/purchases: " + calc.twoDecimals(logbalance));
                              // sender.sendMessage("Theoretical balance condsidering all logged
                              // balance changes: " + calc.twoDecimals(auditbalance));
                              sender.sendMessage(L.get("LINE_BREAK"));
                            }
                          });
                }
              });

    } catch (Exception e) {
      sender.sendMessage(L.get("AUDIT_INVALID"));
    }
  }
예제 #8
0
  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();
    }
  }
예제 #9
0
 public boolean hasAccount(String name) {
   if (hc.useExternalEconomy()) {
     if (hc.getEconomy().hasAccount(name)) {
       if (!hyperPlayers.containsKey(fixpN(name))) {
         addPlayer(name);
       }
       return true;
     } else {
       return false;
     }
   } else {
     return hyperPlayers.containsKey(fixpN(name));
   }
 }
예제 #10
0
 public void load() {
   if (loadActive) {
     return;
   }
   loadActive = true;
   try {
     hc = HyperConomy.hc;
     sr = hc.getSQLRead();
     String query = "SELECT VALUE FROM hyperconomy_settings WHERE SETTING = 'version'";
     hc.getSQLRead().setErrorLogging(false);
     hc.getSQLRead().syncRead(this, "load1", query, null);
   } catch (Exception e) {
     hc.gDB().writeError(e);
   }
 }
예제 #11
0
 private void addOnlinePlayers() {
   for (Player p : Bukkit.getOnlinePlayers()) {
     if (p.getName()
         .equalsIgnoreCase(hc.gYH().gFC("config").getString("config.global-shop-account"))) {
       if (hc.gYH()
           .gFC("config")
           .getBoolean("config.block-player-with-same-name-as-global-shop-account")) {
         p.kickPlayer(hc.getLanguageFile().get("CANT_USE_ACCOUNT"));
       }
     }
     if (!hasAccount(p.getName())) {
       addPlayer(p.getName());
     }
   }
 }
예제 #12
0
 private void waitForLoad() {
   wait =
       hc.getServer()
           .getScheduler()
           .runTaskTimer(
               hc,
               new Runnable() {
                 public void run() {
                   boolean loaded = true;
                   for (HyperEconomy he : getEconomies()) {
                     if (!he.dataLoaded() || !dataLoaded) {
                       loaded = false;
                     }
                   }
                   if (loaded) {
                     hc.getHyperLock().setLoadLock(false);
                     economiesLoaded = true;
                     wait.cancel();
                     hc.getHyperEventHandler().fireDataLoadEvent();
                     loadActive = false;
                     updateAfterLoad();
                   }
                 }
               },
               1L,
               1L);
 }
예제 #13
0
 @EventHandler(priority = EventPriority.NORMAL)
 public void onPlayerQuit(PlayerQuitEvent event) {
   try {
     if (!economiesLoaded()) {
       return;
     }
     Location l = event.getPlayer().getLocation();
     String name = event.getPlayer().getName();
     if (!hasAccount(name)) {
       addPlayer(name);
     }
     if (hyperPlayers.containsKey(name)) {
       HyperPlayer hp = hyperPlayers.get(name);
       if (hp == null) {
         return;
       }
       hp.setX(l.getX());
       hp.setY(l.getY());
       hp.setZ(l.getZ());
       hp.setWorld(l.getWorld().getName());
     }
   } catch (Exception e) {
     hc.gDB().writeError(e);
   }
 }
예제 #14
0
 private void updateAfterLoad() {
   boolean restart = false;
   for (Double d : updateAfterLoad) {
     if (d.doubleValue() == 1.23) {
       hc.getLogger().info("[HyperConomy]Updating object names for version 1.23.");
       for (HyperEconomy he : getEconomies()) {
         he.updateNamesFromYml();
       }
       restart = true;
     } else if (d.doubleValue() == 1.24) {
       hc.getLogger().info("[HyperConomy]Updating for version 1.24.");
     }
   }
   if (restart) {
     hc.restart();
   }
 }
예제 #15
0
  Importprices(String args[], CommandSender sender) {
    HyperConomy hc = HyperConomy.hc;
    LanguageFile L = hc.getLanguageFile();
    DataHandler sf = hc.getDataFunctions();

    try {
      if (args.length == 1) {
        String economy = args[0];
        if (sf.testEconomy(economy)) {
          new Backup();
          FileConfiguration itemsyaml = hc.getYaml().getItems();
          Iterator<String> it = itemsyaml.getKeys(false).iterator();
          while (it.hasNext()) {
            String name = it.next().toString();
            double value = itemsyaml.getDouble(name + ".value");
            double staticprice = itemsyaml.getDouble(name + ".price.staticprice");
            double startprice = itemsyaml.getDouble(name + ".initiation.startprice");
            HyperObject ho = sf.getHyperObject(name, economy);
            ho.setValue(value);
            ho.setStartprice(startprice);
            ho.setStaticprice(staticprice);
          }
          FileConfiguration enchantsyaml = hc.getYaml().getEnchants();
          Iterator<String> it2 = enchantsyaml.getKeys(false).iterator();
          while (it2.hasNext()) {
            String name = it2.next().toString();
            double value = enchantsyaml.getDouble(name + ".value");
            double staticprice = enchantsyaml.getDouble(name + ".price.staticprice");
            double startprice = enchantsyaml.getDouble(name + ".initiation.startprice");
            HyperObject ho = sf.getHyperObject(name, economy);
            ho.setValue(value);
            ho.setStartprice(startprice);
            ho.setStaticprice(staticprice);
          }
          sender.sendMessage(L.get("PRICES_IMPORTED"));
        } else {
          sender.sendMessage(L.get("ECONOMY_NOT_EXIST"));
          return;
        }
      } else {
        sender.sendMessage(L.get("IMPORTPRICES_INVALID"));
      }
    } catch (Exception e) {
      sender.sendMessage(L.get("IMPORTPRICES_INVALID"));
    }
  }
예제 #16
0
 public void storeDisplay() {
   Iterator<String> it = hc.gYH().gFC("displays").getKeys(false).iterator();
   int numdisplays = 0;
   while (it.hasNext()) {
     String key = it.next().toString();
     int number = Integer.parseInt(key.substring(1, key.length()));
     if (number > numdisplays) {
       numdisplays = number;
     }
   }
   numdisplays++;
   FileConfiguration disp = hc.gYH().gFC("displays");
   key = "d" + numdisplays;
   disp.set(key + ".name", name);
   disp.set(key + ".x", x);
   disp.set(key + ".y", y);
   disp.set(key + ".z", z);
   disp.set(key + ".world", w.getName());
 }
예제 #17
0
 public Item makeDisplay() {
   HyperEconomy he = hc.getEconomyManager().getEconomy("default");
   Location l = new Location(w, x, y + 1, z);
   ItemStack dropstack = he.getHyperItem(name).getItemStack();
   dropstack.setDurability((short) he.getHyperItem(name).getDurability());
   this.item = w.dropItem(l, dropstack);
   this.entityId = item.getEntityId();
   item.setVelocity(new Vector(0, 0, 0));
   item.setMetadata("HyperConomy", new FixedMetadataValue(hc, "item_display"));
   return item;
 }
예제 #18
0
  Esell(Player player, String[] args) {
    HyperConomy hc = HyperConomy.hc;
    LanguageFile L = hc.getLanguageFile();
    ShopFactory s = hc.getShopFactory();
    DataHandler dh = hc.getDataFunctions();
    InventoryManipulation im = hc.getInventoryManipulation();
    try {
      if (player.getGameMode() == GameMode.CREATIVE
          && hc.s().gB("block-selling-in-creative-mode")) {
        player.sendMessage(L.get("CANT_SELL_CREATIVE"));
        return;
      }
      if (s.inAnyShop(player)) {
        HyperPlayer hp = dh.getHyperPlayer(player);
        if (hp.hasSellPermission(s.getShop(player))) {
          String name = args[0];
          if (args[0].equalsIgnoreCase("max")) {
            if (!im.hasenchants(player.getItemInHand())) {
              player.sendMessage(L.get("HAS_NO_ENCHANTMENTS"));
            }
            ArrayList<String> enchants = im.getEnchantments(player.getItemInHand());
            for (String e : enchants) {
              if (s.getShop(player).has(e)) {
                PlayerTransaction pt = new PlayerTransaction(TransactionType.SELL);
                pt.setHyperObject(dh.getHyperObject(e, hp.getEconomy()));
                TransactionResponse response = hp.processTransaction(pt);
                response.sendMessages();
              } else {
                player.sendMessage(L.get("CANT_BE_TRADED"));
              }
            }

          } else {
            if (hc.getDataFunctions().enchantTest(name)) {
              if (s.getShop(player).has(name)) {
                PlayerTransaction pt = new PlayerTransaction(TransactionType.SELL);
                pt.setHyperObject(dh.getHyperObject(name, hp.getEconomy()));
                TransactionResponse response = hp.processTransaction(pt);
                response.sendMessages();
              } else {
                player.sendMessage(L.get("CANT_BE_TRADED"));
              }
            } else {
              player.sendMessage(L.get("ENCHANTMENT_NOT_IN_DATABASE"));
            }
          }
        } else {
          player.sendMessage(L.get("NO_TRADE_PERMISSION"));
        }
      } else {
        player.sendMessage(L.get("MUST_BE_IN_SHOP"));
      }
    } catch (Exception e) {
      player.sendMessage(L.get("ESELL_INVALID"));
    }
  }
예제 #19
0
 ItemDisplay(Location location, String name) {
   this.hc = HyperConomy.hc;
   this.location = location;
   HyperEconomy he = hc.getEconomyManager().getEconomy("default");
   this.x = this.location.getX();
   this.y = this.location.getY();
   this.z = this.location.getZ();
   this.w = this.location.getWorld();
   this.name = he.fixName(name);
   storeDisplay();
   setProtectedBlocks();
 }
예제 #20
0
 @EventHandler(priority = EventPriority.NORMAL)
 public void onPlayerJoin(PlayerJoinEvent event) {
   try {
     if (!economiesLoaded()) {
       return;
     }
     String name = event.getPlayer().getName();
     if (name.equalsIgnoreCase(hc.gYH().gFC("config").getString("config.global-shop-account"))) {
       if (hc.gYH()
           .gFC("config")
           .getBoolean("config.block-player-with-same-name-as-global-shop-account")) {
         event.getPlayer().kickPlayer(hc.getLanguageFile().get("CANT_USE_ACCOUNT"));
       }
     }
     if (!hasAccount(name)) {
       addPlayer(name);
     }
   } catch (Exception e) {
     hc.gDB().writeError(e);
   }
 }
예제 #21
0
 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();
 }
예제 #22
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;
 }
예제 #23
0
 public void startShopCheck() {
   shopCheckTask =
       hc.getServer()
           .getScheduler()
           .runTaskTimer(
               hc,
               new Runnable() {
                 public void run() {
                   for (Shop shop : shops.values()) {
                     shop.updatePlayerStatus();
                   }
                 }
               },
               shopinterval,
               shopinterval);
 }
예제 #24
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);
 }
예제 #25
0
 /** Limits messages sent to player to 1 per second. */
 private void sendMessage(String message) {
   messages.put(player, message);
   if (!messageActive) {
     messageActive = true;
     hc.getServer()
         .getScheduler()
         .scheduleSyncDelayedTask(
             hc,
             new Runnable() {
               public void run() {
                 player.sendMessage(messages.get(player));
                 messages.remove(player);
                 messageActive = false;
               }
             },
             20L);
   }
 }
예제 #26
0
 public void load5() {
   hc.getServer()
       .getScheduler()
       .runTaskAsynchronously(
           hc,
           new Runnable() {
             public void run() {
               economies.clear();
               ArrayList<String> econs =
                   sr.getStringList("SELECT DISTINCT ECONOMY FROM hyperconomy_objects");
               for (String e : econs) {
                 economies.put(e, new HyperEconomy(e));
               }
               loadData();
               waitForLoad();
             }
           });
 }
예제 #27
0
 private void loadData() {
   hc.getServer()
       .getScheduler()
       .runTaskAsynchronously(
           hc,
           new Runnable() {
             public void run() {
               hyperPlayers.clear();
               QueryResult result = sr.aSyncSelect("SELECT * FROM hyperconomy_players");
               while (result.next()) {
                 HyperPlayer hplayer =
                     new HyperPlayer(
                         result.getString("PLAYER"),
                         result.getString("ECONOMY"),
                         result.getDouble("BALANCE"),
                         result.getDouble("X"),
                         result.getDouble("Y"),
                         result.getDouble("Z"),
                         result.getString("WORLD"),
                         result.getString("HASH"),
                         result.getString("SALT"));
                 hyperPlayers.put(hplayer.getName(), hplayer);
               }
               result.close();
               hc.getServer()
                   .getScheduler()
                   .runTask(
                       hc,
                       new Runnable() {
                         public void run() {
                           addOnlinePlayers();
                           createGlobalShopAccount();
                           loadShops();
                           dataLoaded = true;
                         }
                       });
             }
           });
 }
예제 #28
0
 public void createTables(SQLWrite sw) {
   sw.convertExecuteSynchronously(
       "CREATE TABLE IF NOT EXISTS hyperconomy_settings (SETTING VARCHAR(255) NOT NULL, VALUE TEXT, TIME DATETIME NOT NULL, PRIMARY KEY (SETTING))");
   sw.convertExecuteSynchronously("DELETE FROM hyperconomy_settings");
   sw.convertExecuteSynchronously(
       "INSERT INTO hyperconomy_settings (SETTING, VALUE, TIME) VALUES ('version', '"
           + hc.getEconomyManager().getVersion()
           + "', NOW() )");
   sw.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))");
   sw.convertExecuteSynchronously(
       "CREATE TABLE IF NOT EXISTS hyperconomy_players (PLAYER VARCHAR(255) NOT NULL PRIMARY KEY, ECONOMY TINYTEXT, BALANCE DOUBLE NOT NULL DEFAULT '0', X DOUBLE NOT NULL DEFAULT '0', Y DOUBLE NOT NULL DEFAULT '0', Z DOUBLE NOT NULL DEFAULT '0', WORLD TINYTEXT NOT NULL, HASH VARCHAR(255) NOT NULL DEFAULT '', SALT VARCHAR(255) NOT NULL DEFAULT '')");
   sw.convertExecuteSynchronously(
       "CREATE TABLE IF NOT EXISTS hyperconomy_log (ID INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, TIME DATETIME, CUSTOMER TINYTEXT, ACTION TINYTEXT, OBJECT TINYTEXT, AMOUNT DOUBLE, MONEY DOUBLE, TAX DOUBLE, STORE TINYTEXT, TYPE TINYTEXT)");
   sw.convertExecuteSynchronously(
       "CREATE TABLE IF NOT EXISTS hyperconomy_history (ID INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, OBJECT TINYTEXT, ECONOMY TINYTEXT, TIME DATETIME, PRICE DOUBLE)");
   sw.convertExecuteSynchronously(
       "CREATE TABLE IF NOT EXISTS hyperconomy_audit_log (ID INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, TIME DATETIME NOT NULL, ACCOUNT TINYTEXT NOT NULL, ACTION TINYTEXT NOT NULL, AMOUNT DOUBLE NOT NULL, ECONOMY TINYTEXT NOT NULL)");
   sw.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)");
   sw.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)");
 }
예제 #29
0
 Sellall(String args[], Player p) {
   hc = HyperConomy.hc;
   s = hc.getShop();
   calc = hc.getCalculation();
   tran = hc.getTransaction();
   ench = hc.getETransaction();
   player = p;
   try {
     s.setinShop(player);
     if (s.inShop() != -1) {
       if (!hc.getYaml().getConfig().getBoolean("config.use-shop-permissions")
           || player.hasPermission("hyperconomy.shop.*")
           || player.hasPermission("hyperconomy.shop." + s.getShop(player))
           || player.hasPermission("hyperconomy.shop." + s.getShop(player) + ".sell")) {
         if (args.length == 0) {
           int slotn = 0;
           Inventory invent = player.getInventory();
           int heldslot = player.getInventory().getHeldItemSlot();
           int itd = 0;
           // Sells the held item slot first.
           if (invent.getItem(heldslot) != null) {
             itd = invent.getItem(heldslot).getTypeId();
           }
           if (itd != 0) {
             int da = calc.getpotionDV(invent.getItem(heldslot));
             int newdat = calc.newData(itd, da);
             String ke = itd + ":" + newdat;
             String nam = hc.getnameData(ke);
             int amount = tran.countInvitems(itd, newdat, player);
             if (nam != null) {
               if (s.has(s.getShop(player), nam)) {
                 tran.sell(nam, itd, newdat, amount, player);
               } else {
                 sendMessage("§9Sorry, one or more of those items cannot be traded at this shop.");
               }
             }
           }
           // Sells remaining items after the held slot.
           while (slotn < 36) {
             if (invent.getItem(slotn) == null) {
               itd = 0;
             } else {
               itd = invent.getItem(slotn).getTypeId();
             }
             if (itd != 0) {
               ItemStack itemn = invent.getItem(slotn);
               if (ench.hasenchants(itemn) == false) {
                 int da = calc.getpotionDV(invent.getItem(slotn));
                 int newdat = calc.newData(itd, da);
                 String ke = itd + ":" + newdat;
                 String nam = hc.getnameData(ke);
                 if (nam != null) {
                   int amount = tran.countInvitems(itd, newdat, player);
                   if (s.has(s.getShop(player), nam)) {
                     tran.sell(nam, itd, newdat, amount, player);
                   } else {
                     sendMessage(
                         "§9Sorry, one or more of those items cannot be traded at this shop.");
                   }
                 }
               } else {
                 sendMessage("§9You cannot buy or sell enchanted items!");
               }
             }
             slotn++;
           }
         } else {
           player.sendMessage("§4Invalid Parameters. Use /sellall");
           return;
         }
       } else {
         player.sendMessage("§9Sorry, you don't have permission to trade here.");
         return;
       }
     } else {
       player.sendMessage("§4You must be in a shop to buy or sell!");
       return;
     }
   } catch (Exception e) {
     player.sendMessage("§4Invalid Parameters. Use /sellall");
     return;
   }
 }
예제 #30
0
 public void deleteDisplay() {
   FileConfiguration disp = hc.gYH().gFC("displays");
   disp.set(key, null);
   clearDisplay();
 }