diff --git a/Auto-Tune/dependency-reduced-pom.xml b/Auto-Tune/dependency-reduced-pom.xml index 9abf0b9..ea06b8a 100644 --- a/Auto-Tune/dependency-reduced-pom.xml +++ b/Auto-Tune/dependency-reduced-pom.xml @@ -4,7 +4,7 @@ unprotesting.com.github Auto-Tune Auto-Tune - 0.12.1 + 0.12.2 The automatic pricing plugin for minecraft https://github.com/Unprotesting/Auto-Tune diff --git a/Auto-Tune/pom.xml b/Auto-Tune/pom.xml index fceb86c..2bb4f5c 100644 --- a/Auto-Tune/pom.xml +++ b/Auto-Tune/pom.xml @@ -9,7 +9,7 @@ unprotesting.com.github Auto-Tune - 0.12.1 + 0.12.2 Auto-Tune https://github.com/Unprotesting/Auto-Tune diff --git a/Auto-Tune/src/resources/config.yml b/Auto-Tune/src/resources/config.yml index d573d54..a1ed9cd 100644 --- a/Auto-Tune/src/resources/config.yml +++ b/Auto-Tune/src/resources/config.yml @@ -164,3 +164,11 @@ tutorial: true ## Time in seconds between messages tutorial-message-period: 325 + +## Data storage location +data-location: 'plugins/Auto-Tune/' + +## Enable transactions +## Info: This will result in much larger file sizes and additional transaction files but more stability and improved data-protection +## Info: This is off by default as the default data protection will be fine for most servers +data-transactions: false diff --git a/Auto-Tune/src/resources/plugin.yml b/Auto-Tune/src/resources/plugin.yml index 85278e8..110f0cb 100644 --- a/Auto-Tune/src/resources/plugin.yml +++ b/Auto-Tune/src/resources/plugin.yml @@ -21,9 +21,11 @@ commands: at: description: Auto-Tune Command. usage: / + aliases: [autotune] trade: description: Trade Online with other players. usage: / + aliases: [pricehistory, onlinepricehistory] shop: description: GUIShop alias for buy and sell commands. usage: / @@ -43,6 +45,7 @@ commands: description: View and change plugin config settings buy: description: Buy items not available in the shop + aliases: [purchase] permssions: at.help: description: Displays Auto-Tune help information diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java index 988aac5..d30bfa8 100644 --- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java +++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java @@ -27,96 +27,99 @@ public class AutoTuneBuyCommand implements CommandExecutor { @Deprecated @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player){ - Player player = (Player) sender; - if (!(player.hasPermission("at.buy") || player.isOp())){ - TextHandler.noPermssion(player); - return true; - } - if (args.length == 0){ - player.sendMessage(ChatColor.YELLOW + "Command Usage: "); - player.sendMessage(ChatColor.YELLOW + "/buy: "); - for (String str : shopTypes){ - player.sendMessage(ChatColor.YELLOW + "Available shop: '" + str + "'"); + if(command.getName().equalsIgnoreCase("buy")){ + if (sender instanceof Player){ + Player player = (Player) sender; + if (!(player.hasPermission("at.buy") || player.isOp())){ + TextHandler.noPermssion(player); return true; } - } - if (args.length == 1){ - if (args[0].contains("enchantments")){ - ConcurrentHashMap inputMap = Main.enchMap.get("Auto-Tune"); - for (String str : Main.enchMap.get("Auto-Tune").keySet()){ - EnchantmentSetting setting = inputMap.get(str); - player.sendMessage(ChatColor.WHITE + "Enchantment: " + ChatColor.AQUA + str + ChatColor.YELLOW + - " | Price : "+ Config.getCurrencySymbol() + AutoTuneGUIShopUserCommand.df2.format(setting.price) + " | Item Multiplier: " + setting.ratio + "x"); + if (args.length == 0){ + player.sendMessage(ChatColor.YELLOW + "Command Usage: "); + player.sendMessage(ChatColor.YELLOW + "/buy: "); + for (String str : shopTypes){ + player.sendMessage(ChatColor.YELLOW + "Available shop: '" + str + "'"); + return true; } - return true; - } - else{ - player.sendMessage(ChatColor.RED + "Shop " + args[0] + " not found!"); - return false; } - } - if (args.length == 2){ - if (args[0].contains("enchantments")){ - ConcurrentHashMap inputMap = Main.enchMap.get("Auto-Tune"); - EnchantmentSetting setting = inputMap.get((args[1].toUpperCase())); - ItemStack is = player.getInventory().getItemInMainHand(); - Material mat = is.getType(); - boolean enchantExists = false; - Map map = is.getEnchantments(); - Enchantment ench = Enchantment.getByName(setting.name); - if (map.get(ench) != null){ - enchantExists = true; + if (args.length == 1){ + if (args[0].contains("enchantments")){ + ConcurrentHashMap inputMap = Main.enchMap.get("Auto-Tune"); + for (String str : Main.enchMap.get("Auto-Tune").keySet()){ + EnchantmentSetting setting = inputMap.get(str); + player.sendMessage(ChatColor.WHITE + "Enchantment: " + ChatColor.AQUA + str + ChatColor.YELLOW + + " | Price : "+ Config.getCurrencySymbol() + AutoTuneGUIShopUserCommand.df2.format(setting.price) + " | Item Multiplier: " + setting.ratio + "x"); + } + return true; + } + else{ + player.sendMessage(ChatColor.RED + "Shop " + args[0] + " not found!"); + return false; } - if (is != null){ - try{ - if (!enchantExists){ - is.addEnchantment(ench, 1); + } + if (args.length == 2){ + if (args[0].contains("enchantments")){ + ConcurrentHashMap inputMap = Main.enchMap.get("Auto-Tune"); + EnchantmentSetting setting = inputMap.get((args[1].toUpperCase())); + ItemStack is = player.getInventory().getItemInMainHand(); + Material mat = is.getType(); + boolean enchantExists = false; + Map map = is.getEnchantments(); + Enchantment ench = Enchantment.getByName(setting.name); + if (map.get(ench) != null){ + enchantExists = true; + } + if (is != null){ + try{ + if (!enchantExists){ + is.addEnchantment(ench, 1); + } + else{ + int level = is.getEnchantmentLevel(ench); + is.addEnchantment(ench, level+1); + } } - else{ - int level = is.getEnchantmentLevel(ench); - is.addEnchantment(ench, level+1); + catch(IllegalArgumentException ex){ + player.sendMessage(ChatColor.RED + "Cannot enchant item: " + is.getType().toString() + " with enchantment " + setting.name); + ex.printStackTrace(); + return true; } - } - catch(IllegalArgumentException ex){ - player.sendMessage(ChatColor.RED + "Cannot enchant item: " + is.getType().toString() + " with enchantment " + setting.name); - ex.printStackTrace(); + double price = setting.price + Main.map.get(is.getType().toString()).get(Main.map.get(is.getType().toString()).size()-1)[0]*setting.ratio; + Main.getEconomy().withdrawPlayer(player, Double.parseDouble(AutoTuneGUIShopUserCommand.df1.format(price))); + player.sendMessage(ChatColor.GOLD + "Purchased " + setting.name + " for " + + ChatColor.GREEN + Config.getCurrencySymbol() + AutoTuneGUIShopUserCommand.df2.format(price)); + ConcurrentHashMap buySellMap = setting.buySellData; + Double[] arr = buySellMap.get(buySellMap.size()-1); + if (arr == null){ + arr = new Double[]{setting.price, 0.0, 0.0}; + } + if (arr[1] == null){ + arr[1] = 0.0; + } + if (arr[2] == null){ + arr[2] = 0.0; + } + arr[1] = arr[1]+1; + buySellMap.put(buySellMap.size()-1, arr); + setting.buySellData = buySellMap; + inputMap.put(setting.name, setting); + Main.enchMap.put("Auto-Tune", inputMap); return true; } - double price = setting.price + Main.map.get(is.getType().toString()).get(Main.map.get(is.getType().toString()).size()-1)[0]*setting.ratio; - Main.getEconomy().withdrawPlayer(player, Double.parseDouble(AutoTuneGUIShopUserCommand.df1.format(price))); - player.sendMessage(ChatColor.GOLD + "Purchased " + setting.name + " for " - + ChatColor.GREEN + Config.getCurrencySymbol() + AutoTuneGUIShopUserCommand.df2.format(price)); - ConcurrentHashMap buySellMap = setting.buySellData; - Double[] arr = buySellMap.get(buySellMap.size()-1); - if (arr == null){ - arr = new Double[]{setting.price, 0.0, 0.0}; - } - if (arr[1] == null){ - arr[1] = 0.0; - } - if (arr[2] == null){ - arr[2] = 0.0; - } - arr[1] = arr[1]+1; - buySellMap.put(buySellMap.size()-1, arr); - setting.buySellData = buySellMap; - inputMap.put(setting.name, setting); - Main.enchMap.put("Auto-Tune", inputMap); + player.sendMessage(ChatColor.RED + "Hold the item you want to enchant in your main hand!"); return true; } - player.sendMessage(ChatColor.RED + "Hold the item you want to enchant in your main hand!"); - return true; - } - else{ - player.sendMessage("Shop " + args[0] + "not found!"); - return false; + else{ + player.sendMessage("Shop " + args[0] + "not found!"); + return false; + } } } - } - else{ - Main.sendMessage(sender, "&cPlayers only."); - return true; + else{ + Main.sendMessage(sender, "&cPlayers only."); + return true; + } + return false; } return false; } diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGDPCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGDPCommand.java index 92fbdb5..cd8b031 100644 --- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGDPCommand.java +++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGDPCommand.java @@ -22,14 +22,13 @@ public boolean onCommand(CommandSender sender, Command command, String gdp, Stri if (command.getName().equalsIgnoreCase("gdp")){ if (args.length < 1){ if (p.hasPermission("at.gdp") || p.isOp()){ - String GDP = AutoTuneGUIShopUserCommand.df4.format(Main.tempdatadata.get("GDP")); - double returnedGDP = Double.parseDouble(GDP); + String GDP = AutoTuneGUIShopUserCommand.df2.format(Main.tempdatadata.get("GDP")); double[] serverBalance = getServerBalance(); double loanBalance = getLoanBalance(); - p.sendMessage(ChatColor.GOLD + "The Current GDP is: $" + ChatColor.GREEN + AutoTuneGUIShopUserCommand.df1.format(returnedGDP)); - p.sendMessage(ChatColor.GOLD + "The Current GDP per capita is: $" + ChatColor.GREEN + AutoTuneGUIShopUserCommand.df2.format(returnedGDP/serverBalance[1])); - p.sendMessage(ChatColor.GOLD + "The Current Average Balance is: $" + ChatColor.GREEN + (serverBalance[0]/serverBalance[1])); - p.sendMessage(ChatColor.GOLD + "The Current Average Debt is: $" + ChatColor.GREEN + (loanBalance/serverBalance[1])); + p.sendMessage(ChatColor.GOLD + "The Current GDP is: $" + ChatColor.GREEN + GDP); + p.sendMessage(ChatColor.GOLD + "The Current GDP per capita is: $" + ChatColor.GREEN + AutoTuneGUIShopUserCommand.df2.format(Main.tempdatadata.get("GDP")/serverBalance[1])); + p.sendMessage(ChatColor.GOLD + "The Current Average Balance is: $" + ChatColor.GREEN + AutoTuneGUIShopUserCommand.df2.format(serverBalance[0]/serverBalance[1])); + p.sendMessage(ChatColor.GOLD + "The Current Average Debt is: $" + ChatColor.GREEN + AutoTuneGUIShopUserCommand.df2.format(loanBalance/serverBalance[1])); } else if (!(p.hasPermission("at.gdp")) && !(p.isOp())){ TextHandler.noPermssion(p); diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java index beb0fd3..5573da0 100644 --- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java +++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java @@ -290,7 +290,7 @@ public static OutlinePane loadTradingItems(String itemName, Section sec, Outline player.sendMessage(ChatColor.BOLD + "Cant Sell " + Integer.toString(amounts[finalI - 7]) + "x of " + itemName); } - if (max[1] < (currentMax + amounts[finalI - 7])) { + else if (max[1] < (currentMax + amounts[finalI - 7])) { player.sendMessage(ChatColor.BOLD + "Cant Sell " + Integer.toString(amounts[finalI - 7]) + "x of " + itemName); int difference = (currentMax + amounts[finalI - 7]) - max[1]; @@ -299,7 +299,8 @@ public static OutlinePane loadTradingItems(String itemName, Section sec, Outline Main.maxSellMap.put(player.getUniqueId(), maxSellMapRec); } player.sendMessage(ChatColor.RED + "Max Sells Reached! - " + max[1] + "/" + max[1]); - } else { + } + else { removeItems(player, (finalI - 7), itemName, sec, 0); } } else { diff --git a/Auto-Tune/src/unprotesting/com/github/Main.java b/Auto-Tune/src/unprotesting/com/github/Main.java index f8cd4d0..4f18020 100644 --- a/Auto-Tune/src/unprotesting/com/github/Main.java +++ b/Auto-Tune/src/unprotesting/com/github/Main.java @@ -268,7 +268,6 @@ public void onEnable() { this.getCommand("buy").setExecutor(new AutoTuneBuyCommand()); basicVolatilityAlgorithim = Config.getBasicVolatilityAlgorithim(); priceModel = Config.getPricingModel().toString(); - TextHandler.sendPriceModelData(priceModel); scheduler = getServer().getScheduler(); if (Config.isAutoSellEnabled()){ scheduler.scheduleSyncRepeatingTask(getINSTANCE(), new AutoSellEventHandler(), Config.getAutoSellUpdatePeriod() * 5, @@ -451,16 +450,27 @@ public static FileConfiguration saveGUIShopFiles(){ } public static void setupDataFiles() { + String dataLocationString = (Config.getDataLocation() + "data.db"); if (Config.isChecksumHeaderBypass()) { Main.debugLog("Enabling checksum-header-bypass"); - db = DBMaker.fileDB("data.db").checksumHeaderBypass().fileChannelEnable().allocateStartSize(10240).transactionEnable().closeOnJvmShutdown().make(); + if (Config.isDataTransactions()){ + db = DBMaker.fileDB(dataLocationString).checksumHeaderBypass().fileChannelEnable().allocateStartSize(10240).transactionEnable().closeOnJvmShutdown().make(); + } + else{ + db = DBMaker.fileDB(dataLocationString).checksumHeaderBypass().fileChannelEnable().allocateStartSize(10240).closeOnJvmShutdown().make(); + } map = (ConcurrentMap>) db.hashMap("map").createOrOpen(); memDB = DBMaker.heapDB().checksumHeaderBypass().transactionEnable().closeOnJvmShutdown().make(); memMap = memDB.hashMap("memMap", Serializer.INTEGER, Serializer.STRING).createOrOpen(); enchDB = DBMaker.fileDB("enchantment-data.db").checksumHeaderBypass().fileChannelEnable().transactionEnable().closeOnJvmShutdown().make(); enchMap = (ConcurrentMap>) enchDB.hashMap("enchMap", Serializer.STRING, Serializer.JAVA).createOrOpen(); } else { - db = DBMaker.fileDB("data.db").checksumHeaderBypass().fileChannelEnable().allocateStartSize(10240).transactionEnable().closeOnJvmShutdown().make(); + if (Config.isDataTransactions()){ + db = DBMaker.fileDB(dataLocationString).fileChannelEnable().allocateStartSize(10240).transactionEnable().closeOnJvmShutdown().make(); + } + else{ + db = DBMaker.fileDB(dataLocationString).fileChannelEnable().allocateStartSize(10240).closeOnJvmShutdown().make(); + } map = (ConcurrentMap>) db.hashMap("map").createOrOpen(); memDB = DBMaker.heapDB().closeOnJvmShutdown().transactionEnable().make(); memMap = memDB.hashMap("memMap", Serializer.INTEGER, Serializer.STRING).createOrOpen(); @@ -513,6 +523,7 @@ public static void loadTopMovers(){ @Deprecated public boolean onCommand(CommandSender sender, Command testcmd, String trade, String[] help) { + if(testcmd.getName().equalsIgnoreCase("trade")){ if (sender instanceof Player) { Player player = (Player) sender; String hostIP = ""; @@ -555,6 +566,8 @@ public boolean onCommand(CommandSender sender, Command testcmd, String trade, St } return false; } + return false; + } public static void saveplayerdata() { try { diff --git a/Auto-Tune/src/unprotesting/com/github/util/Config.java b/Auto-Tune/src/unprotesting/com/github/util/Config.java index 74730a5..18094ab 100644 --- a/Auto-Tune/src/unprotesting/com/github/util/Config.java +++ b/Auto-Tune/src/unprotesting/com/github/util/Config.java @@ -19,7 +19,8 @@ public final class Config { calculateGlobalGDP, tutorial, updatePricesWhenInactive, - sendPlayerTopMoversOnJoin; + sendPlayerTopMoversOnJoin, + dataTransactions; @Getter @Setter @@ -47,7 +48,8 @@ public final class Config { email, inflationMethod, currencySymbol, - economyShopConfig; + economyShopConfig, + dataLocation; @Getter @Setter @@ -75,6 +77,7 @@ public static void loadDefaults() { Config.setSendPlayerTopMoversOnJoin(Main.getMainConfig().getBoolean("send-player-top-movers-on-join", true)); Config.setWebServer(Main.getMainConfig().getBoolean("web-server-enabled", true)); Config.setTutorial(Main.getMainConfig().getBoolean("tutorial", true)); + Config.setDataTransactions(Main.getMainConfig().getBoolean("data-transactions", false)); Config.setCalculateGlobalGDP(Main.getMainConfig().getBoolean("calculate-global-GDP", true)); Config.setAutoSellEnabled(Main.getMainConfig().getBoolean("auto-sell-enabled", true)); Config.setInflationEnabled(Main.getMainConfig().getBoolean("inflation-enabled", true)); @@ -97,8 +100,9 @@ public static void loadDefaults() { Config.setMenuTitle( ChatColor.translateAlternateColorCodes('&', Main.getMainConfig().getString("menu-title", "Auto-Tune Shop"))); Config.setPricingModel( - ChatColor.translateAlternateColorCodes('&', Main.getMainConfig().getString("pricing-model", "Basic"))); + ChatColor.translateAlternateColorCodes('&', Main.getMainConfig().getString("pricing-model", "Exponential"))); Config.setApiKey(Main.getMainConfig().getString("api-key", "xyz")); + Config.setDataLocation(Main.getMainConfig().getString("data-location", "")); Config.setInflationMethod(Main.getMainConfig().getString("inflation-method", "Mixed")); Config.setEmail(Main.getMainConfig().getString("email", "xyz@gmail.com")); Config.setBasicVolatilityAlgorithim(ChatColor.translateAlternateColorCodes('&', Main.getMainConfig().getString("Volatility-Algorithim", "Variable"))); diff --git a/Auto-Tune/src/unprotesting/com/github/util/TextHandler.java b/Auto-Tune/src/unprotesting/com/github/util/TextHandler.java index f367d66..5b95110 100644 --- a/Auto-Tune/src/unprotesting/com/github/util/TextHandler.java +++ b/Auto-Tune/src/unprotesting/com/github/util/TextHandler.java @@ -5,52 +5,6 @@ import unprotesting.com.github.Main; public class TextHandler { - public static void sendPriceModelData(String priceModel){ - if (priceModel.contains("Basic")) { - Main.log("Loaded Basic Price Algorithim"); - if (Main.basicVolatilityAlgorithim.contains("Variable")) { - Main.log("Loaded Algorithim under Variable Configuration"); - } - if (Main.basicVolatilityAlgorithim.contains("Fixed")) { - Main.log("Loaded Algorithim under Variable Configuration"); - } - } - if (priceModel.contains("Advanced")) { - Main.log("Loaded Advanced Price Algorithim"); - if (Main.basicVolatilityAlgorithim.contains("Variable")) { - Main.log("Loaded Advanced Algorithim under Variable Configuration"); - } - if (Main.basicVolatilityAlgorithim.contains("Fixed")) { - Main.log("Loaded Advanced Algorithim under Variable Configuration"); - } - } - } - - public static void sendDataBeforePriceCalculation(String priceModel, String basicVolatilityAlgorithim){ - Main.debugLog("Starting price calculation task... "); - Main.debugLog("Price algorithim settings: "); - if (priceModel.contains("Basic") && basicVolatilityAlgorithim.contains("Fixed")) { - Main.debugLog("Basic Max Fixed Volatility: " + Config.getBasicMaxFixedVolatility()); - Main.debugLog("Basic Min Fixed Volatility: " + Config.getBasicMinFixedVolatility()); - } - if (priceModel.contains("Basic") && basicVolatilityAlgorithim.contains("Variable")) { - Main.debugLog("Basic Max Variable Volatility: " + Config.getBasicMaxVariableVolatility()); - Main.debugLog("Basic Min Variable Volatility: " + Config.getBasicMinVariableVolatility()); - } - if (priceModel.contains("Advanced") && basicVolatilityAlgorithim.contains("Fixed")) { - Main.debugLog("Advanced Max Fixed Volatility: " + Config.getBasicMaxFixedVolatility()); - Main.debugLog("Advanced Min Fixed Volatility: " + Config.getBasicMinFixedVolatility()); - } - if (priceModel.contains("Advanced") && basicVolatilityAlgorithim.contains("Variable")) { - Main.debugLog("Advanced Max Variable Volatility: " + Config.getBasicMaxVariableVolatility()); - Main.debugLog("Advanced Min Variable Volatility: " + Config.getBasicMinVariableVolatility()); - } - if (priceModel.contains("Exponential") && basicVolatilityAlgorithim.contains("Variable")) { - Main.debugLog("Exponential Max Variable Volatility: " + Config.getBasicMaxVariableVolatility()); - Main.debugLog("Exponential Min Variable Volatility: " + Config.getBasicMinVariableVolatility()); - Main.debugLog("Exponential data selection algorithim: y = " + Config.getDataSelectionM() + "(x^" + Config.getDataSelectionZ() + ") + " + Config.getDataSelectionC()); - } - } public static void noPermssion(Player p){ p.sendMessage(Config.getNoPermission());