diff --git a/Auto-Tune/dependency-reduced-pom.xml b/Auto-Tune/dependency-reduced-pom.xml
index 9dc1761..3ded8cd 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.4
+ 0.13.0-pre-release-1
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 a41838d..e8afcc0 100644
--- a/Auto-Tune/pom.xml
+++ b/Auto-Tune/pom.xml
@@ -9,7 +9,7 @@
unprotesting.com.github
Auto-Tune
- 0.12.4
+ 0.13.0-pre-release-1
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 4b721d9..755b317 100644
--- a/Auto-Tune/src/resources/config.yml
+++ b/Auto-Tune/src/resources/config.yml
@@ -118,13 +118,13 @@ inflation-enabled: true
inflation-method: 'Mixed'
## Time period in ticks between dynamic price increases
-dynamic-inflation-time-period: 5000
+dynamic-inflation-time-period: 2500
## Percentage increase in prices per time-period.
-dynamic-inflation-value: 0.00025
+dynamic-inflation-value: 0.000025
-## Percentage increase for buy value per price calculation update period.
-static-inflation-value: 0.1
+## Percentage increase for buy value per price calculation update period. E.g 0.05%
+static-inflation-value: 0.05
## Intrest rate per interest-rate-update-period
## Info: This is the increase in the current debt payment per-time period
@@ -147,9 +147,9 @@ disable-max-buys-sells: false
max-debt-value: -100.00
## The percentage value to decrease items sold with enchantments
-## Info: Stacked enchantments etc. can become very expensive so a number between 10% - 25% is usually fine
+## Info: Stacked enchantments etc. can become very expensive so a number between 25% - 50% is usually fine
## Info: This doesn't affect buys
-enchantment-limiter: 20.00
+enchantment-limiter: 45.00
## The percentage value to decrease items sold with a loss in durability
## Info: This is applied ON TOP of the durability algorithm to limit the exploitability of selling tools
diff --git a/Auto-Tune/src/resources/plugin.yml b/Auto-Tune/src/resources/plugin.yml
index 110f0cb..34309bf 100644
--- a/Auto-Tune/src/resources/plugin.yml
+++ b/Auto-Tune/src/resources/plugin.yml
@@ -40,12 +40,15 @@ commands:
usage: / (Optional)
gdp:
description: View GDP info
- usage:
+ usage: /GDP
atconfig:
description: View and change plugin config settings
buy:
description: Buy items not available in the shop
aliases: [purchase]
+ transactions:
+ description: View player transactions
+ usage: /transactions | /transactions all | /transactions
permssions:
at.help:
description: Displays Auto-Tune help information
@@ -83,6 +86,11 @@ permssions:
at.buy:
description: Allow players to purchase custom items
default: true
+ at.transactions:
+ description: View your own transactions
+ default: true
+ at.transactions.other:
+ description: View another players transactions | View all transactions
diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java
index 90a744f..f30c9fc 100644
--- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java
+++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java
@@ -19,6 +19,7 @@
import unprotesting.com.github.util.EnchantmentAlgorithm;
import unprotesting.com.github.util.EnchantmentSetting;
import unprotesting.com.github.util.TextHandler;
+import unprotesting.com.github.util.Transaction;
public class AutoTuneBuyCommand implements CommandExecutor {
@@ -44,9 +45,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}
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);
+ for (String str : Main.enchMap.keySet()){
+ EnchantmentSetting setting = Main.enchMap.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");
}
@@ -59,10 +59,12 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}
if (args.length == 2){
if (args[0].contains("enchantments")){
- ConcurrentHashMap inputMap = Main.enchMap.get("Auto-Tune");
- EnchantmentSetting setting = inputMap.get((args[1].toUpperCase()));
+ EnchantmentSetting setting = Main.enchMap.get((args[1].toUpperCase()));
ItemStack is = player.getInventory().getItemInMainHand();
- Material mat = is.getType();
+ if (Main.getEconomy().getBalance(player) < setting.price){
+ player.sendMessage(ChatColor.RED + "Cannot enchant item: " + is.getType().toString() + " with enchantment " + setting.name);
+ return true;
+ }
boolean enchantExists = false;
Map map = is.getEnchantments();
Enchantment ench = Enchantment.getByName(setting.name);
@@ -73,10 +75,14 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
try{
if (!enchantExists){
is.addEnchantment(ench, 1);
+ Transaction transaction = new Transaction(player, ench, "Buy");
+ transaction.loadIntoMap();
}
else{
int level = is.getEnchantmentLevel(ench);
is.addEnchantment(ench, level+1);
+ Transaction transaction = new Transaction(player, ench, "Buy");
+ transaction.loadIntoMap();
}
}
catch(IllegalArgumentException ex){
@@ -108,8 +114,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
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);
+ Main.enchMap.put(setting.name, setting);
return true;
}
player.sendMessage(ChatColor.RED + "Hold the item you want to enchant in your main hand!");
diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGDPCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGDPCommand.java
index cd8b031..5ee4f77 100644
--- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGDPCommand.java
+++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGDPCommand.java
@@ -72,7 +72,6 @@ public double getLoanBalance(){
for (Loan loan : map){
output += loan.current_value;
}
-
}
return output;
}
diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java
index 36dd918..5feca8f 100644
--- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java
+++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java
@@ -29,8 +29,10 @@
import net.md_5.bungee.api.ChatColor;
import unprotesting.com.github.Main;
import unprotesting.com.github.util.Config;
+import unprotesting.com.github.util.EnchantmentAlgorithm;
import unprotesting.com.github.util.Section;
import unprotesting.com.github.util.TextHandler;
+import unprotesting.com.github.util.Transaction;
public class AutoTuneGUIShopUserCommand implements CommandExecutor {
@@ -314,6 +316,7 @@ public static OutlinePane loadTradingItems(String itemName, Section sec, Outline
Integer[] max = sec.itemMaxBuySell.get(itemName);
ItemStack test = new ItemStack(Material.matchMaterial(itemName));
test = checkForEnchantAndApply(test, sec);
+ EnchantmentAlgorithm.updateEnchantSellData(test, player);
if (!player.getInventory().containsAtLeast(test, amounts[finalI - 7])) {
player.sendMessage(ChatColor.BOLD + "Cant Sell " + Integer.toString(amounts[finalI - 7])
+ "x of " + itemName);
@@ -523,8 +526,8 @@ public static Double getItemPrice(String item, boolean sell) {
}
catch(NullPointerException e){
ConcurrentHashMap map = Main.map.get(item);
- output = map.get(map.size()-1)[0];
try{
+ output = map.get(map.size()-1)[0];
output = output - output*0.01*getSellDifference(item);
return output;
}
@@ -535,6 +538,18 @@ public static Double getItemPrice(String item, boolean sell) {
}
}
+ @Deprecated
+ public static Double getItemPrice(ItemStack item, boolean sell){
+ Double output;
+ try{
+ output = getItemPrice(item.getType().toString(), sell);
+ }
+ catch (NullPointerException ex){
+ return null;
+ }
+ return output;
+ }
+
public static StaticPane loadReturnButton(Section sec, boolean autosell) {
StaticPane output = new StaticPane(0, 0, 1, 1);
ItemStack iStack = new ItemStack(Material.ARROW);
@@ -617,6 +632,7 @@ public static StaticPane loadMainMenuBackPane(PaginatedPane pPane, boolean autos
}
public static void sendPlayerShopMessageAndUpdateGDP(int amount, Player player, String matClickedString, boolean sell){
+ ItemStack itemstack = new ItemStack(Material.getMaterial(matClickedString));
if (!sell){
ConcurrentHashMap cMap = Main.maxBuyMap.get(player.getUniqueId());
cMap.put(matClickedString, (cMap.get(matClickedString)+amount));
@@ -625,9 +641,11 @@ public static void sendPlayerShopMessageAndUpdateGDP(int amount, Player player,
Double[] arr = inputMap.get(inputMap.size()-1);
Double[] outputArr = {arr[0], (arr[1]+amount), arr[2]};
Main.tempdatadata.put("GDP", (Main.tempdatadata.get("GDP")+(arr[0]*amount)));
+ Transaction transaction = new Transaction(player, itemstack, "Buy", arr[0]);
inputMap.put((inputMap.size()-1), outputArr);
Main.map.put(matClickedString, inputMap);
Main.getEconomy().withdrawPlayer(player, (arr[0]*amount));
+ transaction.loadIntoMap();
player.sendMessage(ChatColor.GOLD + "Purchased " + amount + "x " + matClickedString + " for " + ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(arr[0]*amount));
}
@@ -638,11 +656,13 @@ else if (sell){
ConcurrentHashMap inputMap = Main.map.get(matClickedString);
Double[] arr = inputMap.get(inputMap.size()-1);
Double[] outputArr = {arr[0], arr[1], (arr[2]+amount)};
- Double price = arr[0] - (arr[0]*0.01*getSellDifference(matClickedString));
+ Double price = AutoTuneGUIShopUserCommand.getItemPrice(matClickedString, true);
Main.tempdatadata.put("GDP", (Main.tempdatadata.get("GDP")+(price*amount)));
+ Transaction transaction = new Transaction(player, itemstack, "Sell", price);
inputMap.put((inputMap.size()-1), outputArr);
Main.map.put(matClickedString, inputMap);
Main.getEconomy().depositPlayer(player, (price*amount));
+ transaction.loadIntoMap();
player.sendMessage(ChatColor.GOLD + "Sold " + amount + "x " + matClickedString + " for " + ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(price*amount));
}
}
diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java
index 32be5d3..c67b4a0 100644
--- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java
+++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java
@@ -10,24 +10,24 @@
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
-import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
import net.md_5.bungee.api.ChatColor;
import unprotesting.com.github.Main;
import unprotesting.com.github.util.Config;
import unprotesting.com.github.util.EnchantmentAlgorithm;
import unprotesting.com.github.util.TextHandler;
+import unprotesting.com.github.util.Transaction;
public class AutoTuneSellCommand implements CommandExecutor {
public Integer menuRows = Config.getMenuRows();
- ConcurrentHashMap guis = new ConcurrentHashMap();
-
@Override
public boolean onCommand(CommandSender sender, Command command, String sell, String[] args) {
@@ -39,7 +39,6 @@ public boolean onCommand(CommandSender sender, Command command, String sell, Str
CommandSender sender2 = sender;
Player p = (Player) sender;
if (args.length == 0){
- guis.put(p.getUniqueId(), loadSellGUI(p, sender2));
if (p.hasPermission("at.sell") || p.isOp()){loadSellGUI(p, sender2);}
else if (!(p.hasPermission("at.sell")) && !(p.isOp())){TextHandler.noPermssion(p);}
return true;
@@ -53,10 +52,8 @@ public boolean onCommand(CommandSender sender, Command command, String sell, Str
}
- public void sell(Player player, Gui GUI) {
- ItemStack[] items = GUI.getInventory().getContents();
+ public void sell(Player player, ItemStack[] items) {
sellItems(player, items, false);
- GUI.getInventory().clear();
}
public static String getItemStringForItemStack(ItemStack item) {
@@ -64,81 +61,103 @@ public static String getItemStringForItemStack(ItemStack item) {
}
@Deprecated
- public static void sellItems(Player player, ItemStack[] items, Boolean autoSell) {
- double moneyToGive = 0;
- boolean couldntSell = false;
- int countSell = 0;
- boolean totMax = false;
- for (ItemStack item : items) {
-
- if (item == null) {
- continue;
- }
-
- String itemString = getItemStringForItemStack(item);
+ public static void sellItems(Player player, ItemStack[] items, Boolean autoSell){
+ double money = 0.0;
+ for (ItemStack item : items) {
+ if (item == null){
+ continue;
+ }
+ String itemString = getItemStringForItemStack(item);
int quantity = item.getAmount();
- ConcurrentHashMap tempMap1 = Main.map.get(itemString);
- if ((tempMap1==null)) {
- countSell += quantity;
- couldntSell = true;
+ Double pricePerItem = 0.0;
+ if (item.getItemMeta().hasEnchants()){
+ pricePerItem = EnchantmentAlgorithm.calculatePriceWithEnch(item, false);
+ }
+ if (!item.getItemMeta().hasEnchants()){
+ pricePerItem = AutoTuneGUIShopUserCommand.getItemPrice(item, true);
+ }
+ if (pricePerItem == null || pricePerItem == 0 || pricePerItem.isInfinite() || pricePerItem.isNaN()){
+ player.sendMessage(ChatColor.RED + "Couldn't sell " + item.getType().toString());
player.getInventory().addItem(item);
- continue;
+ continue;
}
- if (!autoSell){
- ConcurrentHashMap cMap = Main.maxSellMap.get(player.getUniqueId());
- Integer max = 10000;
- try{
- max = (Integer)Main.getShopConfig().get("shops." + itemString + "." + "max-sell");
- }
- catch(ClassCastException ex){
- max = Integer.parseInt(AutoTuneGUIShopUserCommand.df5.format(Main.getShopConfig().get("shops." + itemString + "." + "max-sell")));
- }
- if (max == null){
- max = 100000;
- }
- if ((cMap.get(itemString)+quantity) > max){
- couldntSell = true;
- countSell += quantity;
- totMax = true;
+ double totalPrice = pricePerItem * quantity;
+ int maxSells = getMaxSells(itemString);
+ int currentMaxSells = getCurrentSellsMax(itemString, player);
+ int newTempCurrentMaxSells = currentMaxSells + quantity;
+ if (newTempCurrentMaxSells > maxSells){
+ player.sendMessage(ChatColor.RED + "Max Sells Reached for " + item.getType().toString());
+ if (currentMaxSells >= maxSells){
player.getInventory().addItem(item);
continue;
}
+ else{
+ int difference = newTempCurrentMaxSells - (maxSells);
+ totalPrice = pricePerItem * difference;
+ item = loadADifferentAmountFromItemStack(item, difference);
+ player.getInventory().addItem(loadADifferentAmountFromItemStack(item, (quantity - difference)));
+ quantity = difference;
+ }
}
- ConcurrentHashMap cMap2 = Main.maxSellMap.get(player.getUniqueId());
- cMap2.put(itemString, (cMap2.get(itemString)+quantity));
- Main.maxSellMap.put(player.getUniqueId(), cMap2);
- Integer tempMapSize = tempMap1.size();
- Double[] tempDoublearray = tempMap1.get(tempMapSize-1);
- Double buyAmount = tempDoublearray[1];
- Double sellAmount = tempDoublearray[2];
- sellAmount = quantity + sellAmount;
- Double[] tempPutDouble = {tempDoublearray[0], buyAmount, sellAmount};
- tempMap1.put(tempMapSize-1, tempPutDouble);
- Main.map.put(itemString, tempMap1);
- boolean enchantmentPresent = true;
- double enchPrice = EnchantmentAlgorithm.calculatePriceWithEnch(item, false);
- if (enchPrice == 0.0){
- enchantmentPresent = false;
- enchPrice = AutoTuneGUIShopUserCommand.getItemPrice(item.getType().toString(), true);
- }
- moneyToGive += (quantity * enchPrice);
- if (enchantmentPresent){
- EnchantmentAlgorithm.updateEnchantSellData(item);
- }
- }
- if (couldntSell == true && !autoSell) {
- player.sendMessage(ChatColor.BOLD + "Cant sell " + Integer.toString(countSell) + "x of item");
- if (totMax == true){
- player.sendMessage(ChatColor.RED + "Maximum sells reached");
+ increaseMaxSells(player, quantity, item.getType().toString());
+ Transaction transaction = new Transaction(player, item, "Sell", totalPrice);
+ transaction.loadIntoMap();
+ loadEnchantmentTransactions(item, player);
+ increaseMaxSells(player, quantity, itemString);
+ money += totalPrice;
+ }
+ if (money > 0){
+ roundAndGiveMoney(player, money, autoSell);
+ }
+ }
+
+ @Deprecated
+ public static void loadEnchantmentTransactions (ItemStack item, Player player){
+ if (item.getEnchantments().size() < 1){
+ return;
+ }
+ else {
+ for (Enchantment ench : item.getEnchantments().keySet()){
+ Transaction transaction = new Transaction(player, ench, "Sell");
+ transaction.loadIntoMap();
}
}
- else if (autoSell == true){
- roundAndGiveMoney(player, moneyToGive, true);
+ }
+
+ public static void increaseMaxSells (Player player, int amount, String item) {
+ ConcurrentHashMap map = Main.maxSellMap.get(player.getUniqueId());
+ if (map.get(item) == null){
+ map.put(item, 0);
+ }
+ map.put(item, map.get(item)+amount);
+ Main.maxSellMap.put(player.getUniqueId(), map);
+ }
+
+ public static ItemStack loadADifferentAmountFromItemStack (ItemStack item, int new_size){
+ ItemMeta im = item.getItemMeta();
+ ItemStack output = new ItemStack(item.getType(), new_size);
+ output.setItemMeta(im);
+ return output;
+ }
+
+ public static int getCurrentSellsMax(String item, Player player){
+ UUID uuid = player.getUniqueId();
+ return Main.maxSellMap.get(uuid).get(item);
+ }
+
+ public static int getMaxSells(String item){
+ Integer max = 10000;
+ try{
+ max = (Integer)Main.getShopConfig().get("shops." + item + "." + "max-sell");
+ }
+ catch(ClassCastException ex){
+ max = Integer.parseInt(AutoTuneGUIShopUserCommand.df5.format(Main.getShopConfig().get("shops." + item + "." + "max-sell")));
}
- else if (autoSell == false){
- roundAndGiveMoney(player, moneyToGive, false);
+ if (max == null){
+ max = 100000;
}
- }
+ return max;
+ }
public Gui loadSellGUI(Player player, CommandSender sender2) {
Gui GUI = new Gui(menuRows, "Selling Panel");
@@ -146,15 +165,13 @@ public Gui loadSellGUI(Player player, CommandSender sender2) {
GUI.addPane(SellingPane);
GUI.setOnClose(this::onSellClose);
GUI.show((HumanEntity) sender2);
- guis.put(player.getUniqueId(), GUI);
return GUI;
}
private void onSellClose(InventoryCloseEvent event) {
Player player = (Player) event.getPlayer();
- UUID uuid = player.getUniqueId();
- sell(player, guis.get(uuid));
- guis.remove(uuid);
+ sell(player, event.getInventory().getStorageContents());
+ event.getInventory().clear();
}
public static void roundAndGiveMoney(Player player, double moneyToGive, Boolean autoSell) {
@@ -173,6 +190,9 @@ public static void roundAndGiveMoney(Player player, double moneyToGive, Boolean
Main.tempdatadata.put(player.getUniqueId().toString(), Main.tempdatadata.get(player.getUniqueId().toString())+moneyToGive);
}
}
+ else {
+ player.sendMessage(ChatColor.RED + "Error on sale!");
+ }
}
diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneTransactionCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneTransactionCommand.java
new file mode 100644
index 0000000..7f6da8c
--- /dev/null
+++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneTransactionCommand.java
@@ -0,0 +1,149 @@
+package unprotesting.com.github.Commands;
+
+import java.util.ArrayList;
+
+import com.earth2me.essentials.User;
+
+import org.bukkit.Bukkit;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import net.md_5.bungee.api.ChatColor;
+import unprotesting.com.github.Main;
+import unprotesting.com.github.util.TextHandler;
+import unprotesting.com.github.util.Transaction;
+
+public class AutoTuneTransactionCommand implements CommandExecutor {
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String transactions, String[] args) {
+ if (command.getName().equalsIgnoreCase("transactions")) {
+ if (sender instanceof Player) {
+ Player player = (Player) sender;
+ if (args.length < 1) {
+ if (player.hasPermission("at.transactions") || player.isOp() || player.hasPermission("at.transactions.other")){
+ player.sendMessage(ChatColor.RED + "Error! Correct Usage: /transactions ");
+ }
+ else{
+ TextHandler.noPermssion(player);
+ }
+ return true;
+ }
+ else if (args.length < 2) {
+ if (player.hasPermission("at.transactions") || player.isOp()){
+ Integer page = parsePage(args[0], player);
+ if (page != null && page > 0) {
+ setupTransactionViewForPlayer(player, page, player);
+ }
+ }
+ else{
+ TextHandler.noPermssion(player);
+ }
+ return true;
+ } else if (args[0].equals("all")) {
+ if (player.hasPermission("at.transactions.other") || player.isOp()){
+ if (args.length < 2){
+ player.sendMessage(ChatColor.RED + "Error! Correct Usage: /transactions ");
+ return true;
+ }
+ Integer page = parsePage(args[1], player);
+ if (page == null || page < 0) {
+ return true;
+ }
+ setupTransactionViewAll(player, page);
+ }
+ else{
+ TextHandler.noPermssion(player);
+ }
+ return true;
+ } else if (args.length == 2) {
+ if (player.hasPermission("at.transactions.other") || player.isOp()){
+ Integer page = parsePage(args[1], player);
+ if (page == null || page < 0) {
+ return true;
+ }
+ Player select_player = parsePlayer(args[0], player);
+ if (select_player == null){
+ return true;
+ }
+ setupTransactionViewForPlayer(player, page, select_player);
+ }
+ else{
+ TextHandler.noPermssion(player);
+ }
+ return true;
+ } else {
+ if (player.hasPermission("at.transactions") || player.hasPermission("at.transactions.other") || player.isOp()){
+ player.sendMessage("Error! Correct Usage: /transactions ");
+ }
+ else{
+ TextHandler.noPermssion(player);
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ @Deprecated
+ public void setupTransactionViewForPlayer(Player player, int page, Player input_player) {
+ String input_player_name = input_player.getName();
+ player.sendMessage(ChatColor.YELLOW + "Page: " + (page+1));
+ int size = (Main.getTransactions().size() - 1);
+ for (Integer i = (size - (page * 10)); i > size - ((page + 1) * 10); i--) {
+ try{
+ Transaction transaction = Main.getTransactions().get(i);
+ if (transaction.player.equals(input_player_name)) {
+ player.sendMessage(ChatColor.RED + Integer.toString(i+1) + ": " + ChatColor.YELLOW + transaction.toDisplayString());
+ }
+ }
+ catch(NullPointerException ex){
+ }
+ }
+ }
+
+ @Deprecated
+ public void setupTransactionViewAll(Player player, int page) {
+ player.sendMessage(ChatColor.YELLOW + "Page: " + (page+1));
+ int size = (Main.getTransactions().size() - 1);
+ for (Integer i = (size - (page * 10)); i > size - ((page + 1) * 10); i--) {
+ try{
+ player.sendMessage(ChatColor.RED + Integer.toString(i+1) + ": " + ChatColor.YELLOW
+ + Main.getTransactions().get(i).toDisplayString());
+ }
+ catch(NullPointerException ex){
+ }
+ }
+ }
+
+ public Integer parsePage(String arg, Player player) {
+ Integer page = 0;
+ try {
+ page = Integer.parseInt(arg);
+ } catch (NumberFormatException ex) {
+ player.sendMessage("Error! Correct Usage: /transactions all ");
+ page = null;
+ }
+ if (page < 1){
+ player.sendMessage("Error! Correct Usage: /transactions all ");
+ return null;
+ }
+ page = page-1;
+ return page;
+ }
+
+ @Deprecated
+ public Player parsePlayer(String arg, Player player) {
+ OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(arg);
+ if (offlinePlayer == null){
+ player.sendMessage("Error! Correct Usage: /transactions ");
+ return null;
+ }
+ Player output = offlinePlayer.getPlayer();
+ return output;
+ }
+
+}
diff --git a/Auto-Tune/src/unprotesting/com/github/Main.java b/Auto-Tune/src/unprotesting/com/github/Main.java
index 3f81ca9..7936c46 100644
--- a/Auto-Tune/src/unprotesting/com/github/Main.java
+++ b/Auto-Tune/src/unprotesting/com/github/Main.java
@@ -68,6 +68,7 @@
import unprotesting.com.github.Commands.AutoTuneGUIShopUserCommand;
import unprotesting.com.github.Commands.AutoTuneLoanCommand;
import unprotesting.com.github.Commands.AutoTuneSellCommand;
+import unprotesting.com.github.Commands.AutoTuneTransactionCommand;
import unprotesting.com.github.util.AutoSellEventHandler;
import unprotesting.com.github.util.AutoTunePlayerAutoSellEventHandler;
import unprotesting.com.github.util.CSVHandler;
@@ -90,6 +91,8 @@
import unprotesting.com.github.util.StaticFileHandler;
import unprotesting.com.github.util.TextHandler;
import unprotesting.com.github.util.TopMover;
+import unprotesting.com.github.util.Transaction;
+import unprotesting.com.github.util.TransactionSerializer;
import unprotesting.com.github.util.TutorialHandler;
public final class Main extends JavaPlugin implements Listener {
@@ -109,7 +112,7 @@ public final class Main extends JavaPlugin implements Listener {
public static DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
public static FileConfiguration playerDataConfig;
public final static String playerdatafilename = "playerdata.yml";
- public static DB db, memDB, tempDB, loanDB, enchDB;
+ public static DB db, memDB, tempDB, loanDB, enchDB, transactionDB;
public static HTreeMap tempdatadata;
public static ConcurrentMap> map;
public static ConcurrentMap> maxBuyMap = new ConcurrentHashMap>();
@@ -129,10 +132,9 @@ public final class Main extends JavaPlugin implements Listener {
HttpServer server;
@Getter
- public static ConcurrentMap> enchMap;
+ public static ConcurrentMap enchMap;
- static @Getter
- private File configf;
+ static @Getter private File configf;
@Getter
public static File shopf, tradef, tradeShortf, enchf, faviconf;
@@ -180,18 +182,24 @@ public final class Main extends JavaPlugin implements Listener {
@Getter
public static ConcurrentHashMap itemPrices = new ConcurrentHashMap();
+ @Getter
+ public static HTreeMap transactions;
+
@Override
public void onDisable() {
- if (scheduler == null){
+ if (scheduler == null) {
scheduler = getServer().getScheduler();
}
- if (getINSTANCE() == null){
+ if (getINSTANCE() == null) {
INSTANCE = this;
}
- if (server != null){
+ if (server != null) {
server.stop(0);
}
- closeDataFiles();
+ try {
+ closeDataFiles();
+ } catch (ClassNotFoundException e) {
+ }
scheduler.cancelTasks(getINSTANCE());
log.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
}
@@ -277,6 +285,7 @@ public void onEnable() {
this.getCommand("atconfig").setExecutor(new AutoTuneAutoTuneConfigCommand());
this.getCommand("gdp").setExecutor(new AutoTuneGDPCommand());
this.getCommand("buy").setExecutor(new AutoTuneBuyCommand());
+ this.getCommand("transactions").setExecutor(new AutoTuneTransactionCommand());
basicVolatilityAlgorithim = Config.getBasicVolatilityAlgorithim();
priceModel = Config.getPricingModel().toString();
scheduler = getServer().getScheduler();
@@ -302,7 +311,7 @@ public void onEnable() {
loadSections();
debugLog("Loading Enchatments..");
EnchantmentAlgorithm.loadEnchantmentSettings();
- debugLog("Loaded " + enchMap.get("Auto-Tune").size() + " enchantments");
+ debugLog("Loaded " + enchMap.size() + " enchantments");
AutoTuneBuyCommand.shopTypes.add("enchantments");
PriceCalculationHandler.loadItemPriceData();
scheduler.scheduleAsyncRepeatingTask(getINSTANCE(), new PriceCalculationHandler(), Config.getTimePeriod() * 600, Config.getTimePeriod() * 1200);
@@ -323,18 +332,19 @@ private boolean setupEconomy() {
public static int calculatePlayerCount(){
int output = 0;
for (Player player : Bukkit.getServer().getOnlinePlayers()){
+ Main.log("Player: " + player);
User user = getEss().getUser(player);
if (Config.isIgnoreAFK()){
if (user.isAfk()){
+ Main.log("AFK");
continue;
}
- else if(user.isVanished()){
+ if (user.isVanished()){
+ Main.log("Vanished");
continue;
}
}
- else{
- output++;
- }
+ output++;
}
return output;
}
@@ -346,8 +356,9 @@ public static String[] convert(Set setOfString) {
public static ConcurrentHashMap loadMaxStrings(ConcurrentMap> mainMap){
ConcurrentHashMap maxMap = new ConcurrentHashMap();
- for (String str : mainMap.keySet()){
- maxMap.put(str, 0);
+ Set set = mainMap.keySet();
+ for (String str : set){
+ maxMap.put(str, 0);
}
return maxMap;
}
@@ -358,9 +369,10 @@ public static void tempdataresetSPDifference() {
public static void setupMaxBuySell(){
if (!Config.isDisableMaxBuysSells()){
+ ConcurrentHashMap cMap = loadMaxStrings(map);
for (OfflinePlayer p : Bukkit.getOnlinePlayers()){
- maxBuyMap.put(p.getUniqueId(), loadMaxStrings(map));
- maxSellMap.put(p.getUniqueId(), loadMaxStrings(map));
+ maxBuyMap.put(p.getUniqueId(), cMap);
+ maxSellMap.put(p.getUniqueId(), cMap);
}
}
}
@@ -369,11 +381,12 @@ public void SellDifrunnable() {
new BukkitRunnable() {
@Override
public void run() {
+ double sellPriceDifInConfig = getMainConfig().getDouble("sell-price-difference", 10.0);
Integer sellPriceVariationInt = Config.getSellPriceVariationUpdatePeriod();
Double d = Double.valueOf(sellPriceVariationInt);
Double updates = (Config.getSellPriceVariationTimePeriod() / d);
Double variation = Config.getSellPriceDifferenceVariationStart()
- - (getMainConfig().getDouble("sell-price-difference", 2.5));
+ - (sellPriceDifInConfig);
Double updateVariation = variation / updates;
Main.tempdatadata.put("SellPriceDifferenceDifference",
(Main.tempdatadata.get("SellPriceDifferenceDifference")) + updateVariation);
@@ -383,13 +396,12 @@ public void run() {
Main.debugLog("Variation: " + Double.toString(variation));
Main.debugLog("Changed sell-price-difference by " + Double.toString(updateVariation) + " to "
+ Double.toString(Config.getSellPriceDifference()));
- if (Config.getSellPriceDifference() <= Main.getMainConfig().getDouble("sell-price-difference", 2.5)) {
- Config.setSellPriceDifference(Main.getMainConfig().getDouble("sell-price-difference", 2.5));
+ if (Config.getSellPriceDifference() <= sellPriceDifInConfig) {
+ Config.setSellPriceDifference(sellPriceDifInConfig);
debugLog("Finished sell difference change task as sell difference has reached: "
- + Main.getMainConfig().getDouble("sell-price-difference", 2.5));
+ + sellPriceDifInConfig);
cancel();
}
- PriceCalculationHandler.loadItemPriceData();
}
}.runTaskTimer(Main.getINSTANCE(), Config.getSellPriceVariationUpdatePeriod() * 20 * 60,
Config.getSellPriceVariationUpdatePeriod() * 20 * 60);
@@ -483,6 +495,7 @@ public static FileConfiguration saveGUIShopFiles(){
public static void setupDataFiles() {
String dataLocationString = (Config.getDataLocation() + "data.db");
+ String enchanmentLocationString = (Config.getDataLocation() + "enchantment-data.db");
if (Config.isChecksumHeaderBypass()) {
Main.debugLog("Enabling checksum-header-bypass");
if (Config.isDataTransactions()){
@@ -494,8 +507,9 @@ public static void setupDataFiles() {
map = (ConcurrentMap>) db.hashMap("map").createOrOpen();
memDB = DBMaker.heapDB().checksumHeaderBypass().closeOnJvmShutdown().make();
memMap = memDB.hashMap("memMap", Serializer.INTEGER, Serializer.STRING).createOrOpen();
- enchDB = DBMaker.fileDB("enchantment-data.db").checksumHeaderBypass().fileChannelEnable().closeOnJvmShutdown().make();
- enchMap = (ConcurrentMap>) enchDB.hashMap("enchMap", Serializer.STRING, Serializer.JAVA).createOrOpen();
+ enchDB = DBMaker.fileDB(enchanmentLocationString).checksumHeaderBypass().fileChannelEnable().closeOnJvmShutdown().make();
+ enchMap = (ConcurrentMap) enchDB
+ .hashMap("enchMap", Serializer.STRING, Serializer.JAVA).createOrOpen();
} else {
if (Config.isDataTransactions()){
db = DBMaker.fileDB(dataLocationString).fileChannelEnable().allocateStartSize(10240).transactionEnable().closeOnJvmShutdown().make();
@@ -506,9 +520,12 @@ public static void setupDataFiles() {
map = (ConcurrentMap>) db.hashMap("map").createOrOpen();
memDB = DBMaker.heapDB().closeOnJvmShutdown().make();
memMap = memDB.hashMap("memMap", Serializer.INTEGER, Serializer.STRING).createOrOpen();
- enchDB = DBMaker.fileDB("enchantment-data.db").closeOnJvmShutdown().fileChannelEnable().make();
- enchMap = (ConcurrentMap>) enchDB.hashMap("enchMap", Serializer.STRING, Serializer.JAVA).createOrOpen();
+ enchDB = DBMaker.fileDB(enchanmentLocationString).closeOnJvmShutdown().fileChannelEnable().make();
+ enchMap = (ConcurrentMap) enchDB
+ .hashMap("enchMap", Serializer.STRING, Serializer.JAVA).createOrOpen();
}
+ transactionDB = DBMaker.fileDB("plugins/Auto-Tune/transactiondata.db").checksumHeaderBypass().fileMmapEnableIfSupported().fileMmapPreclearDisable().cleanerHackEnable().closeOnJvmShutdown().make();
+ transactions = db.hashMap("transactions").keySerializer(Serializer.INTEGER).valueSerializer(new TransactionSerializer()).createOrOpen();
playerDataConfig = YamlConfiguration.loadConfiguration(playerdata);
tempDB = DBMaker.fileDB("plugins/Auto-Tune/temp/tempdata.db").checksumHeaderBypass().fileMmapEnableIfSupported().fileMmapPreclearDisable().cleanerHackEnable().closeOnJvmShutdown().make();
tempdatadata = tempDB.hashMap("tempdatadata", Serializer.STRING, Serializer.DOUBLE).createOrOpen();
@@ -521,7 +538,7 @@ public static void setupDataFiles() {
topBuyers = new ArrayList();
}
- public static void closeDataFiles(){
+ public static void closeDataFiles() throws ClassNotFoundException {
db.commit();
db.close();
enchDB.commit();
diff --git a/Auto-Tune/src/unprotesting/com/github/util/AutoSellEventHandler.java b/Auto-Tune/src/unprotesting/com/github/util/AutoSellEventHandler.java
index 87cbc24..fa68d3c 100644
--- a/Auto-Tune/src/unprotesting/com/github/util/AutoSellEventHandler.java
+++ b/Auto-Tune/src/unprotesting/com/github/util/AutoSellEventHandler.java
@@ -11,6 +11,7 @@
import org.bukkit.inventory.ItemStack;
import unprotesting.com.github.Main;
+import unprotesting.com.github.Commands.AutoTuneGUIShopUserCommand;
import unprotesting.com.github.Commands.AutoTuneSellCommand;
public class AutoSellEventHandler implements Runnable {
diff --git a/Auto-Tune/src/unprotesting/com/github/util/EnchantmentAlgorithm.java b/Auto-Tune/src/unprotesting/com/github/util/EnchantmentAlgorithm.java
index cc7f9d4..a06124b 100644
--- a/Auto-Tune/src/unprotesting/com/github/util/EnchantmentAlgorithm.java
+++ b/Auto-Tune/src/unprotesting/com/github/util/EnchantmentAlgorithm.java
@@ -5,6 +5,7 @@
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
+import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import unprotesting.com.github.Main;
@@ -14,72 +15,56 @@ public class EnchantmentAlgorithm {
public static void loadEnchantmentSettings() {
ConfigurationSection config = Main.getEnchantmentConfig().getConfigurationSection("enchantments");
- ConcurrentHashMap newMap = Main.enchMap.get("Auto-Tune");
- if (newMap == null){
- newMap = new ConcurrentHashMap();
+ if (Main.enchMap == null){
+ Main.enchMap = new ConcurrentHashMap();
}
- if (Main.enchMap.containsKey("Auto-Tune")) {
- newMap = Main.enchMap.get("Auto-Tune");
- for (String str : config.getKeys(false)) {
- if (!newMap.containsKey(str)) {
- Main.debugLog("Loaded new enchantment: " + str + ".");
- EnchantmentSetting setting = new EnchantmentSetting(str);
- newMap.put(str, setting);
- }
+ for (String str : config.getKeys(false)) {
+ if (!Main.enchMap.containsKey(str)) {
+ Main.debugLog("Loaded new enchantment: " + str + ".");
+ EnchantmentSetting setting = new EnchantmentSetting(str);
+ Main.enchMap.put(str, setting);
}
- } else {
- for (String str : config.getKeys(false)) {
- if (!newMap.containsKey(str)) {
- Main.debugLog("Loaded new enchantment: " + str + ".");
- EnchantmentSetting setting = new EnchantmentSetting(str);
- newMap.put(str, setting);
- }
- }
- }
- Main.enchMap.put("Auto-Tune", newMap);
+ }
}
@Deprecated
- public static double calculatePriceWithEnch(ItemStack is, boolean buy) {
+ public static Double calculatePriceWithEnch(ItemStack is, boolean buy) {
ItemMeta iMeta = is.getItemMeta();
Map enchants = iMeta.getEnchants();
double price = 0.0;
+ int checks = 0;
+ double ratio = 0;
try{
price = AutoTuneGUIShopUserCommand.getItemPrice(is.getType().toString(), !buy);
}
catch(NullPointerException e){
- price = 0.0;
+ return null;
}
double cachePrice = 0;
for (Map.Entry ench : enchants.entrySet()) {
String enchName = ench.getKey().getName();
- EnchantmentSetting setting = Main.enchMap.get("Auto-Tune").get(enchName);
+ EnchantmentSetting setting = Main.enchMap.get(enchName);
if (setting == null){
- loadEnchantmentSettings();
- setting = Main.enchMap.get("Auto-Tune").get(enchName);
- if (setting == null){
- return 0.0;
- }
+ continue;
}
Double enchPrice;
try{
enchPrice = setting.price;
}
catch(NullPointerException e){
- loadEnchantmentSettings();
- setting = Main.enchMap.get("Auto-Tune").get(enchName);
- if (setting == null){
- return 0.0;
- }
- enchPrice = setting.price;
+ continue;
}
enchPrice = enchPrice * ench.getValue();
- Double ratio = setting.ratio;
if (!buy){
+ enchPrice = enchPrice - (enchPrice*0.01*Config.getSellPriceDifference());
enchPrice = enchPrice - (enchPrice*0.01*Config.getEnchantmentLimiter());
}
- cachePrice = cachePrice + (price * ratio) + enchPrice;
+ cachePrice += enchPrice;
+ ratio++;
+ checks++;
}
+ double newRatio = ratio/checks;
+ cachePrice = (price*newRatio) + cachePrice;
double durability = DurabilityAlgorithm.calculateDurability(is);
if (durability != 100.00){
if (cachePrice == 0) {
@@ -100,12 +85,12 @@ public static double calculatePriceWithEnch(ItemStack is, boolean buy) {
}
@Deprecated
- public static void updateEnchantSellData(ItemStack is){
+ public static void updateEnchantSellData(ItemStack is, Player player){
ItemMeta iMeta = is.getItemMeta();
Map enchants = iMeta.getEnchants();
for (Map.Entry ench : enchants.entrySet()) {
String enchName = ench.getKey().getName();
- EnchantmentSetting setting = Main.enchMap.get("Auto-Tune").get(enchName);
+ EnchantmentSetting setting = Main.enchMap.get(enchName);
ConcurrentHashMap map;
try{
map = setting.buySellData;
@@ -125,12 +110,12 @@ public static void updateEnchantSellData(ItemStack is){
if (arr[1] == null){
arr[1] = 0.0;
}
- arr[2] += 1;
+ arr[2] += ench.getValue();
map.put(size, arr);
setting.buySellData = map;
- ConcurrentHashMap map_2 = Main.enchMap.get("Auto-Tune");
- map_2.put(enchName, setting);
- Main.enchMap.put("Auto-Tune", map_2);
+ Main.enchMap.put(enchName, setting);
+ Transaction transaction = new Transaction(player, ench.getKey(), "Sell");
+ transaction.loadIntoMap();
}
}
}
diff --git a/Auto-Tune/src/unprotesting/com/github/util/HttpPostRequestor.java b/Auto-Tune/src/unprotesting/com/github/util/HttpPostRequestor.java
index 0334f1c..b336226 100644
--- a/Auto-Tune/src/unprotesting/com/github/util/HttpPostRequestor.java
+++ b/Auto-Tune/src/unprotesting/com/github/util/HttpPostRequestor.java
@@ -9,6 +9,7 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
+import org.apache.http.ConnectionClosedException;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -34,8 +35,25 @@ public static void updatePricesforItems(JSONObject json) throws ClientProtocolEx
result = EntityUtils.toString(entityResponse);
} catch (SocketException ex) {
Main.debugLog("Socket Exception: Socket Closed. Reloading HttpClient..");
+ client.close();
+ client = HttpClients.createDefault();
+ entityResponse = sendPostRequest(json);
+ try {
+ result = EntityUtils.toString(entityResponse);
+ }
+ catch (SocketException ex2) {
+ }
+ }
+ catch (ConnectionClosedException ex){
+ Main.debugLog("Connection Closed Exception: Socket Closed. Reloading HttpClient..");
+ client.close();
client = HttpClients.createDefault();
entityResponse = sendPostRequest(json);
+ try {
+ result = EntityUtils.toString(entityResponse);
+ }
+ catch (SocketException ex2) {
+ }
}
if (result == null) {
return;
@@ -104,15 +122,13 @@ public static void updatePricesforEnchantments(JSONObject json) throws ClientPro
String priceString = priceElement.getAsString();
String name = nameElement.getAsString();
Double price = Double.parseDouble(priceString);
- ConcurrentHashMap map = Main.enchMap.get("Auto-Tune").get(name).buySellData;
+ ConcurrentHashMap map = Main.enchMap.get(name).buySellData;
Double[] arr = {price, 0.0, 0.0};
map.put((map.size()), arr);
- EnchantmentSetting setting = Main.enchMap.get("Auto-Tune").get(name);
+ EnchantmentSetting setting = Main.enchMap.get(name);
setting.buySellData.put(setting.buySellData.size(), arr);
setting.price = price;
- ConcurrentHashMap out = Main.enchMap.get("Auto-Tune");
- out.put(name, setting);
- Main.enchMap.put("Auto-Tune", out);
+ Main.enchMap.put(name, setting);
}
}
}
diff --git a/Auto-Tune/src/unprotesting/com/github/util/JoinEventHandler.java b/Auto-Tune/src/unprotesting/com/github/util/JoinEventHandler.java
index 7ad3d76..35ca6cc 100644
--- a/Auto-Tune/src/unprotesting/com/github/util/JoinEventHandler.java
+++ b/Auto-Tune/src/unprotesting/com/github/util/JoinEventHandler.java
@@ -30,13 +30,12 @@ public void onPlayerJoin(PlayerJoinEvent e) {
Main.playerDataConfig.set(uuid + ".name", name);
Main.saveplayerdata();
if (!Config.isDisableMaxBuysSells()){
+ ConcurrentHashMap cMap = Main.loadMaxStrings(Main.map);
if (!Main.maxBuyMap.containsKey(player.getUniqueId())){
- ConcurrentHashMap cMap = Main.loadMaxStrings(Main.map);
Main.maxBuyMap.put(player.getUniqueId(), cMap);
}
if (!Main.maxSellMap.containsKey(player.getUniqueId())){
- ConcurrentHashMap cMap2 = Main.loadMaxStrings(Main.map);
- Main.maxSellMap.put(player.getUniqueId(), cMap2);
+ Main.maxSellMap.put(player.getUniqueId(), cMap);
}
}
}
diff --git a/Auto-Tune/src/unprotesting/com/github/util/PriceCalculationHandler.java b/Auto-Tune/src/unprotesting/com/github/util/PriceCalculationHandler.java
index 67c4e05..a6f920a 100644
--- a/Auto-Tune/src/unprotesting/com/github/util/PriceCalculationHandler.java
+++ b/Auto-Tune/src/unprotesting/com/github/util/PriceCalculationHandler.java
@@ -10,6 +10,7 @@
import org.apache.http.client.ClientProtocolException;
import org.bukkit.Bukkit;
+import org.bukkit.configuration.ConfigurationSection;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.ParseException;
@@ -29,9 +30,6 @@ public void run() {
}
public static void loadItemPriceData() {
- if (Main.getItemPrices() != null) {
- Main.itemPrices.clear();
- }
Set strSet = Main.map.keySet();
for (String str : strSet) {
Main.itemPrices.put(str, new ItemPriceData(str));
@@ -40,8 +38,9 @@ public static void loadItemPriceData() {
public static void loadItemPricesAndCalculate() throws ParseException, ClientProtocolException, IOException {
Integer playerCount = Main.calculatePlayerCount();
+ Main.log("Player count on price-update: " + playerCount);
+ Main.setupMaxBuySell();
if (playerCount >= Config.getUpdatePricesThreshold()){
- Main.setupMaxBuySell();
Main.log("Loading Item Price Update Algorithm");
JSONObject obj = new JSONObject();
JSONArray itemData = new JSONArray();
@@ -83,14 +82,23 @@ public static void loadEnchantmentPricesAndCalculate() throws ParseException, Cl
JSONObject obj = new JSONObject();
JSONArray itemData = new JSONArray();
Main.log("Loading Enchantment Price Update Algorithm");
- for (String str : Main.enchMap.get("Auto-Tune").keySet()) {
- ConcurrentHashMap buySellMap = Main.enchMap.get("Auto-Tune").get(str).buySellData;
+ Set set = Main.enchMap.keySet();
+ for (String str : set) {
+ ConfigurationSection config = Main.getShopConfig().getConfigurationSection("shops").getConfigurationSection(str);
+ try{
+ boolean locked = config.getBoolean("locked");
+ if (locked){
+ continue;
+ }
+ }
+ catch(NullPointerException ex){}
+ ConcurrentHashMap buySellMap = Main.enchMap.get(str).buySellData;
Double price;
try{
price = buySellMap.get(buySellMap.size()-1)[0];
}
catch(NullPointerException ex){
- price = Main.enchMap.get("Auto-Tune").get(str).price;
+ price = Main.enchMap.get(str).price;
buySellMap.put(0, new Double[]{price, 0.0, 0.0});
}
Double[] arr = loadAverageBuyAndSellValue(buySellMap, price, str);
@@ -117,7 +125,6 @@ public static void loadEnchantmentPricesAndCalculate() throws ParseException, Cl
public static Double[] loadAverageBuyAndSellValue(ConcurrentHashMap map, Double price, String name)
throws ParseException {
Integer tempSize = map.size()-1;
- Double[] arr = map.get(tempSize);
Integer x = 0;
Integer expvalues = 0;
Double tempbuys = 0.0;
diff --git a/Auto-Tune/src/unprotesting/com/github/util/Transaction.java b/Auto-Tune/src/unprotesting/com/github/util/Transaction.java
new file mode 100644
index 0000000..ea37424
--- /dev/null
+++ b/Auto-Tune/src/unprotesting/com/github/util/Transaction.java
@@ -0,0 +1,97 @@
+package unprotesting.com.github.util;
+
+import java.io.Serializable;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Date;
+
+import javax.lang.model.element.TypeElement;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+
+import unprotesting.com.github.Main;
+import unprotesting.com.github.Commands.AutoTuneGUIShopUserCommand;
+
+public class Transaction implements Serializable{
+
+ private static final long serialVersionUID = 4371216893978491119L;
+ public Date date;
+ public String player;
+ public String item;
+ public int amount;
+ public String type;
+ public double total_price;
+
+ public Transaction(Player player, ItemStack is, String type, double total_price){
+ this.date = Date.from(Instant.now());
+ this.player = player.getName();
+ this.item = is.getType().toString();
+ this.amount = is.getAmount();
+ this.total_price = total_price;
+ this.type = type;
+ }
+
+ @Deprecated
+ public Transaction(Player player, Enchantment enchantment, String type){
+ double price = Main.enchMap.get(enchantment.getName()).price;
+ price = price - price*0.01*Config.getSellPriceDifference();
+ this.date = Date.from(Instant.now());
+ this.player = player.getName();
+ this.item = enchantment.getName();
+ this.amount = 1;
+ this.total_price = price;
+ this.type = type;
+ }
+
+ public Transaction(Date date, Player player, String item, int amount, String type, double total_price){
+ this.date = date;
+ this.player = player.getName();
+ this.item = item;
+ this.amount = amount;
+ this.type = type;
+ this.total_price = total_price;
+ }
+
+ @Deprecated
+ public String toString() {
+ Player player = Bukkit.getPlayer(this.player);
+ String output = ("Date: " + this.date.toGMTString()
+ + " | Player: " + player.getDisplayName()
+ + " | UUID: " + player.getUniqueId()
+ + " | Item: " + this.item
+ + " | Quantity: " + this.amount
+ + " | Total Price Paid: " + Config.getCurrencySymbol() + AutoTuneGUIShopUserCommand.df2.format(this.total_price)
+ + " | Indiviudal Price: " + Config.getCurrencySymbol() + AutoTuneGUIShopUserCommand.df2.format(this.total_price/this.amount)
+ + " | Type: " + this.type
+ );
+ return output;
+ }
+
+ @Deprecated
+ public String toDisplayString() {
+ String output = (ChatColor.YELLOW + "Date: " + ChatColor.GREEN + this.date.toGMTString()
+ + ChatColor.YELLOW + " | Item: " + ChatColor.GREEN + this.item
+ + ChatColor.YELLOW + " | Quantity: " + ChatColor.GREEN + this.amount
+ + ChatColor.YELLOW + " | Total Price Paid: " + ChatColor.GREEN + Config.getCurrencySymbol() + AutoTuneGUIShopUserCommand.df2.format(this.total_price)
+ + ChatColor.YELLOW + " | Indiviudal Price: " + ChatColor.GREEN + Config.getCurrencySymbol() + AutoTuneGUIShopUserCommand.df2.format(this.total_price/this.amount)
+ + ChatColor.YELLOW + " | Type: " + ChatColor.GREEN + this.type
+ );
+ return output;
+ }
+
+ public void loadIntoMap(){
+ int size = Main.getTransactions().size()-1;
+ Main.transactions.put(size, this);
+ }
+
+ public void loadTransactionArrayIntoMap(Transaction[] arr){
+ for (Transaction transaction : arr){
+ transaction.loadIntoMap();
+ }
+ }
+
+}
diff --git a/Auto-Tune/src/unprotesting/com/github/util/TransactionSerializer.java b/Auto-Tune/src/unprotesting/com/github/util/TransactionSerializer.java
new file mode 100644
index 0000000..a81762f
--- /dev/null
+++ b/Auto-Tune/src/unprotesting/com/github/util/TransactionSerializer.java
@@ -0,0 +1,37 @@
+package unprotesting.com.github.util;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.UUID;
+
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.mapdb.DataInput2;
+import org.mapdb.DataOutput2;
+import org.mapdb.serializer.GroupSerializerObjectArray;
+
+public class TransactionSerializer extends GroupSerializerObjectArray {
+
+ @Override
+ public void serialize(DataOutput2 out, Transaction value) throws IOException {
+ out.writeUTF(value.date.toString());
+ out.writeUTF(value.item);
+ out.writeUTF(value.player);
+ out.writeUTF(value.type);
+ out.writeInt(value.amount);
+ out.writeDouble(value.total_price);
+ }
+
+ @Override
+ @Deprecated
+ public Transaction deserialize(DataInput2 input, int available) throws IOException {
+ Date date = new Date(Date.parse(input.readUTF()));
+ String item = input.readUTF();
+ Player player = Bukkit.getPlayer(input.readUTF());
+ String type = input.readUTF();
+ int amount = input.readInt();
+ double total_price = input.readDouble();
+ return new Transaction(date, player, item, amount, type, total_price);
+ }
+
+}