diff --git a/Auto-Tune/src/resources/config.yml b/Auto-Tune/src/resources/config.yml index 3be9cda..5b4358a 100644 --- a/Auto-Tune/src/resources/config.yml +++ b/Auto-Tune/src/resources/config.yml @@ -93,6 +93,9 @@ data-selection-c: 1.05 ## -- Other Econonomy Settings -- +## Update prices for server when no players are online +update-prices-when-inactive: false + ## The symbol that appears before all currency currency-symbol: '$' diff --git a/Auto-Tune/src/unprotesting/com/github/Main.java b/Auto-Tune/src/unprotesting/com/github/Main.java index 800aa78..bd4f7f8 100644 --- a/Auto-Tune/src/unprotesting/com/github/Main.java +++ b/Auto-Tune/src/unprotesting/com/github/Main.java @@ -338,257 +338,260 @@ public void run() { } public static void loadItemPricesAndCalculate() throws ParseException { - setupMaxBuySell(); - tempbuys = 0.0; - tempsells = 0.0; - buys = 0.0; - sells = 0.0; - if (priceModel.contains("Basic") || priceModel.contains("Advanced") || priceModel.contains("Exponential")) { - TextHandler.sendDataBeforePriceCalculation(priceModel, basicVolatilityAlgorithim); - Set strSet = map.keySet(); - for (String str : strSet) { - ConcurrentHashMap tempMap = map.get(str); - Integer expvalues = 0; - Main.getINSTANCE(); - ConfigurationSection config = Main.getShopConfig().getConfigurationSection("shops") - .getConfigurationSection(str); - locked = null; - if (config != null) { - Boolean lk = config.getBoolean("locked", false); - if (lk == true) { - locked = falseBool; - debugLog("Locked item found: " + str); - } - tempbuys = 0.0; - tempsells = 0.0; - buys = 0.0; - sells = 0.0; - - if (priceModel.contains("Basic")) { - for (Integer key1 : tempMap.keySet()) { - Double[] key = tempMap.get(key1); - tempbuys = key[1]; - buys = buys + tempbuys; - tempsells = key[2]; - sells = sells + tempsells; + Integer playerCount = Bukkit.getServer().getOnlinePlayers().size(); + if (Config.isUpdatePricesWhenInactive() || (!Config.isUpdatePricesWhenInactive() && playerCount > 0)){ + setupMaxBuySell(); + tempbuys = 0.0; + tempsells = 0.0; + buys = 0.0; + sells = 0.0; + if (priceModel.contains("Basic") || priceModel.contains("Advanced") || priceModel.contains("Exponential")) { + TextHandler.sendDataBeforePriceCalculation(priceModel, basicVolatilityAlgorithim); + Set strSet = map.keySet(); + for (String str : strSet) { + ConcurrentHashMap tempMap = map.get(str); + Integer expvalues = 0; + Main.getINSTANCE(); + ConfigurationSection config = Main.getShopConfig().getConfigurationSection("shops") + .getConfigurationSection(str); + locked = null; + if (config != null) { + Boolean lk = config.getBoolean("locked", false); + if (lk == true) { + locked = falseBool; + debugLog("Locked item found: " + str); } - } + tempbuys = 0.0; + tempsells = 0.0; + buys = 0.0; + sells = 0.0; - if (priceModel.contains("Advanced")) { - for (Integer key1 : tempMap.keySet()) { - Double[] key = tempMap.get(key1); - tempbuys = key[1]; - tempbuys = tempbuys * key[0]; - if (tempbuys == 0) { - tempbuys = key[0]; - } - buys = buys + tempbuys; - tempsells = key[2]; - tempsells = tempsells * key[0]; - if (tempsells == 0) { - tempsells = key[0]; + if (priceModel.contains("Basic")) { + for (Integer key1 : tempMap.keySet()) { + Double[] key = tempMap.get(key1); + tempbuys = key[1]; + buys = buys + tempbuys; + tempsells = key[2]; + sells = sells + tempsells; } - sells = sells + tempsells; } - } - if (priceModel.contains("Exponential")) { - Integer tempSize = tempMap.keySet().size(); - Integer x = 0; - for (; x < 100000;) { - Double y = Config.getDataSelectionM() * (Math.pow(x, Config.getDataSelectionZ())) - + Config.getDataSelectionC(); - Integer inty = (int) Math.round(y) - 1; - if (inty > tempSize - 1) { - expvalues = inty + 1; - break; - } - Double[] key = tempMap.get((tempSize - 1) - inty); - tempbuys = key[1]; - tempbuys = tempbuys * key[0]; - if (tempbuys == 0) { - tempbuys = key[0]; + + if (priceModel.contains("Advanced")) { + for (Integer key1 : tempMap.keySet()) { + Double[] key = tempMap.get(key1); + tempbuys = key[1]; + tempbuys = tempbuys * key[0]; + if (tempbuys == 0) { + tempbuys = key[0]; + } + buys = buys + tempbuys; + tempsells = key[2]; + tempsells = tempsells * key[0]; + if (tempsells == 0) { + tempsells = key[0]; + } + sells = sells + tempsells; } - buys = buys + tempbuys; - tempsells = key[2]; - tempsells = tempsells * key[0]; - if (tempsells == 0) { - tempsells = key[0]; + } + if (priceModel.contains("Exponential")) { + Integer tempSize = tempMap.keySet().size(); + Integer x = 0; + for (; x < 100000;) { + Double y = Config.getDataSelectionM() * (Math.pow(x, Config.getDataSelectionZ())) + + Config.getDataSelectionC(); + Integer inty = (int) Math.round(y) - 1; + if (inty > tempSize - 1) { + expvalues = inty + 1; + break; + } + Double[] key = tempMap.get((tempSize - 1) - inty); + tempbuys = key[1]; + tempbuys = tempbuys * key[0]; + if (tempbuys == 0) { + tempbuys = key[0]; + } + buys = buys + tempbuys; + tempsells = key[2]; + tempsells = tempsells * key[0]; + if (tempsells == 0) { + tempsells = key[0]; + } + sells = sells + tempsells; + x++; } - sells = sells + tempsells; - x++; } - } - if ((Config.getInflationMethod().contains("Static") || Config.getInflationMethod().contains("Mixed")) - && Config.isInflationEnabled()) { - buys = buys + buys * 0.01 * Config.getInflationValue(); - } + if ((Config.getInflationMethod().contains("Static") || Config.getInflationMethod().contains("Mixed")) + && Config.isInflationEnabled()) { + buys = buys + buys * 0.01 * Config.getInflationValue(); + } - if (locked == falseBool) { - Double[] temp2 = tempMap.get(tempMap.size() - 1); - Double temp3 = temp2[0]; - Integer tsize = tempMap.size(); - Double newSpotPrice = temp3; - Double[] temporary = { newSpotPrice, 0.0, 0.0 }; - tempMap.put(tsize, temporary); - map.put(str, tempMap); - debugLog("Loading item, " + str + " with price " + Double.toString(temp3) + " as price is locked"); - } - Double avBuy = buys / (tempMap.size()); - Double avSells = sells / (tempMap.size()); - if (priceModel.contains("Advanced") || priceModel.contains("Basic")) { - avBuy = buys / (tempMap.size()); - avSells = sells / (tempMap.size()); - } - if (priceModel.contains("Exponential")) { - avBuy = buys / (expvalues); - avSells = sells / (expvalues); - } - if (avBuy > avSells && locked == null) { - if (priceModel.contains("Basic")) { - debugLog("AvBuy > AvSells for " + str); + if (locked == falseBool) { + Double[] temp2 = tempMap.get(tempMap.size() - 1); + Double temp3 = temp2[0]; + Integer tsize = tempMap.size(); + Double newSpotPrice = temp3; + Double[] temporary = { newSpotPrice, 0.0, 0.0 }; + tempMap.put(tsize, temporary); + map.put(str, tempMap); + debugLog("Loading item, " + str + " with price " + Double.toString(temp3) + " as price is locked"); } - if (priceModel.contains("Advanced") || priceModel.contains("Exponential")) { - debugLog("AvBuyValue > AvSellValue for " + str); + Double avBuy = buys / (tempMap.size()); + Double avSells = sells / (tempMap.size()); + if (priceModel.contains("Advanced") || priceModel.contains("Basic")) { + avBuy = buys / (tempMap.size()); + avSells = sells / (tempMap.size()); } - Double[] temp2 = tempMap.get(tempMap.size() - 1); - Double temp3 = temp2[0]; - Integer tsize = tempMap.size(); - if ((priceModel.contains("Basic") == true || priceModel.contains("Advanced") - || priceModel.contains("Exponential")) && basicVolatilityAlgorithim.contains("Fixed") == true) { - Double newSpotPrice = HttpPostRequestor.sendRequestForPrice("Fixed", priceModel, Config.getApiKey(), - Config.getEmail(), str, temp3, avBuy, avSells, Config.getBasicMaxFixedVolatility(), - Config.getBasicMinFixedVolatility()); - Double[] temporary = { newSpotPrice, 0.0, 0.0 }; + if (priceModel.contains("Exponential")) { + avBuy = buys / (expvalues); + avSells = sells / (expvalues); + } + if (avBuy > avSells && locked == null) { if (priceModel.contains("Basic")) { - debugLog("Loading item, " + str + ", with new price: " + Double.toString(newSpotPrice) - + " becasue Average buys = " + Double.toString(avBuy) + " and Average sells = " - + Double.toString(avSells)); + debugLog("AvBuy > AvSells for " + str); } if (priceModel.contains("Advanced") || priceModel.contains("Exponential")) { - debugLog("Loading item, " + str + ", with new price: " + Double.toString(newSpotPrice) - + " becasue Average buy value = " + Double.toString(avBuy) + " and Average sell value = " - + Double.toString(avSells)); + debugLog("AvBuyValue > AvSellValue for " + str); } - tempMap.put(tsize, temporary); - map.put(str, tempMap); + Double[] temp2 = tempMap.get(tempMap.size() - 1); + Double temp3 = temp2[0]; + Integer tsize = tempMap.size(); + if ((priceModel.contains("Basic") == true || priceModel.contains("Advanced") + || priceModel.contains("Exponential")) && basicVolatilityAlgorithim.contains("Fixed") == true) { + Double newSpotPrice = HttpPostRequestor.sendRequestForPrice("Fixed", priceModel, Config.getApiKey(), + Config.getEmail(), str, temp3, avBuy, avSells, Config.getBasicMaxFixedVolatility(), + Config.getBasicMinFixedVolatility()); + Double[] temporary = { newSpotPrice, 0.0, 0.0 }; + if (priceModel.contains("Basic")) { + debugLog("Loading item, " + str + ", with new price: " + Double.toString(newSpotPrice) + + " becasue Average buys = " + Double.toString(avBuy) + " and Average sells = " + + Double.toString(avSells)); + } + if (priceModel.contains("Advanced") || priceModel.contains("Exponential")) { + debugLog("Loading item, " + str + ", with new price: " + Double.toString(newSpotPrice) + + " becasue Average buy value = " + Double.toString(avBuy) + " and Average sell value = " + + Double.toString(avSells)); + } + tempMap.put(tsize, temporary); + map.put(str, tempMap); - } - if ((priceModel.contains("Basic") == true || priceModel.contains("Advanced") - || priceModel.contains("Exponential")) && basicVolatilityAlgorithim.contains("Variable") == true) { - Double newSpotPrice = HttpPostRequestor.sendRequestForPrice("Variable", priceModel, Config.getApiKey(), - Config.getEmail(), str, temp3, avBuy, avSells, Config.getBasicMaxVariableVolatility(), - Config.getBasicMinVariableVolatility()); - Double[] temporary = { newSpotPrice, 0.0, 0.0 }; - if (priceModel.contains("Basic")) { - debugLog("Loading item, " + str + ", with new price: " + Double.toString(newSpotPrice) - + " becasue Average buys = " + Double.toString(avBuy) + " and Average sells = " - + Double.toString(avSells)); } - if (priceModel.contains("Advanced") || priceModel.contains("Exponential")) { - debugLog("Loading item, " + str + ", with new price: " + Double.toString(newSpotPrice) - + " becasue Average buy value = " + Double.toString(avBuy) + " and Average sell value = " - + Double.toString(avSells)); + if ((priceModel.contains("Basic") == true || priceModel.contains("Advanced") + || priceModel.contains("Exponential")) && basicVolatilityAlgorithim.contains("Variable") == true) { + Double newSpotPrice = HttpPostRequestor.sendRequestForPrice("Variable", priceModel, Config.getApiKey(), + Config.getEmail(), str, temp3, avBuy, avSells, Config.getBasicMaxVariableVolatility(), + Config.getBasicMinVariableVolatility()); + Double[] temporary = { newSpotPrice, 0.0, 0.0 }; + if (priceModel.contains("Basic")) { + debugLog("Loading item, " + str + ", with new price: " + Double.toString(newSpotPrice) + + " becasue Average buys = " + Double.toString(avBuy) + " and Average sells = " + + Double.toString(avSells)); + } + if (priceModel.contains("Advanced") || priceModel.contains("Exponential")) { + debugLog("Loading item, " + str + ", with new price: " + Double.toString(newSpotPrice) + + " becasue Average buy value = " + Double.toString(avBuy) + " and Average sell value = " + + Double.toString(avSells)); + } + tempMap.put(tsize, temporary); + map.put(str, tempMap); } - tempMap.put(tsize, temporary); - map.put(str, tempMap); } - } - if (avBuy < avSells && locked == null) { - if (priceModel.contains("Basic")) { - debugLog("AvBuy < AvSells for " + str); - } - if (priceModel.contains("Advanced") || priceModel.contains("Exponential")) { - debugLog("AvBuyValue < AvSellValue for " + str); - } - Double[] temp2 = tempMap.get(tempMap.size() - 1); - Double temp3 = temp2[0]; - Integer tsize = tempMap.size(); - if ((priceModel.contains("Basic") == true || priceModel.contains("Advanced") - || priceModel.contains("Exponential")) && basicVolatilityAlgorithim.contains("Fixed")) { - Double newSpotPrice = HttpPostRequestor.sendRequestForPrice("Fixed", priceModel, Config.getApiKey(), - Config.getEmail(), str, temp3, avBuy, avSells, Config.getBasicMaxFixedVolatility(), - Config.getBasicMinFixedVolatility()); - Double[] temporary = { newSpotPrice, 0.0, 0.0 }; + if (avBuy < avSells && locked == null) { if (priceModel.contains("Basic")) { - debugLog("Loading item, " + str + ", with new price: " + Double.toString(newSpotPrice) - + " becasue Average buys = " + Double.toString(avBuy) + " and Average sells = " - + Double.toString(avSells)); + debugLog("AvBuy < AvSells for " + str); } if (priceModel.contains("Advanced") || priceModel.contains("Exponential")) { - debugLog("Loading item, " + str + ", with new price: " + Double.toString(newSpotPrice) - + " becasue Average buy value = " + Double.toString(avBuy) + " and Average sell value = " - + Double.toString(avSells)); + debugLog("AvBuyValue < AvSellValue for " + str); } - tempMap.put(tsize, temporary); - map.put(str, tempMap); - } - if ((priceModel.contains("Basic") == true || priceModel.contains("Advanced") - || priceModel.contains("Exponential")) && basicVolatilityAlgorithim.contains("Variable") == true) { - Double newSpotPrice = HttpPostRequestor.sendRequestForPrice("Variable", priceModel, Config.getApiKey(), - Config.getEmail(), str, temp3, avBuy, avSells, Config.getBasicMaxVariableVolatility(), - Config.getBasicMinVariableVolatility()); - Double[] temporary = { newSpotPrice, 0.0, 0.0 }; - if (priceModel.contains("Basic")) { - debugLog("Loading item, " + str + ", with new price: " + Double.toString(newSpotPrice) - + " becasue Average buys = " + Double.toString(avBuy) + " and Average sells = " - + Double.toString(avSells)); + Double[] temp2 = tempMap.get(tempMap.size() - 1); + Double temp3 = temp2[0]; + Integer tsize = tempMap.size(); + if ((priceModel.contains("Basic") == true || priceModel.contains("Advanced") + || priceModel.contains("Exponential")) && basicVolatilityAlgorithim.contains("Fixed")) { + Double newSpotPrice = HttpPostRequestor.sendRequestForPrice("Fixed", priceModel, Config.getApiKey(), + Config.getEmail(), str, temp3, avBuy, avSells, Config.getBasicMaxFixedVolatility(), + Config.getBasicMinFixedVolatility()); + Double[] temporary = { newSpotPrice, 0.0, 0.0 }; + if (priceModel.contains("Basic")) { + debugLog("Loading item, " + str + ", with new price: " + Double.toString(newSpotPrice) + + " becasue Average buys = " + Double.toString(avBuy) + " and Average sells = " + + Double.toString(avSells)); + } + if (priceModel.contains("Advanced") || priceModel.contains("Exponential")) { + debugLog("Loading item, " + str + ", with new price: " + Double.toString(newSpotPrice) + + " becasue Average buy value = " + Double.toString(avBuy) + " and Average sell value = " + + Double.toString(avSells)); + } + tempMap.put(tsize, temporary); + map.put(str, tempMap); } - if (priceModel.contains("Advanced") || priceModel.contains("Exponential")) { - debugLog("Loading item, " + str + ", with new price: " + Double.toString(newSpotPrice) - + " becasue Average buy value = " + Double.toString(avBuy) + " and Average sell value = " - + Double.toString(avSells)); + if ((priceModel.contains("Basic") == true || priceModel.contains("Advanced") + || priceModel.contains("Exponential")) && basicVolatilityAlgorithim.contains("Variable") == true) { + Double newSpotPrice = HttpPostRequestor.sendRequestForPrice("Variable", priceModel, Config.getApiKey(), + Config.getEmail(), str, temp3, avBuy, avSells, Config.getBasicMaxVariableVolatility(), + Config.getBasicMinVariableVolatility()); + Double[] temporary = { newSpotPrice, 0.0, 0.0 }; + if (priceModel.contains("Basic")) { + debugLog("Loading item, " + str + ", with new price: " + Double.toString(newSpotPrice) + + " becasue Average buys = " + Double.toString(avBuy) + " and Average sells = " + + Double.toString(avSells)); + } + if (priceModel.contains("Advanced") || priceModel.contains("Exponential")) { + debugLog("Loading item, " + str + ", with new price: " + Double.toString(newSpotPrice) + + " becasue Average buy value = " + Double.toString(avBuy) + " and Average sell value = " + + Double.toString(avSells)); + } + tempMap.put(tsize, temporary); + map.put(str, tempMap); } - tempMap.put(tsize, temporary); - map.put(str, tempMap); - } - } + } - if (avBuy == avSells && locked == null) { - debugLog("AvBuy = AvSells for " + str); - Double[] temp2 = tempMap.get(tempMap.size() - 1); - Double temp3 = temp2[0]; - Integer tsize = tempMap.size(); - if (priceModel.contains("Basic") == true || priceModel.contains("Advanced") - || priceModel.contains("Exponential")) { - Double newSpotPrice = HttpPostRequestor.sendRequestForPrice("Variable", priceModel, Config.getApiKey(), - Config.getEmail(), str, temp3, avBuy, avSells, Config.getBasicMaxVariableVolatility(), - Config.getBasicMinVariableVolatility()); - Double[] temporary = { newSpotPrice, 0.0, 0.0 }; - if (priceModel.contains("Basic")) { - debugLog("Loading item, " + str + ", with the same price: " + Double.toString(newSpotPrice) - + " becasue Average buys = " + Double.toString(avBuy) + " and Average sells = " - + Double.toString(avSells)); - } - if (priceModel.contains("Advanced") || priceModel.contains("Exponential")) { - debugLog("Loading item, " + str + ", with the same price: " + Double.toString(newSpotPrice) - + " becasue Average buy value = " + Double.toString(avBuy) + " and Average sell value = " - + Double.toString(avSells)); + if (avBuy == avSells && locked == null) { + debugLog("AvBuy = AvSells for " + str); + Double[] temp2 = tempMap.get(tempMap.size() - 1); + Double temp3 = temp2[0]; + Integer tsize = tempMap.size(); + if (priceModel.contains("Basic") == true || priceModel.contains("Advanced") + || priceModel.contains("Exponential")) { + Double newSpotPrice = HttpPostRequestor.sendRequestForPrice("Variable", priceModel, Config.getApiKey(), + Config.getEmail(), str, temp3, avBuy, avSells, Config.getBasicMaxVariableVolatility(), + Config.getBasicMinVariableVolatility()); + Double[] temporary = { newSpotPrice, 0.0, 0.0 }; + if (priceModel.contains("Basic")) { + debugLog("Loading item, " + str + ", with the same price: " + Double.toString(newSpotPrice) + + " becasue Average buys = " + Double.toString(avBuy) + " and Average sells = " + + Double.toString(avSells)); + } + if (priceModel.contains("Advanced") || priceModel.contains("Exponential")) { + debugLog("Loading item, " + str + ", with the same price: " + Double.toString(newSpotPrice) + + " becasue Average buy value = " + Double.toString(avBuy) + " and Average sell value = " + + Double.toString(avSells)); + } + tempMap.put(tsize, temporary); + map.put(str, tempMap); } - tempMap.put(tsize, temporary); - map.put(str, tempMap); + locked = null; } - locked = null; } } - } - tempbuys = 0.0; - tempsells = 0.0; - buys = 0.0; - sells = 0.0; - Date date = Calendar.getInstance().getTime(); - Date newDate = MathHandler.addMinutesToJavaUtilDate(date, Config.getTimePeriod()); - String strDate = dateFormat.format(newDate); - debugLog("Done running price Algorithim, a new check will occur at: " + strDate); - try { - debugLog("Saving data to data.csv file"); - CSVHandler.writeCSV(); - CSVHandler.writeShortCSV(); - debugLog("Saved data to data.csv file"); - } catch (InterruptedException | IOException e) { - e.printStackTrace(); + tempbuys = 0.0; + tempsells = 0.0; + buys = 0.0; + sells = 0.0; + Date date = Calendar.getInstance().getTime(); + Date newDate = MathHandler.addMinutesToJavaUtilDate(date, Config.getTimePeriod()); + String strDate = dateFormat.format(newDate); + debugLog("Done running price Algorithim, a new check will occur at: " + strDate); + try { + debugLog("Saving data to data.csv file"); + CSVHandler.writeCSV(); + CSVHandler.writeShortCSV(); + debugLog("Saved data to data.csv file"); + } catch (InterruptedException | IOException e) { + e.printStackTrace(); + } } } } diff --git a/Auto-Tune/src/unprotesting/com/github/util/Config.java b/Auto-Tune/src/unprotesting/com/github/util/Config.java index 5b7f8b3..6ea599e 100644 --- a/Auto-Tune/src/unprotesting/com/github/util/Config.java +++ b/Auto-Tune/src/unprotesting/com/github/util/Config.java @@ -17,7 +17,8 @@ public final class Config { inflationEnabled, autoSellEnabled, calculateGlobalGDP, - tutorial; + tutorial, + updatePricesWhenInactive; @Getter @Setter @@ -65,6 +66,7 @@ public final class Config { public static void loadDefaults() { + Config.setUpdatePricesWhenInactive(Main.getMainConfig().getBoolean("update-prices-when-inactive", false)); Config.setSellPriceDifferenceVariationEnabled(Main.getMainConfig().getBoolean("sell-price-difference-variation-enabled", true)); Config.setWebServer(Main.getMainConfig().getBoolean("web-server-enabled", true)); Config.setTutorial(Main.getMainConfig().getBoolean("tutorial", true));