diff --git a/src/main/java/unprotesting/com/github/Main.java b/src/main/java/unprotesting/com/github/Main.java index 4d7eb12..6de281d 100644 --- a/src/main/java/unprotesting/com/github/Main.java +++ b/src/main/java/unprotesting/com/github/Main.java @@ -91,7 +91,9 @@ public void onEnable() { setupDataFiles(); mm = MiniMessage.miniMessage(); UtilFunctions.setDf(new DecimalFormat(Config.getConfig().getNumberFormat())); - getLogger().setLevel(Level.parse(Config.getConfig().getLogLevel().toUpperCase())); + Level logLevel = Level.parse(Config.getConfig().getLogLevel()); + getLogger().setLevel(logLevel); + getLogger().info("Log level set to " + getLogger().getLevel().toString()); new Messages(); Bukkit.getScheduler().runTaskAsynchronously(this, () -> @@ -112,9 +114,11 @@ public void onEnable() { */ public void updateTimePeriod() { + getLogger().config("Updating time period."); new TimePeriod().addToMap(); cache = new LocalDataCache(); - if (Config.getConfig().isWebServer()) { + if (Config.getConfig().isWebServerEnabled()) { + getLogger().fine("Writing CSV file"); CsvHandler.writeCsv(); } @@ -128,6 +132,7 @@ private void checkEconomy() { // Check if an economy plugin is installed and if it is enabled, if it is return. if (EconomyFunctions.setupLocalEconomy(getServer())) { + getLogger().info("Found an economy plugin."); return; } @@ -225,11 +230,13 @@ private void getEssentials() { // If essentials is not installed, set essentialsEnabled to false and return. if (plugin == null) { setEssentialsEnabled(false); + getLogger().info("Essentials not found."); return; } setEssentialsEnabled(true); setEss((IEssentials) plugin); + getLogger().info("Found Essentials."); } diff --git a/src/main/java/unprotesting/com/github/config/Config.java b/src/main/java/unprotesting/com/github/config/Config.java index cba9668..9e3ea5e 100644 --- a/src/main/java/unprotesting/com/github/config/Config.java +++ b/src/main/java/unprotesting/com/github/config/Config.java @@ -14,7 +14,7 @@ public class Config { @Getter private static Config config; - private boolean webServer; + private boolean webServerEnabled; private boolean sellPriceDifferenceVariationEnabled; private boolean tutorial; private boolean disableMaxBuysSells; @@ -66,7 +66,7 @@ private void loadConfig() { FileConfiguration configF = Main.getInstance().getDataFiles().getConfig(); setApiKey(configF.getString("apiKey", "xyz")); setEmail(configF.getString("email", "xyz@gmail.com")); - setWebServer(configF.getBoolean("web-server-enabled", true)); + setWebServerEnabled(configF.getBoolean("web-server-enabled", true)); setPort(configF.getInt("port", 8123)); setTimePeriod(configF.getInt("time-period", 30)); setMenuTitle(configF.getString("menu-title", "Shop")); diff --git a/src/main/java/unprotesting/com/github/data/csv/CsvHandler.java b/src/main/java/unprotesting/com/github/data/csv/CsvHandler.java index b17da94..3dba8ac 100644 --- a/src/main/java/unprotesting/com/github/data/csv/CsvHandler.java +++ b/src/main/java/unprotesting/com/github/data/csv/CsvHandler.java @@ -1,9 +1,9 @@ package unprotesting.com.github.data.csv; +import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.util.Arrays; -import java.util.Collections; import java.util.List; import unprotesting.com.github.Main; @@ -21,7 +21,7 @@ public class CsvHandler { public static void writeCsv() { try { - write("trade", 0); + write("trade.csv", 0); } catch (IOException e) { Main.getInstance().getLogger().severe("Could not write to csv file."); } @@ -29,93 +29,61 @@ public static void writeCsv() { } /** - * Creates a CSV file with all price, buy and sell data to be read by the webpage. - * @param csvName The name of the csv file. - * @param cutoffValue The cutoff value for the data. - * @throws IOException If the file could not be created. + * Write the latest x rows of price data. + * @param fileName The name of the file to write to. + * @param rows The number of rows to write. */ - private static void write(String csvName, int cutoffValue) throws IOException { - - int cutoff = cutoffValue; - FileWriter writer = new FileWriter("plugins/Auto-Tune/web/" + csvName + ".csv"); + private static void write(String fileName, int rows) throws IOException { + FileWriter fileStream = new FileWriter(Config.getConfig().getDataLocation() + fileName); + BufferedWriter writer = new BufferedWriter(fileStream); int size = Main.getInstance().getDatabase().getMap().size(); TimePeriod tp = Main.getInstance().getDatabase().getMap().get(size - 1); List items = Arrays.asList(tp.getItemTP().getItems()); List enchantments = Arrays.asList(tp.getEnchantmentsTP().getItems()); + writer.write("GDP,Balance,Debt,Loss,Inflation"); - if (size < cutoff || cutoff < 3) { - cutoff = size; + if (rows == -1) { + rows = size; } - - Collections.sort(items); - Collections.sort(enchantments); - + for (String item : items) { - - writer.write("\n" + "%" + item + "\n"); - - for (int i = (size - cutoff); i < size; i++) { - - ItemTimePeriod itp = Main.getInstance().getDatabase().getMap().get(i).getItemTP(); - int pos = Arrays.asList(itp.getItems()).indexOf(item); - - writer.append(i + "," + itp.getPrices()[pos] + "," - + itp.getBuys()[pos] + "," + itp.getSells()[pos] + "\n"); - - } - + writer.write(item + ","); } if (Config.getConfig().isEnableEnchantments()) { - for (String enchantment : enchantments) { + writer.write(enchantment.toUpperCase() + ","); + } + } - writer.write("\n" + "%" + enchantment + "\n"); - - for (int i = (size - cutoff); i < size; i++) { + writer.write("\n"); - EnchantmentsTimePeriod etp = Main.getInstance().getDatabase() - .getMap().get(i).getEnchantmentsTP(); + for (int i = (size - rows); i < size; i++) { + GdpTimePeriod gtp = Main.getInstance().getDatabase().getMap().get(i).getGdpTP(); - int pos = Arrays.asList(etp.getItems()).indexOf(enchantment); + writer.write(gtp.getGdp() + "," + + gtp.getBalance() + "," + + gtp.getDebt() + "," + + gtp.getLoss() + "," + + gtp.getInflation()); - writer.append(i + "," + etp.getPrices()[pos] + "," - + etp.getBuys()[pos] + "," + etp.getSells()[pos] + "\n"); + ItemTimePeriod itp = Main.getInstance().getDatabase().getMap().get(i).getItemTP(); - } + EnchantmentsTimePeriod etp = Main.getInstance() + .getDatabase().getMap().get(i).getEnchantmentsTP(); + if (itp == null) { + continue; } - } - - for (int k = 0; k < 5; k++) { - - if (k == 0) { - writer.write("\n" + "%GDP" + "\n"); - } else if (k == 1) { - writer.write("\n" + "%Balance" + "\n"); - } else if (k == 2) { - writer.write("\n" + "%Debt" + "\n"); - } else if (k == 3) { - writer.write("\n" + "%Loss" + "\n"); - } else if (k == 4) { - writer.write("\n" + "%Inflation" + "\n"); + for (int j = 0; j < itp.getItems().length; j++) { + writer.write("," + itp.getPrices()[j]); } - for (int i = (size - cutoff); i < size; i++) { + if (Config.getConfig().isEnableEnchantments()) { - GdpTimePeriod gtp = Main.getInstance().getDatabase().getMap().get(i).getGdpTP(); - - if (k == 0) { - writer.write(i + "," + gtp.getGdp() + "\n"); - } else if (k == 1) { - writer.write(i + "," + gtp.getBalance() + "\n"); - } else if (k == 2) { - writer.write(i + "," + gtp.getDebt() + "\n"); - } else if (k == 3) { - writer.write(i + "," + gtp.getLoss() + "\n"); - } else if (k == 4) { - writer.write(i + "," + gtp.getInflation() + "\n"); + for (int j = 0; j < etp.getItems().length; j++) { + writer.write("," + etp.getPrices()[j]); } } @@ -123,7 +91,7 @@ private static void write(String csvName, int cutoffValue) throws IOException { } writer.close(); - + } } diff --git a/src/main/java/unprotesting/com/github/events/async/PriceUpdateEvent.java b/src/main/java/unprotesting/com/github/events/async/PriceUpdateEvent.java index 5c1589a..7f68dcd 100644 --- a/src/main/java/unprotesting/com/github/events/async/PriceUpdateEvent.java +++ b/src/main/java/unprotesting/com/github/events/async/PriceUpdateEvent.java @@ -38,10 +38,19 @@ public PriceUpdateEvent(boolean isAsync) { */ private void calculateAndLoad() { + int playerCount = UtilFunctions.calculatePlayerCount(); + // If the player count is less than "update-prices-threshold" then don't update the prices. - if (UtilFunctions.calculatePlayerCount() < Config.getConfig().getUpdatePricesThreshold()) { + if (playerCount < Config.getConfig().getUpdatePricesThreshold()) { + + Main.getInstance().getLogger().info("Player count is less than " + + Config.getConfig().getUpdatePricesThreshold() + + " so not updating prices."); + return; } + + Main.getInstance().getLogger().info("Calculating prices as player count is " + playerCount); Main.getInstance().updateTimePeriod(); updateItems(); @@ -65,13 +74,21 @@ private void updateItems() { continue; } - + ItemData data = Main.getInstance().getCache().getItems().get(item); + double initialPrice = data.getPrice(); double[] sb = loadAverageBuySellValue(item, false); double[] volatility = getMaxMinVolatility("shops", item); data.setPrice(UtilFunctions.calculateNewPrice(data.getPrice(), volatility, sb[0], sb[1])); Main.getInstance().getCache().getItems().put(item, data); + if (data.getPrice() != initialPrice) { + + Main.getInstance().getLogger().info("Updated price of " + + item + " from " + initialPrice + " to " + data.getPrice()); + + } + } } diff --git a/src/main/java/unprotesting/com/github/events/async/SellPriceDifferenceUpdateEvent.java b/src/main/java/unprotesting/com/github/events/async/SellPriceDifferenceUpdateEvent.java index 73212ee..2ca4efe 100644 --- a/src/main/java/unprotesting/com/github/events/async/SellPriceDifferenceUpdateEvent.java +++ b/src/main/java/unprotesting/com/github/events/async/SellPriceDifferenceUpdateEvent.java @@ -43,12 +43,15 @@ private void updateSellPriceDifference() { // If the new sell price difference is greater than the minimum then update it. if (newSpd > Main.getInstance().getDataFiles().getConfig() - .getDouble("sell-price-difference", 10)) { + .getDouble("sell-price-difference", 15)) { Main.getInstance().getCache().getEconomyInfo().updateSellPriceDifference(newSpd); - + } + Main.getInstance().getLogger().finer("Sell price difference changed from " + + spd + " to " + newSpd); + } } diff --git a/src/main/java/unprotesting/com/github/localserver/LocalServer.java b/src/main/java/unprotesting/com/github/localserver/LocalServer.java index 413fdb7..6973d5b 100644 --- a/src/main/java/unprotesting/com/github/localserver/LocalServer.java +++ b/src/main/java/unprotesting/com/github/localserver/LocalServer.java @@ -18,7 +18,7 @@ public class LocalServer { public LocalServer() { // If "web-server-enabled" is false, don't start the server. - if (!Config.getConfig().isWebServer()) { + if (!Config.getConfig().isWebServerEnabled()) { return; } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 64e7549..97b6784 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -12,12 +12,6 @@ ## -- General Settings -- ## -## API key given on sign-up -api-key: 'xyz' - -## Email used on sign-up -email: 'xyz@gmail.com' - ## Enable/Disable integrated Web Server. ## Info: Use /trade to view the web-server web-server-enabled: true diff --git a/src/main/resources/web/trade.html b/src/main/resources/web/trade.html index e176119..c1ac6a9 100644 --- a/src/main/resources/web/trade.html +++ b/src/main/resources/web/trade.html @@ -1,149 +1,25 @@ - - - - - - - Minecraft Economy Plugin - - - + + + + + + + - - -
- -
- - -