From 9a3e83f4a22938a3eb51cca12b0abf5d20beb61f Mon Sep 17 00:00:00 2001 From: "Noah Clarkson (Unprotesting)" Date: Tue, 24 Nov 2020 22:43:02 +0000 Subject: [PATCH 1/9] Initial Commit for Shop Overhaul + Started re-writing the shop for effieciency and features. --- Auto-Tune/src/resources/shops.yml | 40 +- .../Commands/AutoTuneGUIShopUserCommand.java | 1375 +++-------------- .../unprotesting/com/github/util/Section.java | 44 + README.md | 2 +- 4 files changed, 282 insertions(+), 1179 deletions(-) diff --git a/Auto-Tune/src/resources/shops.yml b/Auto-Tune/src/resources/shops.yml index 2737585..0d8d97d 100644 --- a/Auto-Tune/src/resources/shops.yml +++ b/Auto-Tune/src/resources/shops.yml @@ -40,97 +40,97 @@ shops: price: 15.00 max-buy: 80 max-sell: 115 - section: 'Ores' + section: 'Natural Resources' COAL_ORE: price: 30.00 max-buy: 50 max-sell: 90 - section: 'Ores' + section: 'Natural Resources' IRON_INGOT: price: 13.00 max-buy: 75 max-sell: 100 - section: 'Ores' + section: 'Natural Resources' IRON_ORE: price: 15.00 max-buy: 60 max-sell: 100 - section: 'Ores' + section: 'Natural Resources' GOLD_INGOT: price: 30.00 max-buy: 45 max-sell: 75 - section: 'Ores' + section: 'Natural Resources' GOLD_ORE: price: 32.50 max-buy: 40 max-sell: 90 - section: 'Ores' + section: 'Natural Resources' DIAMOND: price: 300.00 max-buy: 12 max-sell: 32 - section: 'Ores' + section: 'Natural Resources' DIAMOND_ORE: price: 550.00 max-buy: 5 max-sell: 12 - section: 'Ores' + section: 'Natural Resources' LAPIS_LAZULI: price: 18.00 max-buy: 128 max-sell: 256 - section: 'Ores' + section: 'Natural Resources' LAPIS_ORE: price: 35.00 max-buy: 64 max-sell: 80 - section: 'Ores' + section: 'Natural Resources' EMERALD: price: 150.00 max-buy: 12 max-sell: 32 - section: 'Ores' + section: 'Natural Resources' EMERALD_ORE: price: 250.00 max-buy: 6 max-sell: 32 - section: 'Ores' + section: 'Natural Resources' QUARTZ: price: 17.00 max-buy: 40 max-sell: 125 - section: 'Ores' + section: 'Natural Resources' NETHER_QUARTZ_ORE: price: 40.00 max-buy: 75 max-sell: 90 - section: 'Ores' + section: 'Natural Resources' REDSTONE: price: 9.00 max-buy: 80 max-sell: 128 - section: 'Ores' + section: 'Natural Resources' REDSTONE_ORE: price: 25.00 max-buy: 50 max-sell: 80 - section: 'Ores' + section: 'Natural Resources' NETHERITE_INGOT: price: 8000.00 max-buy: 1 max-sell: 2 - section: 'Ores' + section: 'Natural Resources' NETHERITE_SCRAP: price: 3000.00 max-buy: 2 max-sell: 4 - section: 'Ores' + section: 'Natural Resources' GLOWSTONE_DUST: price: 5.00 max-buy: 128 max-sell: 256 - section: 'Ores' + section: 'Natural Resources' DIRT: price: 0.5 max-buy: 512 @@ -658,7 +658,7 @@ shops: section: 'Other' ## Shop sections configuration sections: - 'Ores': + 'Natural Resources': ## Block that the section image is displayed as block: 'IRON_ORE' ## Optional - set to disabled to disable the back button when running "/shop ". diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java index 6e58950..f46d2bf 100644 --- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java +++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java @@ -2,7 +2,7 @@ import java.text.DecimalFormat; import java.util.Arrays; -import java.util.List; +import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; import com.github.stefvanschie.inventoryframework.Gui; @@ -15,7 +15,6 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -25,7 +24,6 @@ import org.bukkit.inventory.meta.ItemMeta; import net.md_5.bungee.api.ChatColor; -import net.milkbowl.vault.economy.Economy; import unprotesting.com.github.Main; import unprotesting.com.github.util.Config; import unprotesting.com.github.util.Section; @@ -35,23 +33,21 @@ public class AutoTuneGUIShopUserCommand implements CommandExecutor { public static DecimalFormat df1 = new DecimalFormat("###########0.00"); public static DecimalFormat df2 = new DecimalFormat("###,###,###,##0.00"); - static DecimalFormat df3 = new DecimalFormat("###,###,###,##0.00000"); + public static DecimalFormat df3 = new DecimalFormat("###,###,###,##0.00000"); public static DecimalFormat df4 = new DecimalFormat("###########0.0000"); public static DecimalFormat df5 = new DecimalFormat("###########0"); - public Economy economy = Main.getEconomy(); - public static Integer SBPanePos = 1; + public static Integer[] amounts = {1, 2, 4, 8, 16, 32, 64}; + @Override public boolean onCommand(CommandSender sender, Command command, String shop, String[] args) { - if (command.getName().equalsIgnoreCase("shop")) { if (!(sender instanceof Player)) { Main.sendMessage(sender, "&cPlayers only."); return true; } - Player p = (Player) sender; if (Config.getMenuRows() == 6) { SBPanePos = 2; @@ -59,7 +55,7 @@ public boolean onCommand(CommandSender sender, Command command, String shop, Str if (args.length == 0){ if (p.hasPermission("at.shop") || p.isOp()) { - loadGUISECTIONS(p, sender); + loadGUISECTIONS(p); } else if (!(p.hasPermission("at.shop")) && !(p.isOp())){TextHandler.noPermssion(p);} return true; @@ -78,7 +74,7 @@ public boolean onCommand(CommandSender sender, Command command, String shop, Str } for (int i = 0; i < Main.sectionedItems.length; i++){ if (Main.sectionedItems[i].name.toLowerCase().equals(inputSection)){ - loadGUIMAIN(p, sender, Main.sectionedItems[i], true); + loadGUIMAIN(p, Main.sectionedItems[i], true); return true; } } @@ -90,13 +86,13 @@ public boolean onCommand(CommandSender sender, Command command, String shop, Str return false; } - public void loadGUISECTIONS(Player player, CommandSender senderpub){ - Gui front = new Gui(3, Config.getMenuTitle()); - OutlinePane pane = new OutlinePane(1, 1, 7, 1); - if (Main.sectionedItems.length > 7){ - front = new Gui(4, Config.getMenuTitle()); - pane = new OutlinePane(1, 1, 7, 2); + public void loadGUISECTIONS(Player player){ + int lines = (int)Math.floor(((Main.sectionedItems.length)/7)+1); + if (lines > 4){ + lines = 4; } + Gui front = new Gui((lines+2), Config.getMenuTitle()); + OutlinePane pane = new OutlinePane(1, 1, 7, lines); for (int i = 0; i < Main.sectionedItems.length; i++){ ItemStack is = new ItemStack((Main.sectionedItems[i].image)); ItemMeta im = is.getItemMeta(); @@ -107,8 +103,9 @@ public void loadGUISECTIONS(Player player, CommandSender senderpub){ GuiItem gItem = new GuiItem(is, event ->{ final Player playernew = player; if (event.getClick() == ClickType.LEFT) { + event.setCancelled(true); player.getOpenInventory().close(); - loadGUIMAIN(player, senderpub, inputSection, false); + loadGUIMAIN(player, inputSection, false); } else if (event.getClick() != ClickType.LEFT) { event.setCancelled(true); @@ -119,1194 +116,256 @@ else if (event.getClick() != ClickType.LEFT) { front.addPane(pane); } front.update(); - front.show((HumanEntity) senderpub); + CommandSender playerSender = player; + front.show((HumanEntity) playerSender); } - public void loadGUIMAIN(Player player, CommandSender senderpub, Section sec, boolean twoArgs) { - Integer menuRows = Config.getMenuRows(); - OutlinePane SBPane = new OutlinePane(1, SBPanePos, 7, 2); - ItemStack is; - GuiItem a; - final Player playerpub = player; - Integer i = 0; - Material b; - Double price1; - Gui gui1; - StaticPane pageTwo = new StaticPane(1, 1, 7, menuRows - 2); - StaticPane pageThree = new StaticPane(1, 1, 7, menuRows - 2); - StaticPane pageFour = new StaticPane(1, 1, 7, menuRows - 2); - StaticPane pageFive = new StaticPane(1, 1, 7, menuRows - 2); - StaticPane back = new StaticPane(0, menuRows - 1, 1, 1); - StaticPane forward = new StaticPane(8, menuRows - 1, 1, 1); - StaticPane reset = new StaticPane(0, 0, 1, 1); - - player = (Player) senderpub; - gui1 = new Gui(menuRows, Config.getMenuTitle()); - Integer size = sec.items.size(); - PaginatedPane pane = new PaginatedPane(0, 0, 9, menuRows); - Integer paneSize = (menuRows - 2) * 7; - Integer pageAmount = 2; - if (size > paneSize) { - pageAmount = 3; - pane.addPane(1, pageTwo); + public void loadGUIMAIN(Player player, Section sec, boolean twoArgs) { + int itemAmount = sec.items.size(); + int lines = (int)Math.floor(((itemAmount-1)/7)+1); + Main.log("Lines: " + lines); + if (lines > 4){ + lines = 4; } - if (size > paneSize * 2) { - pageAmount = 4; - pane.addPane(2, pageThree); + Gui main = new Gui((lines+2), Config.getMenuTitle()); + Integer paneSize = (lines+1)*7; + Integer paneAmount = (int) Math.ceil(itemAmount/paneSize)+1; + Main.log("Pane Amount: " + paneAmount); + Main.log("Pane Size: " + paneSize); + PaginatedPane pPane = new PaginatedPane(0, 0, 9, (lines+2)); + OutlinePane[] shopPanes = new OutlinePane[paneAmount]; + for (int i = 0; i < shopPanes.length; i++){ + shopPanes[i] = new OutlinePane(1, 1, 7, lines); + for(int k = 0; k < paneSize; k++){ + if(k+(i*paneSize) < sec.items.size()){ + String itemName = sec.items.get(k+(i*paneSize)); + ItemStack iStack = loadShopItem(itemName, sec); + GuiItem item = new GuiItem(iStack, event ->{ + if (event.getClick() == ClickType.LEFT){ + event.setCancelled(true); + player.getOpenInventory().close(); + loadGUITRADING(player, itemName); + } + else{ + event.setCancelled(true); + } + }); + shopPanes[i].addItem(item); + } + else{ + break; + } + } } - if (size > paneSize * 3) { - pageAmount = 5; - pane.addPane(3, pageFour); + for (int i = 0; i < shopPanes.length; i++){ + pPane.addPane(i, shopPanes[i]); } - if (size > paneSize * 4) { - pageAmount = 6; - pane.addPane(4, pageFive); + main.addPane(pPane); + StaticPane[] panes = loadPagePanes(pPane, (lines+1), main); + panes[0].setVisible(false); + panes[1].setVisible(true); + if (pPane.getPages() == 1){ + panes[1].setVisible(false); } - - final Integer finalPageAmount = pageAmount; - - boolean showBackButton = true; - if (twoArgs){ - if (!sec.showBackButton){ - showBackButton = false; - } + main.addPane(panes[0]); + main.addPane(panes[1]); + if (twoArgs == false || (twoArgs == true && sec.showBackButton == true)){ + main.addPane(loadMainMenuBackPane(pPane)); } - final boolean fSBB = showBackButton; + CommandSender cSender = player; + main.update(); + main.show((HumanEntity) cSender); + } - // page one - StaticPane pageOne = new StaticPane(1, 1, 7, menuRows - 2); - for (i = 0; i { - if (event.getClick() == ClickType.LEFT) { - Gui gui = gui1; - final Player playernew = playerpub; - final Double price; - String matClickedString = ""; - ItemStack tempis = event.getCurrentItem(); - Material tempmat = tempis.getType(); - matClickedString = tempmat.toString(); - ConcurrentHashMap tempmap = Main.map.get(matClickedString); - Integer tempMapSize = tempmap.size(); - Double[] tempDoublearray = tempmap.get(tempMapSize - 1); - price = tempDoublearray[0]; - createTradingPanel(gui, matClickedString, playernew, SBPane, price, forward, back, fSBB); - if (finalPageAmount == 2) { - pane.setPage(1); - } - if (finalPageAmount == 3) { - pane.setPage(2); - } - if (finalPageAmount == 4) { - pane.setPage(3); - } - if (finalPageAmount == 5) { - pane.setPage(4); + public void loadGUITRADING(Player player, String itemName){ + Gui main = new Gui(4, Config.getMenuTitle()); + OutlinePane front = new OutlinePane(1, 1, 7, 2); + for (int i = 0; i < 14; i++){ + final int finalI = i; + ItemStack iStack; + GuiItem gItem; + if (i < 7){ + iStack = loadTradingItem(itemName, amounts[i], true); + gItem = new GuiItem(iStack, event ->{ + event.setCancelled(true); + try { + HashMap unableItems = player.getInventory().addItem(new ItemStack(Material.matchMaterial(itemName), amounts[finalI])); + if (unableItems.size() > 0){ + player.sendMessage(ChatColor.BOLD + "Cant sell " + Integer.toString(amounts[finalI]) + "x of " + itemName); } - if (finalPageAmount == 6) { - pane.setPage(5); + else{ + sendPlayerShopMessageAndUpdateGDP(amounts[finalI], player, itemName, false); } - gui.update(); - playernew.setItemOnCursor(null); - event.setCancelled(true); } - if (event.getClick() != ClickType.LEFT) { - final Player playernew = playerpub; - event.setCancelled(true); - playernew.setItemOnCursor(null); + catch(IllegalArgumentException ex){ } }); - ItemMeta im = is.getItemMeta(); - im.setDisplayName(ChatColor.AQUA + sec.items.get(i)); - ConcurrentHashMap tempmap = Main.map.get(sec.items.get(i)); - Integer tempMapSize = tempmap.size(); - Double[] tempDoublearray = tempmap.get(tempMapSize - 1); - price1 = tempDoublearray[0]; - String priceString = df2.format(price1); - String fullprice = "Price: " + Config.getCurrencySymbol() + priceString; - im.setLore(Arrays.asList((ChatColor.GOLD + fullprice), (ChatColor.WHITE + "Maximum Buys: " + (Integer)Main.getShopConfig().get("shops." + sec.items.get(i) + "." + "max-buy") + " per " + Config.getTimePeriod() + "min"), (ChatColor.WHITE + "Maximum Sells: " + (Integer)Main.getShopConfig().get("shops." + sec.items.get(i) + "." + "max-sell") + " per " + Config.getTimePeriod() + "min"))); - is.setItemMeta(im); - if (Config.getMenuRows() == 4) { - if (i<7) { - pageOne.addItem(a, i, 0); - } - else if (i >= 7 && i<14) { - pageOne.addItem(a, i - 7, 1); - } - else if (i >= 14 && i<21) { - pageTwo.addItem(a, i - 14, 0); - } - else if (i >= 21 && i<28) { - pageTwo.addItem(a, i - 21, 1); - } - else if (i >= 28 && i<35) { - pageThree.addItem(a, i - 28, 0); - } - else if (i >= 35 && i<42) { - pageThree.addItem(a, i - 35, 1); - } - else if (i >= 42 && i<49) { - pageFour.addItem(a, i - 42, 0); - } - else if (i >= 49 && i<56) { - pageFour.addItem(a, i - 49, 1); - } - else if (i >= 56 && i<63) { - pageFive.addItem(a, i - 56, 0); - } - else if (i >= 63 && i<70) { - pageFive.addItem(a, i - 63, 1); - } - } - if (Config.getMenuRows() == 5) { - if (i<7) { - pageOne.addItem(a, i, 0); - } - else if (i >= 7 && i<14) { - pageOne.addItem(a, i - 7, 1); - } - else if (i >= 14 && i<21) { - pageOne.addItem(a, i - 14, 2); - } - else if (i >= 21 && i<28) { - pageTwo.addItem(a, i - 21, 0); - } - else if (i >= 28 && i<35) { - pageTwo.addItem(a, i - 28, 1); - } - else if (i >= 35 && i<42) { - pageTwo.addItem(a, i - 35, 2); - } - else if (i >= 42 && i<49) { - pageThree.addItem(a, i - 42, 0); - } - else if (i >= 49 && i<56) { - pageThree.addItem(a, i - 49, 1); - } - else if (i >= 56 && i<63) { - pageThree.addItem(a, i - 56, 2); - } - else if (i >= 63 && i<70) { - pageFour.addItem(a, i - 63, 0); - } - else if (i >= 70 && i<77) { - pageFour.addItem(a, i - 70, 1); - } - else if (i >= 77 && i<84) { - pageFour.addItem(a, i - 77, 2); - } - else if (i >= 84 && i<91) { - pageFive.addItem(a, i - 84, 0); - } - else if (i >= 91 && i<98) { - pageFive.addItem(a, i - 91, 1); - } - else if (i >= 98 && i<105) { - pageFive.addItem(a, i - 98, 2); - } - } - if (Config.getMenuRows() == 6) { - if (i<7) { - pageOne.addItem(a, i, 0); - } - else if (i >= 7 && i<14) { - pageOne.addItem(a, i - 7, 1); - } - else if (i >= 14 && i<21) { - pageOne.addItem(a, i - 14, 2); - } - else if (i >= 21 && i<28) { - pageOne.addItem(a, i - 21, 3); - } - else if (i >= 28 && i<35) { - pageTwo.addItem(a, i - 28, 0); - } - else if (i >= 35 && i<42) { - pageTwo.addItem(a, i - 35, 1); - } - else if (i >= 42 && i<49) { - pageTwo.addItem(a, i - 42, 2); - } - else if (i >= 49 && i<56) { - pageTwo.addItem(a, i - 49, 3); - } - else if (i >= 56 && i<63) { - pageThree.addItem(a, i - 56, 0); - } - else if (i >= 63 && i<70) { - pageThree.addItem(a, i - 63, 1); - } - else if (i >= 70 && i<77) { - pageThree.addItem(a, i - 70, 2); - } - else if (i >= 77 && i<84) { - pageThree.addItem(a, i - 77, 3); - } - else if (i >= 84 && i<91) { - pageFour.addItem(a, i - 84, 0); - } - else if (i >= 91 && i<98) { - pageFour.addItem(a, i - 91, 1); - } - else if (i >= 98 && i<105) { - pageFour.addItem(a, i - 98, 2); - } - else if (i >= 105 && i<112) { - pageFour.addItem(a, i - 105, 3); - } - else if (i >= 112 && i<119) { - pageFive.addItem(a, i - 112, 0); - } - else if (i >= 119 && i<126) { - pageFive.addItem(a, i - 119, 1); - } - else if (i >= 126 && i<135) { - pageFive.addItem(a, i - 126, 2); + } + else{ + iStack = loadTradingItem(itemName, amounts[i-7], false); + gItem = new GuiItem(iStack, event ->{ + event.setCancelled(true); + try { + HashMap takenItems = player.getInventory().removeItem(new ItemStack(Material.matchMaterial(itemName), amounts[finalI])); + if (takenItems.size() > 0){ + player.sendMessage(ChatColor.BOLD + "Cant sell " + Integer.toString(amounts[finalI]) + "x of " + itemName); + } + else{ + sendPlayerShopMessageAndUpdateGDP(amounts[finalI-8], player, itemName, true); + } } - else if (i >= 135 && i<142) { - pageFive.addItem(a, i - 135, 3); + catch(IllegalArgumentException ex){ } - - } - - i++; + }); } - - } - pane.addPane(0, pageOne); - if (finalPageAmount == 3) { - pane.addPane(1, pageTwo); - pane.addPane(2, SBPane); - } - else if (finalPageAmount == 4) { - pane.addPane(1, pageTwo); - pane.addPane(2, pageThree); - pane.addPane(3, SBPane); - } - else if (finalPageAmount == 5) { - pane.addPane(1, pageTwo); - pane.addPane(2, pageThree); - pane.addPane(3, pageFour); - pane.addPane(4, SBPane); - } - else if (finalPageAmount == 6) { - pane.addPane(1, pageTwo); - pane.addPane(2, pageThree); - pane.addPane(3, pageFour); - pane.addPane(4, pageFive); - pane.addPane(5, SBPane); - } - else { - pane.addPane(1, SBPane); + front.addItem(gItem); } + main.addPane(front); + CommandSender cSender = player; + main.update(); + main.show((HumanEntity) cSender); + } - gui1.addPane(pane); + public ItemStack loadShopItem(String itemName, Section sec){ + ItemStack iStack = new ItemStack(Material.matchMaterial(itemName)); + ItemMeta iMeta = iStack.getItemMeta(); + Integer[] maxBuySellForItem = sec.itemMaxBuySell.get(itemName); + iMeta.setDisplayName(ChatColor.GOLD + itemName); + iMeta.setLore(Arrays.asList((ChatColor.GRAY + "Click to purchase/sell"), + (ChatColor.WHITE + "Max Buys: " + maxBuySellForItem[0] + " per " + Config.getTimePeriod() + "min"), + (ChatColor.WHITE + "Max Sells: " + maxBuySellForItem[1] + " per " + Config.getTimePeriod() + "min"))); + iStack.setItemMeta(iMeta); + return iStack; + } - // page selection - ItemStack isback = new ItemStack(Material.ARROW); - ItemMeta imback = isback.getItemMeta(); - imback.setDisplayName(ChatColor.WHITE + "Back"); - imback.setLore(Arrays.asList(ChatColor.BOLD + "Click to return to Shop Menu")); - isback.setItemMeta(imback); - ItemStack isforward = new ItemStack(Material.ARROW); - ItemMeta imforward = isforward.getItemMeta(); - imforward.setDisplayName(ChatColor.WHITE + "Next Page"); - imforward.setLore(Arrays.asList(ChatColor.BOLD + "Click to go to the next page")); - isforward.setItemMeta(imforward); - ItemStack isback2 = new ItemStack(Material.ARROW); - ItemMeta imback2 = isback2.getItemMeta(); - imback2.setDisplayName(ChatColor.WHITE + "Main-Menu"); - imback2.setLore(Arrays.asList(ChatColor.BOLD + "Click to return to Main-Shop Menu")); - isback2.setItemMeta(imback2); - - final Player fPlayer = player; - - if (fSBB){ - reset.addItem(new GuiItem(new ItemStack(isback2), event -> { - fPlayer.getOpenInventory().close(); - loadGUISECTIONS(fPlayer, senderpub); - }), 0, 0); + public ItemStack loadTradingItem(String itemName, int number, boolean buy){ + ItemStack iStack = new ItemStack(Material.matchMaterial(itemName)); + ItemMeta iMeta = iStack.getItemMeta(); + iMeta.setDisplayName(ChatColor.GOLD + itemName); + if (buy){ + iMeta.setLore(Arrays.asList((ChatColor.WHITE + "$" + df2.format(getItemPrice(itemName)*number)), + (ChatColor.GRAY + "Purchase " + number + "x "))); + iStack.setItemMeta(iMeta); } - - if (pane.getPage() == 0 && finalPageAmount == 6) { - back.setVisible(false); - forward.setVisible(true); + if (!buy){ + iMeta.setLore(Arrays.asList((ChatColor.WHITE + "$" + df2.format(getItemPrice(itemName)*number)), + (ChatColor.GRAY + "Sell " + number + "x "))); + iStack.setItemMeta(iMeta); } + return iStack; + } - if (pane.getPage() == 0 && finalPageAmount == 5) { - back.setVisible(false); - forward.setVisible(true); + public boolean hasAvaliableSlot(Player player) { + InventoryView invview = player.getOpenInventory(); + Inventory inv = invview.getBottomInventory(); + Boolean check = true; + int a = inv.firstEmpty(); + if (a == -1) { + check = false; + return check; } + return check; + } - if (pane.getPage() == 0 && finalPageAmount == 4) { - back.setVisible(false); - forward.setVisible(true); - } + public Double getItemPrice(String item){ + ConcurrentHashMap inputMap = Main.map.get(item); + Double[] arr = inputMap.get(inputMap.size()-1); + return arr[0]; + } - if (pane.getPage() == 0 && finalPageAmount == 3) { - back.setVisible(false); + public StaticPane[] loadPagePanes(PaginatedPane pPane, int lines, Gui main){ + StaticPane output = new StaticPane(0, (lines), 1, 1); + ItemStack iStack = new ItemStack(Material.ARROW); + ItemMeta iMeta = iStack.getItemMeta(); + iMeta.setDisplayName(ChatColor.DARK_PURPLE + "Back"); + iMeta.setLore(Arrays.asList(ChatColor.GRAY + "Page " + ChatColor.WHITE + (pPane.getPage()+1))); + iStack.setItemMeta(iMeta); + StaticPane forward = loadForwardPane(pPane, lines, main, output); + GuiItem gItem = new GuiItem(iStack, event ->{ + event.setCancelled(true); + int page = pPane.getPage(); + pPane.setPage(page-1); forward.setVisible(true); - } - - if (pane.getPage() == 0 && finalPageAmount == 2) { - forward.setVisible(false); - } - - back.addItem(new GuiItem(new ItemStack(isback), event -> { - if (pane.getPage() != 0) { - pane.setPage(pane.getPage() - 1); - } - if (pane.getPage() != (finalPageAmount-2) && pane.getPage() != (finalPageAmount-1) && pane.getPage() != (finalPageAmount)){ + if (pPane.getPage() == 0){ + output.setVisible(false); forward.setVisible(true); } - else if (pane.getPage() == 0 && finalPageAmount == 2) { - forward.setVisible(false); - } - if (pane.getPage() == 0){ - back.setVisible(false); - } - - gui1.update(); - }), 0, 0); - - back.setVisible(false); - - forward.addItem(new GuiItem(new ItemStack(isforward), event -> { - pane.setPage(pane.getPage() + 1); - forward.setVisible(false); - - if ((pane.getPage() == (finalPageAmount)) || (pane.getPage() == (finalPageAmount)-1) || (pane.getPage() == (finalPageAmount)-2)) { - forward.setVisible(false); - } - - else{ - forward.setVisible(true); - } - - back.setVisible(true); - gui1.update(); - }), 0, 0); - - gui1.addPane(back); - gui1.addPane(forward); - if (fSBB){ - gui1.addPane(reset); - } - gui1.show((HumanEntity) senderpub); - - } - - public Double sellpricedif; - public Double sellpricedif2; - - public void createTradingPanel(Gui gui, String matClickedString, Player player, OutlinePane SBPane, Double price, StaticPane forward, StaticPane back, boolean showMainMenuButton) { - sellpricedif2 = null; - sellpricedif = null; - sellpricedif = Config.getSellPriceDifference(); - Main.getINSTANCE(); - ConfigurationSection config = Main.getShopConfig().getConfigurationSection("shops") - .getConfigurationSection((matClickedString)); - sellpricedif2 = config.getDouble("sell-difference", sellpricedif); - if (sellpricedif2 != null) { - sellpricedif = sellpricedif2; - } - SBPane.clear(); - ItemStack is1 = new ItemStack(Material.matchMaterial(matClickedString), 1); - ItemMeta is1im = is1.getItemMeta(); - is1im.setDisplayName(ChatColor.GOLD + "Buy 1x " + ChatColor.AQUA + matClickedString); - is1im.setLore(Arrays.asList(ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(price))); - is1.setItemMeta(is1im); - ItemStack is2 = new ItemStack(Material.matchMaterial(matClickedString), 2); - ItemMeta is2im = is2.getItemMeta(); - is2im.setDisplayName(ChatColor.GOLD + "Buy 2x " + ChatColor.AQUA + matClickedString); - is2im.setLore(Arrays.asList(ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(price * 2))); - is2.setItemMeta(is2im); - ItemStack is4 = new ItemStack(Material.matchMaterial(matClickedString), 4); - ItemMeta is4im = is4.getItemMeta(); - is4im.setDisplayName(ChatColor.GOLD + "Buy 4x " + ChatColor.AQUA + matClickedString); - is4im.setLore(Arrays.asList(ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(price * 4))); - is4.setItemMeta(is4im); - ItemStack is8 = new ItemStack(Material.matchMaterial(matClickedString), 8); - ItemMeta is8im = is8.getItemMeta(); - is8im.setDisplayName(ChatColor.GOLD + "Buy 8x " + ChatColor.AQUA + matClickedString); - is8im.setLore(Arrays.asList(ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(price * 8))); - is8.setItemMeta(is8im); - ItemStack is16 = new ItemStack(Material.matchMaterial(matClickedString), 16); - ItemMeta is16im = is16.getItemMeta(); - is16im.setDisplayName(ChatColor.GOLD + "Buy 16x " + ChatColor.AQUA + matClickedString); - is16im.setLore(Arrays.asList(ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(price * 16))); - is16.setItemMeta(is16im); - ItemStack is32 = new ItemStack(Material.matchMaterial(matClickedString), 32); - ItemMeta is32im = is2.getItemMeta(); - is32im.setDisplayName(ChatColor.GOLD + "Buy 32x " + ChatColor.AQUA + matClickedString); - is32im.setLore(Arrays.asList(ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(price * 32))); - is32.setItemMeta(is32im); - ItemStack is64 = new ItemStack(Material.matchMaterial(matClickedString), 64); - ItemMeta is64im = is2.getItemMeta(); - is64im.setDisplayName(ChatColor.GOLD + "Buy 64x " + ChatColor.AQUA + matClickedString); - is64im.setLore(Arrays.asList(ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(price * 64))); - is64.setItemMeta(is64im); - GuiItem isa = new GuiItem(is1, event -> { - player.setItemOnCursor(null); - if ((Player) event.getWhoClicked() == player) { - ConcurrentHashMap tempMap2 = Main.map.get(matClickedString); - Integer tempMap2Size = tempMap2.size(); - Double[] tempDarray2 = tempMap2.get(tempMap2Size - 1); - Double buyAmount = tempDarray2[1]; - Double sellAmount = tempDarray2[2]; - Double[] tempDArray = { - price, - buyAmount + 1, - sellAmount - }; - tempMap2.put(tempMap2Size - 1, tempDArray); - ConcurrentHashMap cMap = Main.maxBuyMap.get(player.getUniqueId()); - boolean notMax = true; - Integer max = (Integer)Main.getShopConfig().get("shops." + matClickedString + "." + "max-buy"); - if (max == null){ - max = 100000; - } - if ((cMap.get(matClickedString)+1) > max){ - notMax = false; - player.sendMessage(ChatColor.RED + "Maximum buys reached"); - } - if (hasAvaliableSlot(player) == true && (Main.econ.getBalance(player)) > (price) && notMax == true) { - Main.map.put(matClickedString, tempMap2); - Main.econ.withdrawPlayer(player, price); - player.getInventory().addItem(new ItemStack(Material.matchMaterial(matClickedString), 1)); - sendPlayerShopMessageAndUpdateGDP(1, price, player, matClickedString, false); - } else { - player.sendMessage(ChatColor.RED + "Cannot purchase 1x " + matClickedString + " for " + ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(price)); - - } - player.setItemOnCursor(null); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - player.setItemOnCursor(null); - event.setCancelled(true); - } - }); - GuiItem isa2 = new GuiItem(is2, event -> { - player.setItemOnCursor(null); - if ((Player) event.getWhoClicked() == player) { - ConcurrentHashMap tempMap2 = Main.map.get(matClickedString); - Integer tempMap2Size = tempMap2.size(); - Double[] tempDarray2 = tempMap2.get(tempMap2Size - 1); - Double buyAmount = tempDarray2[1]; - Double sellAmount = tempDarray2[2]; - Double[] tempDArray = { - price, - buyAmount + 2, - sellAmount - }; - tempMap2.put(tempMap2Size - 1, tempDArray); - ConcurrentHashMap cMap = Main.maxBuyMap.get(player.getUniqueId()); - boolean notMax = true; - Integer max = (Integer)Main.getShopConfig().get("shops." + matClickedString + "." + "max-buy"); - if (max == null){ - max = 100000; - } - if ((cMap.get(matClickedString)+1) > max){ - notMax = false; - player.sendMessage(ChatColor.RED + "Maximum buys reached"); - } - if (hasAvaliableSlot(player) == true && Main.econ.getBalance(player) > (price*2) && notMax == true) { - Main.map.put(matClickedString, tempMap2); - Main.econ.withdrawPlayer(player, price * 2); - player.getInventory().addItem(new ItemStack(Material.matchMaterial(matClickedString), 2)); - sendPlayerShopMessageAndUpdateGDP(2, price, player, matClickedString, false); - } else { - player.sendMessage(ChatColor.RED + "Cannot purchase 2x " + matClickedString + " for " + ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(price * 2)); - - } - player.setItemOnCursor(null); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - player.setItemOnCursor(null); - event.setCancelled(true); - } - }); - GuiItem isa4 = new GuiItem(is4, event -> { - player.setItemOnCursor(null); - if ((Player) event.getWhoClicked() == player) { - ConcurrentHashMap tempMap2 = Main.map.get(matClickedString); - Integer tempMap2Size = tempMap2.size(); - Double[] tempDarray2 = tempMap2.get(tempMap2Size - 1); - Double buyAmount = tempDarray2[1]; - Double sellAmount = tempDarray2[2]; - Double[] tempDArray = { - price, - buyAmount + 4, - sellAmount - }; - tempMap2.put(tempMap2Size - 1, tempDArray); - ConcurrentHashMap cMap = Main.maxBuyMap.get(player.getUniqueId()); - boolean notMax = true; - Integer max = (Integer)Main.getShopConfig().get("shops." + matClickedString + "." + "max-buy"); - if (max == null){ - max = 100000; - } - if ((cMap.get(matClickedString)+4) > max){ - notMax = false; - player.sendMessage(ChatColor.RED + "Maximum buys reached"); - } - if (hasAvaliableSlot(player) == true && Main.econ.getBalance(player) > (price*4) && notMax == true) { - Main.map.put(matClickedString, tempMap2); - Main.econ.withdrawPlayer(player, price * 4); - player.getInventory().addItem(new ItemStack(Material.matchMaterial(matClickedString), 4)); - sendPlayerShopMessageAndUpdateGDP(4, price, player, matClickedString, false); - } else { - player.sendMessage(ChatColor.RED + "Cannot purchase 4x " + matClickedString + " for " + ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(price * 4)); - - } - player.setItemOnCursor(null); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - player.setItemOnCursor(null); - event.setCancelled(true); - } - }); - GuiItem isa8 = new GuiItem(is8, event -> { - player.setItemOnCursor(null); - if ((Player) event.getWhoClicked() == player) { - ConcurrentHashMap tempMap2 = Main.map.get(matClickedString); - Integer tempMap2Size = tempMap2.size(); - Double[] tempDarray2 = tempMap2.get(tempMap2Size - 1); - Double buyAmount = tempDarray2[1]; - Double sellAmount = tempDarray2[2]; - Double[] tempDArray = { - price, - buyAmount + 8, - sellAmount - }; - tempMap2.put(tempMap2Size - 1, tempDArray); - ConcurrentHashMap cMap = Main.maxBuyMap.get(player.getUniqueId()); - boolean notMax = true; - Integer max = (Integer)Main.getShopConfig().get("shops." + matClickedString + "." + "max-buy"); - if (max == null){ - max = 100000; - } - if ((cMap.get(matClickedString)+8) > max){ - notMax = false; - player.sendMessage(ChatColor.RED + "Maximum buys reached"); - } - if (hasAvaliableSlot(player) == true && Main.econ.getBalance(player) > (price*8) && notMax == true) { - Main.map.put(matClickedString, tempMap2); - Main.econ.withdrawPlayer(player, price * 8); - player.getInventory().addItem(new ItemStack(Material.matchMaterial(matClickedString), 8)); - sendPlayerShopMessageAndUpdateGDP(8, price, player, matClickedString, false); - } else { - player.sendMessage(ChatColor.RED + "Cannot purchase 8x " + matClickedString + " for " + ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(price * 8)); - - } - player.setItemOnCursor(null); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - player.setItemOnCursor(null); - event.setCancelled(true); - } - }); - GuiItem isa16 = new GuiItem(is16, event -> { - player.setItemOnCursor(null); - if ((Player) event.getWhoClicked() == player) { - ConcurrentHashMap tempMap2 = Main.map.get(matClickedString); - Integer tempMap2Size = tempMap2.size(); - Double[] tempDarray2 = tempMap2.get(tempMap2Size - 1); - Double buyAmount = tempDarray2[1]; - Double sellAmount = tempDarray2[2]; - Double[] tempDArray = { - price, - buyAmount + 16, - sellAmount - }; - tempMap2.put(tempMap2Size - 1, tempDArray); - ConcurrentHashMap cMap = Main.maxBuyMap.get(player.getUniqueId()); - boolean notMax = true; - Integer max = (Integer)Main.getShopConfig().get("shops." + matClickedString + "." + "max-buy"); - if (max == null){ - max = 100000; - } - if ((cMap.get(matClickedString)+16) > max){ - notMax = false; - player.sendMessage(ChatColor.RED + "Maximum buys reached"); - } - if (hasAvaliableSlot(player) == true && Main.econ.getBalance(player) > (price*16) && notMax == true) { - Main.map.put(matClickedString, tempMap2); - Main.econ.withdrawPlayer(player, price * 16); - player.getInventory().addItem(new ItemStack(Material.matchMaterial(matClickedString), 16)); - sendPlayerShopMessageAndUpdateGDP(16, price, player, matClickedString, false); - } else { - player.sendMessage(ChatColor.RED + "Cannot purchase 16x " + matClickedString + " for " + ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(price * 16)); - - } - player.setItemOnCursor(null); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - player.setItemOnCursor(null); - event.setCancelled(true); - } - }); - GuiItem isa32 = new GuiItem(is32, event -> { - player.setItemOnCursor(null); - if ((Player) event.getWhoClicked() == player) { - ConcurrentHashMap tempMap2 = Main.map.get(matClickedString); - Integer tempMap2Size = tempMap2.size(); - Double[] tempDarray2 = tempMap2.get(tempMap2Size - 1); - Double buyAmount = tempDarray2[1]; - Double sellAmount = tempDarray2[2]; - Double[] tempDArray = { - price, - buyAmount + 32, - sellAmount - }; - tempMap2.put(tempMap2Size - 1, tempDArray); - ConcurrentHashMap cMap = Main.maxBuyMap.get(player.getUniqueId()); - boolean notMax = true; - Integer max = (Integer)Main.getShopConfig().get("shops." + matClickedString + "." + "max-buy"); - if (max == null){ - max = 100000; - } - if ((cMap.get(matClickedString)+32) > max){ - notMax = false; - player.sendMessage(ChatColor.RED + "Maximum buys reached"); - } - if (hasAvaliableSlot(player) == true && Main.econ.getBalance(player) > (price*32) && notMax == true) { - Main.map.put(matClickedString, tempMap2); - Main.econ.withdrawPlayer(player, price * 32); - player.getInventory().addItem(new ItemStack(Material.matchMaterial(matClickedString), 32)); - sendPlayerShopMessageAndUpdateGDP(32, price, player, matClickedString, false); - } else { - player.sendMessage(ChatColor.RED + "Cannot purchase 32x " + matClickedString + " for " + ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(price * 32)); - - } - player.setItemOnCursor(null); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - player.setItemOnCursor(null); - event.setCancelled(true); - } - }); - GuiItem isa64 = new GuiItem(is64, event -> { - player.setItemOnCursor(null); - if ((Player) event.getWhoClicked() == player) { - ConcurrentHashMap tempMap2 = Main.map.get(matClickedString); - Integer tempMap2Size = tempMap2.size(); - Double[] tempDarray2 = tempMap2.get(tempMap2Size - 1); - Double buyAmount = tempDarray2[1]; - Double sellAmount = tempDarray2[2]; - Double[] tempDArray = { - price, - buyAmount + 64, - sellAmount - }; - tempMap2.put(tempMap2Size - 1, tempDArray); - ConcurrentHashMap cMap = Main.maxBuyMap.get(player.getUniqueId()); - boolean notMax = true; - Integer max = (Integer)Main.getShopConfig().get("shops." + matClickedString + "." + "max-buy"); - if (max == null){ - max = 100000; - } - if ((cMap.get(matClickedString)+64) > max){ - notMax = false; - player.sendMessage(ChatColor.RED + "Maximum buys reached"); - } - if (hasAvaliableSlot(player) == true && Main.econ.getBalance(player) > (price*64) && notMax == true) { - Main.map.put(matClickedString, tempMap2); - Main.econ.withdrawPlayer(player, price * 64); - player.getInventory().addItem(new ItemStack(Material.matchMaterial(matClickedString), 64)); - sendPlayerShopMessageAndUpdateGDP(64, price, player, matClickedString, false); - } else { - player.sendMessage(ChatColor.RED + "Cannot purchase 64x " + matClickedString + " for " + ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(price * 64)); - } - player.setItemOnCursor(null); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - player.setItemOnCursor(null); - event.setCancelled(true); - } - }); - ItemStack iss1 = new ItemStack(Material.matchMaterial(matClickedString), 1); - ItemMeta iss1im = iss1.getItemMeta(); - iss1im.setDisplayName(ChatColor.GOLD + "Sell 1x " + ChatColor.AQUA + matClickedString); - iss1im.setLore(Arrays.asList(ChatColor.GREEN + Config.getCurrencySymbol() + df2.format((price - price * 0.01 * sellpricedif)))); - iss1.setItemMeta(iss1im); - ItemStack iss2 = new ItemStack(Material.matchMaterial(matClickedString), 2); - ItemMeta iss2im = iss2.getItemMeta(); - iss2im.setDisplayName(ChatColor.GOLD + "Sell 2x " + ChatColor.AQUA + matClickedString); - iss2im.setLore(Arrays.asList(ChatColor.GREEN + Config.getCurrencySymbol() + df2.format((price - price * 0.01 * sellpricedif) * 2))); - iss2.setItemMeta(iss2im); - ItemStack iss4 = new ItemStack(Material.matchMaterial(matClickedString), 4); - ItemMeta iss4im = iss4.getItemMeta(); - iss4im.setDisplayName(ChatColor.GOLD + "Sell 4x " + ChatColor.AQUA + matClickedString); - iss4im.setLore(Arrays.asList(ChatColor.GREEN + Config.getCurrencySymbol() + df2.format((price - price * 0.01 * sellpricedif) * 4))); - iss4.setItemMeta(iss4im); - ItemStack iss8 = new ItemStack(Material.matchMaterial(matClickedString), 8); - ItemMeta iss8im = iss8.getItemMeta(); - iss8im.setDisplayName(ChatColor.GOLD + "Sell 8x " + ChatColor.AQUA + matClickedString); - iss8im.setLore(Arrays.asList(ChatColor.GREEN + Config.getCurrencySymbol() + df2.format((price - price * 0.01 * sellpricedif) * 8))); - iss8.setItemMeta(iss8im); - ItemStack iss16 = new ItemStack(Material.matchMaterial(matClickedString), 16); - ItemMeta iss16im = iss16.getItemMeta(); - iss16im.setDisplayName(ChatColor.GOLD + "Sell 16x " + ChatColor.AQUA + matClickedString); - iss16im.setLore(Arrays.asList(ChatColor.GREEN + Config.getCurrencySymbol() + df2.format((price - price * 0.01 * sellpricedif) * 16))); - iss16.setItemMeta(iss16im); - ItemStack iss32 = new ItemStack(Material.matchMaterial(matClickedString), 32); - ItemMeta iss32im = iss32.getItemMeta(); - iss32im.setDisplayName(ChatColor.GOLD + "Sell 32x " + ChatColor.AQUA + matClickedString); - iss32im.setLore(Arrays.asList(ChatColor.GREEN + Config.getCurrencySymbol() + df2.format((price - price * 0.01 * sellpricedif) * 32))); - iss32.setItemMeta(iss32im); - ItemStack iss64 = new ItemStack(Material.matchMaterial(matClickedString), 64); - ItemMeta iss64im = iss64.getItemMeta(); - iss64im.setDisplayName(ChatColor.GOLD + "Sell 64x " + ChatColor.AQUA + matClickedString); - iss64im.setLore(Arrays.asList(ChatColor.GREEN + Config.getCurrencySymbol() + df2.format((price - price * 0.01 * sellpricedif) * 64))); - iss64.setItemMeta(iss64im); - GuiItem issa = new GuiItem(iss1, event -> { - Boolean sellable = false; - player.setItemOnCursor(null); - - if ((Player) event.getWhoClicked() == player && player.getInventory().contains(Material.matchMaterial(matClickedString), 1)) { - try { - player.getInventory().removeItem(new ItemStack(Material.matchMaterial(matClickedString), 1)); - sellable = true; - } catch (IllegalArgumentException e) { - player.sendMessage(ChatColor.RED + "No items present of that type in your inventory!"); - } - ConcurrentHashMap cMap = Main.maxSellMap.get(player.getUniqueId()); - boolean notMax = true; - Integer max = (Integer)Main.getShopConfig().get("shops." + matClickedString + "." + "max-sell"); - if (max == null){ - max = 100000; - } - if ((cMap.get(matClickedString)+1) > max){ - notMax = false; - player.sendMessage(ChatColor.RED + "Maximum sells reached"); - } - if (sellable != true || notMax == false) { - event.setCancelled(true); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - } - if (sellable == true && notMax == true) { - ConcurrentHashMap tempMap2 = Main.map.get(matClickedString); - Integer tempMap2Size = tempMap2.size(); - Double[] tempDarray2 = tempMap2.get(tempMap2Size - 1); - Double buyAmount = tempDarray2[1]; - Double sellAmount = tempDarray2[2]; - Double[] tempDArray = { - price, - buyAmount, - sellAmount + 1 - }; - tempMap2.put(tempMap2Size - 1, tempDArray); - Main.map.put(matClickedString, tempMap2); - - sendPlayerShopMessageAndUpdateGDP(1, (price - price * 0.01 * sellpricedif), player, matClickedString, true); - Main.econ.depositPlayer(player, (price - price * 0.01 * sellpricedif)); - sellable = false; - } - player.setItemOnCursor(null); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - event.setCancelled(true); - } else { - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - event.setCancelled(true); - } - }); - GuiItem issa2 = new GuiItem(iss2, event -> { - Boolean sellable = false; - player.setItemOnCursor(null); - - if ((Player) event.getWhoClicked() == player && player.getInventory().contains(Material.matchMaterial(matClickedString), 2)) { - try { - player.getInventory().removeItem(new ItemStack(Material.matchMaterial(matClickedString), 2)); - sellable = true; - } catch (IllegalArgumentException e) { - player.sendMessage(ChatColor.RED + "No items present of that type in your inventory!"); - } - ConcurrentHashMap cMap = Main.maxSellMap.get(player.getUniqueId()); - boolean notMax = true; - Integer max = (Integer)Main.getShopConfig().get("shops." + matClickedString + "." + "max-sell"); - if (max == null){ - max = 100000; - } - if ((cMap.get(matClickedString)+2) > max){ - notMax = false; - player.sendMessage(ChatColor.RED + "Maximum sells reached"); - } - if (sellable != true || notMax == false) { - player.setItemOnCursor(null); - event.setCancelled(true); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - } - if (sellable == true && notMax == true) { - ConcurrentHashMap tempMap2 = Main.map.get(matClickedString); - Integer tempMap2Size = tempMap2.size(); - Double[] tempDarray2 = tempMap2.get(tempMap2Size - 1); - Double buyAmount = tempDarray2[1]; - Double sellAmount = tempDarray2[2]; - Double[] tempDArray = { - price, - buyAmount, - sellAmount + 2 - }; - tempMap2.put(tempMap2Size - 1, tempDArray); - Main.map.put(matClickedString, tempMap2); - - sendPlayerShopMessageAndUpdateGDP(2, (price - price * 0.01 * sellpricedif), player, matClickedString, true); - Main.econ.depositPlayer(player, ((price - price * 0.01 * sellpricedif) * 2)); - sellable = false; - } - player.setItemOnCursor(null); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - event.setCancelled(true); - } else { - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - event.setCancelled(true); - } + main.update(); }); - GuiItem issa4 = new GuiItem(iss4, event -> { - Boolean sellable = false; - player.setItemOnCursor(null); - - if ((Player) event.getWhoClicked() == player && player.getInventory().contains(Material.matchMaterial(matClickedString), 4)) { - try { - player.getInventory().removeItem(new ItemStack(Material.matchMaterial(matClickedString), 4)); - sellable = true; - } catch (IllegalArgumentException e) { - player.sendMessage(ChatColor.RED + "No items present of that type in your inventory!"); - } - ConcurrentHashMap cMap = Main.maxSellMap.get(player.getUniqueId()); - boolean notMax = true; - Integer max = (Integer)Main.getShopConfig().get("shops." + matClickedString + "." + "max-sell"); - if (max == null){ - max = 100000; - } - if ((cMap.get(matClickedString)+4) > max){ - notMax = false; - player.sendMessage(ChatColor.RED + "Maximum sells reached"); - } - if (sellable != true || notMax == false) { - player.setItemOnCursor(null); - event.setCancelled(true); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - } - if (sellable == true && notMax == true) { - ConcurrentHashMap tempMap2 = Main.map.get(matClickedString); - Integer tempMap2Size = tempMap2.size(); - Double[] tempDarray2 = tempMap2.get(tempMap2Size - 1); - Double buyAmount = tempDarray2[1]; - Double sellAmount = tempDarray2[2]; - Double[] tempDArray = { - price, - buyAmount, - sellAmount + 4 - }; - tempMap2.put(tempMap2Size - 1, tempDArray); - Main.map.put(matClickedString, tempMap2); - - sendPlayerShopMessageAndUpdateGDP(4, (price - price * 0.01 * sellpricedif), player, matClickedString, true); - Main.econ.depositPlayer(player, ((price - price * 0.01 * sellpricedif) * 4)); - sellable = false; - } - player.setItemOnCursor(null); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - event.setCancelled(true); - } else { - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - event.setCancelled(true); - } - }); - GuiItem issa8 = new GuiItem(iss8, event -> { - Boolean sellable = false; - player.setItemOnCursor(null); - - if ((Player) event.getWhoClicked() == player && player.getInventory().contains(Material.matchMaterial(matClickedString), 8)) { - try { - player.getInventory().removeItem(new ItemStack(Material.matchMaterial(matClickedString), 8)); - sellable = true; - } catch (IllegalArgumentException e) { - player.sendMessage(ChatColor.RED + "No items present of that type in your inventory!"); - } - ConcurrentHashMap cMap = Main.maxSellMap.get(player.getUniqueId()); - boolean notMax = true; - Integer max = (Integer)Main.getShopConfig().get("shops." + matClickedString + "." + "max-sell"); - if (max == null){ - max = 100000; - } - if ((cMap.get(matClickedString)+8) > max){ - notMax = false; - player.sendMessage(ChatColor.RED + "Maximum sells reached"); - } - if (sellable != true || notMax == false) { - player.setItemOnCursor(null); - event.setCancelled(true); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - } - if (sellable == true && notMax == true) { - ConcurrentHashMap tempMap2 = Main.map.get(matClickedString); - Integer tempMap2Size = tempMap2.size(); - Double[] tempDarray2 = tempMap2.get(tempMap2Size - 1); - Double buyAmount = tempDarray2[1]; - Double sellAmount = tempDarray2[2]; - Double[] tempDArray = { - price, - buyAmount, - sellAmount + 8 - }; - tempMap2.put(tempMap2Size - 1, tempDArray); - Main.map.put(matClickedString, tempMap2); - - sendPlayerShopMessageAndUpdateGDP(8, (price - price * 0.01 * sellpricedif), player, matClickedString, true); - Main.econ.depositPlayer(player, ((price - price * 0.01 * sellpricedif) * 8)); - sellable = false; - } - player.setItemOnCursor(null); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - event.setCancelled(true); - } else { - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - event.setCancelled(true); - } - }); - GuiItem issa16 = new GuiItem(iss16, event -> { - Boolean sellable = false; - player.setItemOnCursor(null); - - if ((Player) event.getWhoClicked() == player && player.getInventory().contains(Material.matchMaterial(matClickedString), 16)) { - try { - player.getInventory().removeItem(new ItemStack(Material.matchMaterial(matClickedString), 16)); - sellable = true; - } catch (IllegalArgumentException e) { - player.sendMessage(ChatColor.RED + "No items present of that type in your inventory!"); - } - ConcurrentHashMap cMap = Main.maxSellMap.get(player.getUniqueId()); - boolean notMax = true; - Integer max = (Integer)Main.getShopConfig().get("shops." + matClickedString + "." + "max-sell"); - if (max == null){ - max = 100000; - } - if ((cMap.get(matClickedString)+16) > max){ - notMax = false; - player.sendMessage(ChatColor.RED + "Maximum sells reached"); - } - if (sellable != true || notMax == false) { - player.setItemOnCursor(null); - event.setCancelled(true); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - } - if (sellable == true && notMax == true) { - ConcurrentHashMap tempMap2 = Main.map.get(matClickedString); - Integer tempMap2Size = tempMap2.size(); - Double[] tempDarray2 = tempMap2.get(tempMap2Size - 1); - Double buyAmount = tempDarray2[1]; - Double sellAmount = tempDarray2[2]; - Double[] tempDArray = { - price, - buyAmount, - sellAmount + 16 - }; - tempMap2.put(tempMap2Size - 1, tempDArray); - Main.map.put(matClickedString, tempMap2); - - sendPlayerShopMessageAndUpdateGDP(16, (price - price * 0.01 * sellpricedif), player, matClickedString, true); - Main.econ.depositPlayer(player, ((price - price * 0.01 * sellpricedif) * 16)); - sellable = false; - } - player.setItemOnCursor(null); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - event.setCancelled(true); - } else { - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - event.setCancelled(true); - } - }); - GuiItem issa32 = new GuiItem(iss32, event -> { - Boolean sellable = false; - - player.setItemOnCursor(null); - if ((Player) event.getWhoClicked() == player && player.getInventory().contains(Material.matchMaterial(matClickedString), 32)) { - try { - player.getInventory().removeItem(new ItemStack(Material.matchMaterial(matClickedString), 32)); - sellable = true; - } catch (IllegalArgumentException e) { - player.sendMessage(ChatColor.RED + "No items present of that type in your inventory!"); - } - ConcurrentHashMap cMap = Main.maxSellMap.get(player.getUniqueId()); - boolean notMax = true; - Integer max = (Integer)Main.getShopConfig().get("shops." + matClickedString + "." + "max-sell"); - if (max == null){ - max = 100000; - } - if ((cMap.get(matClickedString)+32) > max){ - notMax = false; - player.sendMessage(ChatColor.RED + "Maximum sells reached"); - } - if (sellable != true || notMax == false) { - player.setItemOnCursor(null); - event.setCancelled(true); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - } - if (sellable == true && notMax == true) { - ConcurrentHashMap tempMap2 = Main.map.get(matClickedString); - Integer tempMap2Size = tempMap2.size(); - Double[] tempDarray2 = tempMap2.get(tempMap2Size - 1); - Double buyAmount = tempDarray2[1]; - Double sellAmount = tempDarray2[2]; - Double[] tempDArray = { - price, - buyAmount, - sellAmount + 32 - }; - tempMap2.put(tempMap2Size - 1, tempDArray); - Main.map.put(matClickedString, tempMap2); + output.addItem(gItem, 0, 0); + StaticPane[] realOut = {output, forward}; + return realOut; + } - sendPlayerShopMessageAndUpdateGDP(32, (price - price * 0.01 * sellpricedif), player, matClickedString, true); - Main.econ.depositPlayer(player, ((price - price * 0.01 * sellpricedif)) * 32); - sellable = false; - } - player.setItemOnCursor(null); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - event.setCancelled(true); - } else { - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - event.setCancelled(true); + public StaticPane loadForwardPane(PaginatedPane pPane, int lines, Gui main, StaticPane backPane){ + StaticPane output = new StaticPane(8, (lines), 1, 1); + ItemStack iStack = new ItemStack(Material.ARROW); + ItemMeta iMeta = iStack.getItemMeta(); + iMeta.setDisplayName(ChatColor.DARK_PURPLE + "Next"); + iMeta.setLore(Arrays.asList(ChatColor.GRAY + "Page " + ChatColor.WHITE + (pPane.getPage()+2))); + iStack.setItemMeta(iMeta); + GuiItem gItem = new GuiItem(iStack, event ->{ + event.setCancelled(true); + int page = pPane.getPage(); + int pages = pPane.getPages(); + pPane.setPage(page+1); + if (pPane.getPage() > (pages-2)){ + output.setVisible(false); } - }); - GuiItem issa64 = new GuiItem(iss64, event -> { - Boolean sellable = false; - player.setItemOnCursor(null); - if ((Player) event.getWhoClicked() == player && player.getInventory().contains(Material.matchMaterial(matClickedString), 64)) { - try { - player.getInventory().removeItem(new ItemStack(Material.matchMaterial(matClickedString), 64)); - sellable = true; - } catch (IllegalArgumentException e) { - player.sendMessage(ChatColor.RED + "No items present of that type in your inventory!"); - } - ConcurrentHashMap cMap = Main.maxSellMap.get(player.getUniqueId()); - boolean notMax = true; - Integer max = (Integer)Main.getShopConfig().get("shops." + matClickedString + "." + "max-sell"); - if (max == null){ - max = 100000; - } - if ((cMap.get(matClickedString)+64) > max){ - notMax = false; - player.sendMessage(ChatColor.RED + "Maximum sells reached"); - } - if (sellable != true || notMax == false) { - player.setItemOnCursor(null); - event.setCancelled(true); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - } - if (sellable == true && notMax == true) { - ConcurrentHashMap tempMap2 = Main.map.get(matClickedString); - Integer tempMap2Size = tempMap2.size(); - Double[] tempDarray2 = tempMap2.get(tempMap2Size - 1); - Double buyAmount = tempDarray2[1]; - Double sellAmount = tempDarray2[2]; - Double[] tempDArray = { - price, - buyAmount, - sellAmount + 64 - }; - tempMap2.put(tempMap2Size - 1, tempDArray); - Main.map.put(matClickedString, tempMap2); - - sendPlayerShopMessageAndUpdateGDP(64, (price - price * 0.01 * sellpricedif), player, matClickedString, true); - Main.econ.depositPlayer(player, ((price - price * 0.01 * sellpricedif)) * 64); - sellable = false; - } - player.setItemOnCursor(null); - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - event.setCancelled(true); - } else { - SBPane.clear(); - createTradingPanel(gui, matClickedString, player, SBPane, price, forward, back, showMainMenuButton); - event.setCancelled(true); + if (pPane.getPage() > page){ + backPane.setVisible(true); } + main.update(); }); - forward.setVisible(false); - back.setVisible(true); - SBPane.addItem(isa); - SBPane.addItem(isa2); - SBPane.addItem(isa4); - SBPane.addItem(isa8); - SBPane.addItem(isa16); - SBPane.addItem(isa32); - SBPane.addItem(isa64); - SBPane.addItem(issa); - SBPane.addItem(issa2); - SBPane.addItem(issa4); - SBPane.addItem(issa8); - SBPane.addItem(issa16); - SBPane.addItem(issa32); - SBPane.addItem(issa64); - gui.update(); - sellpricedif2 = null; + output.addItem(gItem, 0, 0); + return output; } - public boolean hasAvaliableSlot(Player player) { - InventoryView invview = player.getOpenInventory(); - Inventory inv = invview.getBottomInventory(); - Boolean check = true; - int a = inv.firstEmpty(); - if (a == -1) { - check = false; - return check; - } - return check; + public StaticPane loadMainMenuBackPane(PaginatedPane pPane){ + StaticPane output = new StaticPane(0, 0, 1, 1); + ItemStack iStack = new ItemStack(Material.ARROW); + ItemMeta iMeta = iStack.getItemMeta(); + iMeta.setDisplayName(ChatColor.DARK_PURPLE + "Main Menu"); + iMeta.setLore(Arrays.asList(ChatColor.GRAY + "Click to go to " + ChatColor.WHITE + "Main Menu")); + iStack.setItemMeta(iMeta); + GuiItem gItem = new GuiItem(iStack, event ->{ + event.setCancelled(true); + Player player = (Player) event.getWhoClicked(); + player.getOpenInventory().close(); + loadGUISECTIONS(player); + }); + output.addItem(gItem, 0, 0); + return output; } - public static void sendPlayerShopMessageAndUpdateGDP(int amount, double price, Player player, String matClickedString, boolean sell){ + public static void sendPlayerShopMessageAndUpdateGDP(int amount, Player player, String matClickedString, boolean sell){ if (!sell){ ConcurrentHashMap cMap = Main.maxBuyMap.get(player.getUniqueId()); cMap.put(matClickedString, (cMap.get(matClickedString)+amount)); Main.maxBuyMap.put(player.getUniqueId(), cMap); - Main.tempdatadata.put("GDP", (Main.tempdatadata.get("GDP")+(price*amount))); - player.sendMessage(ChatColor.GOLD + "Purchased " + amount + "x " + matClickedString + " for " + ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(price*amount)); + ConcurrentHashMap inputMap = Main.map.get(matClickedString); + 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))); + player.getInventory().addItem(new ItemStack(Material.matchMaterial(matClickedString), amount)); + inputMap.put((inputMap.size()-1), outputArr); + Main.map.put(matClickedString, inputMap); + Main.getEconomy().withdrawPlayer(player, (arr[0]*amount)); + player.sendMessage(ChatColor.GOLD + "Purchased " + amount + "x " + matClickedString + " for " + ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(arr[0]*amount)); } else if (sell){ ConcurrentHashMap cMap = Main.maxSellMap.get(player.getUniqueId()); cMap.put(matClickedString, (cMap.get(matClickedString)+amount)); Main.maxSellMap.put(player.getUniqueId(), cMap); - Main.tempdatadata.put("GDP", (Main.tempdatadata.get("GDP")+(price*amount))); - player.sendMessage(ChatColor.GOLD + "Sold " + amount + "x " + matClickedString + " for " + ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(price*amount)); + ConcurrentHashMap inputMap = Main.map.get(matClickedString); + Double[] arr = inputMap.get(inputMap.size()-1); + Double[] outputArr = {arr[0], arr[1], (arr[2]+amount)}; + Main.tempdatadata.put("GDP", (Main.tempdatadata.get("GDP")+(arr[0]*amount))); + inputMap.put((inputMap.size()-1), outputArr); + Main.map.put(matClickedString, inputMap); + Main.getEconomy().depositPlayer(player, (arr[0]*amount)); + player.sendMessage(ChatColor.GOLD + "Sold " + amount + "x " + matClickedString + " for " + ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(arr[0]*amount)); } } - } \ No newline at end of file diff --git a/Auto-Tune/src/unprotesting/com/github/util/Section.java b/Auto-Tune/src/unprotesting/com/github/util/Section.java index 13b53f9..7d7077e 100644 --- a/Auto-Tune/src/unprotesting/com/github/util/Section.java +++ b/Auto-Tune/src/unprotesting/com/github/util/Section.java @@ -2,6 +2,8 @@ import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + import org.bukkit.Material; import unprotesting.com.github.Main; @@ -12,6 +14,7 @@ public class Section { public String name; public Material image = Material.matchMaterial("GRASS_BLOCK"); public boolean showBackButton = true; + public ConcurrentHashMap itemMaxBuySell = new ConcurrentHashMap(); public Section(String name){ this.name = name; @@ -36,6 +39,47 @@ public Section(String name){ Main.log("Shop " + shop + " doesn't have a section, please input one to continue"); } } + for (String item : items){ + Integer maxBuy = 100000; + Integer maxSell = 100000; + Integer test = 0; + try{ + maxBuy = Main.getShopConfig().getConfigurationSection("shops." + item).getInt("max-buy"); + test = maxBuy; + } + catch(NullPointerException ex){ + maxBuy = 100000; + } + catch(NumberFormatException ex){ + try{ + maxBuy = (int)Main.getShopConfig().getConfigurationSection("shops." + item).getDouble("max-buy"); + test = maxBuy; + } + catch (NumberFormatException ex2){ + maxSell = 100000; + Main.log("Can't format " + item + " for max-buy"); + } + } + try{ + maxSell = Main.getShopConfig().getConfigurationSection("shops." + item).getInt("max-sell"); + test = maxSell; + } + catch(NullPointerException ex){ + maxSell = 100000; + } + catch(NumberFormatException ex){ + try{ + maxSell = (int)Main.getShopConfig().getConfigurationSection("shops." + item).getDouble("max-sell"); + test = maxSell; + } + catch (NumberFormatException ex2){ + maxSell = 100000; + Main.log("Can't format " + item + " for max-sell"); + } + } + Integer[] outputIntegerArray = {maxBuy, maxSell}; + itemMaxBuySell.put(item, outputIntegerArray); + } } } } diff --git a/README.md b/README.md index 0787978..ead0184 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ An example of a shop setup using Auto-Tune: #### To use Auto-Tune - Note: Make sure you have a valid API key - - 1. Download the latest version of Auto-Tune from the resources tab for your Minecraft server's Minecraft version - Make sure the dependencies are also installed (Vault[https://www.spigotmc.org/resources/vault.34315/] and Essentials[https://essentialsx.net]) + - 1. Download the latest version of Auto-Tune from the resources tab for your Minecraft server's Minecraft version - Make sure the dependencies are also installed (Vault - [https://www.spigotmc.org/resources/vault.34315/] and Essentials - [https://essentialsx.net]) - 2. Put the .jar file in your minecraft plugins folder - 3. Restart your server - 4. Edit the config.yml file inside plugins/Auto-Tune/, and enter your API key and email (check Auto-Tune API for more) From 497f2547e65db4d678f917f2d9f407ca965eeced Mon Sep 17 00:00:00 2001 From: "Noah Clarkson (Unprotesting)" Date: Thu, 26 Nov 2020 21:58:43 +0000 Subject: [PATCH 2/9] Expanded the shop details and fixed a multitude of bugs + Added a way to view price change over time + Fixed some more bugs --- .../Commands/AutoTuneGUIShopUserCommand.java | 141 +++++++++++++++--- 1 file changed, 117 insertions(+), 24 deletions(-) diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java index f46d2bf..786ff1e 100644 --- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java +++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java @@ -1,5 +1,6 @@ package unprotesting.com.github.Commands; +import java.math.BigDecimal; import java.text.DecimalFormat; import java.util.Arrays; import java.util.HashMap; @@ -15,6 +16,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -144,7 +146,7 @@ public void loadGUIMAIN(Player player, Section sec, boolean twoArgs) { if (event.getClick() == ClickType.LEFT){ event.setCancelled(true); player.getOpenInventory().close(); - loadGUITRADING(player, itemName); + loadGUITRADING(player, itemName, sec); } else{ event.setCancelled(true); @@ -177,7 +179,7 @@ public void loadGUIMAIN(Player player, Section sec, boolean twoArgs) { main.show((HumanEntity) cSender); } - public void loadGUITRADING(Player player, String itemName){ + public void loadGUITRADING(Player player, String itemName, Section sec){ Gui main = new Gui(4, Config.getMenuTitle()); OutlinePane front = new OutlinePane(1, 1, 7, 2); for (int i = 0; i < 14; i++){ @@ -188,16 +190,32 @@ public void loadGUITRADING(Player player, String itemName){ iStack = loadTradingItem(itemName, amounts[i], true); gItem = new GuiItem(iStack, event ->{ event.setCancelled(true); - try { - HashMap unableItems = player.getInventory().addItem(new ItemStack(Material.matchMaterial(itemName), amounts[finalI])); - if (unableItems.size() > 0){ - player.sendMessage(ChatColor.BOLD + "Cant sell " + Integer.toString(amounts[finalI]) + "x of " + itemName); - } - else{ - sendPlayerShopMessageAndUpdateGDP(amounts[finalI], player, itemName, false); + ConcurrentHashMap maxBuyMapRec = Main.maxBuyMap.get(player.getUniqueId()); + int currentMax = maxBuyMapRec.get(itemName); + Integer[] max = sec.itemMaxBuySell.get(itemName); + if (max[0] < (currentMax+amounts[finalI])){ + player.sendMessage(ChatColor.BOLD + "Cant Purchase " + Integer.toString(amounts[finalI]) + "x of " + itemName); + int difference = (currentMax+amounts[finalI]) - max[0]; + Main.log("difference: " + difference); + if (difference != 0 && currentMax != max[0]){ + sendPlayerShopMessageAndUpdateGDP(difference, player, itemName, false); + Main.maxBuyMap.put(player.getUniqueId(), maxBuyMapRec); } + player.sendMessage(ChatColor.RED + "Max Buys Reached! - " + max[0] + "/" + max[0]); + } - catch(IllegalArgumentException ex){ + else{ + try { + HashMap unableItems = player.getInventory().addItem(new ItemStack(Material.matchMaterial(itemName), amounts[finalI])); + if (unableItems.size() > 0){ + player.sendMessage(ChatColor.BOLD + "Cant Purchase " + Integer.toString(amounts[finalI]) + "x of " + itemName); + } + else{ + sendPlayerShopMessageAndUpdateGDP(amounts[finalI], player, itemName, false); + } + } + catch(IllegalArgumentException ex){ + } } }); } @@ -205,50 +223,92 @@ public void loadGUITRADING(Player player, String itemName){ iStack = loadTradingItem(itemName, amounts[i-7], false); gItem = new GuiItem(iStack, event ->{ event.setCancelled(true); - try { - HashMap takenItems = player.getInventory().removeItem(new ItemStack(Material.matchMaterial(itemName), amounts[finalI])); - if (takenItems.size() > 0){ - player.sendMessage(ChatColor.BOLD + "Cant sell " + Integer.toString(amounts[finalI]) + "x of " + itemName); - } - else{ - sendPlayerShopMessageAndUpdateGDP(amounts[finalI-8], player, itemName, true); + ConcurrentHashMap maxSellMapRec = Main.maxSellMap.get(player.getUniqueId()); + int currentMax = maxSellMapRec.get(itemName); + Integer[] max = sec.itemMaxBuySell.get(itemName); + 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]; + if (!(difference < 1)){ + sendPlayerShopMessageAndUpdateGDP((difference), player, itemName, true); } } - catch(IllegalArgumentException ex){ + else{ + removeItems(player, (finalI-7), itemName); } }); } front.addItem(gItem); } main.addPane(front); + main.addPane(loadReturnButton(sec)); CommandSender cSender = player; main.update(); main.show((HumanEntity) cSender); } + public void removeItems(Player player, int finalI, String itemName){ + try { + HashMap takenItems = player.getInventory().removeItem(new ItemStack(Material.matchMaterial(itemName), amounts[finalI])); + if (takenItems.size() > 0){ + player.sendMessage(ChatColor.BOLD + "Cant sell " + Integer.toString(amounts[finalI]) + "x of " + itemName); + } + else{ + sendPlayerShopMessageAndUpdateGDP(amounts[finalI], player, itemName, true); + } + } + catch(IllegalArgumentException ex){ + } + } + public ItemStack loadShopItem(String itemName, Section sec){ ItemStack iStack = new ItemStack(Material.matchMaterial(itemName)); ItemMeta iMeta = iStack.getItemMeta(); Integer[] maxBuySellForItem = sec.itemMaxBuySell.get(itemName); iMeta.setDisplayName(ChatColor.GOLD + itemName); iMeta.setLore(Arrays.asList((ChatColor.GRAY + "Click to purchase/sell"), + (loadPriceDisplay(itemName)), (ChatColor.WHITE + "Max Buys: " + maxBuySellForItem[0] + " per " + Config.getTimePeriod() + "min"), (ChatColor.WHITE + "Max Sells: " + maxBuySellForItem[1] + " per " + Config.getTimePeriod() + "min"))); iStack.setItemMeta(iMeta); return iStack; } + public String loadPriceDisplay(String item){ + double currentPrice = getItemPrice(item, false); + float timePeriod = (float) Config.getTimePeriod(); + float timePeriodsInADay = (float)(1/(timePeriod/1440)); + ConcurrentHashMap newMap = Main.map.get(item); + if (newMap.size() <= timePeriodsInADay){ + return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.BLACK + " - " + ChatColor.GRAY + "%0.0"); + } + Integer oneDayOldTP = (int) Math.floor(newMap.size() - timePeriodsInADay); + Double[] arr = newMap.get(oneDayOldTP); + double oneDayOldPrice = arr[0]; + if (oneDayOldPrice > currentPrice){ + double percent = 100*((currentPrice/oneDayOldPrice)-1); + return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.BLACK + " - " + ChatColor.RED + "%-" + df2.format(Math.abs(percent))); + } + else if (oneDayOldPrice < currentPrice){ + double percent = 100*(1-(oneDayOldPrice/currentPrice)); + return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.BLACK + " - " + ChatColor.GREEN + "%+" + df2.format(Math.abs(percent))); + } + else{ + return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.BLACK + " - " + ChatColor.GRAY + "%0.0"); + } + } + public ItemStack loadTradingItem(String itemName, int number, boolean buy){ - ItemStack iStack = new ItemStack(Material.matchMaterial(itemName)); + ItemStack iStack = new ItemStack(Material.matchMaterial(itemName), number); ItemMeta iMeta = iStack.getItemMeta(); iMeta.setDisplayName(ChatColor.GOLD + itemName); if (buy){ - iMeta.setLore(Arrays.asList((ChatColor.WHITE + "$" + df2.format(getItemPrice(itemName)*number)), + iMeta.setLore(Arrays.asList((ChatColor.WHITE + "$" + df2.format(getItemPrice(itemName, false)*number)), (ChatColor.GRAY + "Purchase " + number + "x "))); iStack.setItemMeta(iMeta); } if (!buy){ - iMeta.setLore(Arrays.asList((ChatColor.WHITE + "$" + df2.format(getItemPrice(itemName)*number)), + iMeta.setLore(Arrays.asList((ChatColor.WHITE + "$" + df2.format(getItemPrice(itemName, true)*number)), (ChatColor.GRAY + "Sell " + number + "x "))); iStack.setItemMeta(iMeta); } @@ -267,10 +327,44 @@ public boolean hasAvaliableSlot(Player player) { return check; } - public Double getItemPrice(String item){ + public double getSellPriceDifference(String item){ + double output = Config.getSellPriceDifference(); + try{ + ConfigurationSection config = Main.getShopConfig().getConfigurationSection("shops").getConfigurationSection((item)); + output = config.getDouble("sell-difference", output); + return output; + } + catch(NullPointerException ex){ + output = Config.getSellPriceDifference(); + } + return output; + } + + public Double getItemPrice(String item, boolean sell){ ConcurrentHashMap inputMap = Main.map.get(item); Double[] arr = inputMap.get(inputMap.size()-1); - return arr[0]; + if (!sell){ + return arr[0]; + } + else{ + return getSellPriceDifference(item); + } + } + + public StaticPane loadReturnButton(Section sec){ + StaticPane output = new StaticPane(0, 0, 1, 1); + ItemStack iStack = new ItemStack(Material.ARROW); + ItemMeta iMeta = iStack.getItemMeta(); + iMeta.setDisplayName(ChatColor.DARK_PURPLE + sec.name); + iMeta.setLore(Arrays.asList(ChatColor.GRAY + "Click to go to " + ChatColor.WHITE + sec.name)); + iStack.setItemMeta(iMeta); + GuiItem gItem = new GuiItem(iStack, event ->{ + Player player = (Player) event.getWhoClicked(); + player.getOpenInventory().close(); + loadGUIMAIN(player, sec, false); + }); + output.addItem(gItem, 0, 0); + return output; } public StaticPane[] loadPagePanes(PaginatedPane pPane, int lines, Gui main){ @@ -347,7 +441,6 @@ 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))); - player.getInventory().addItem(new ItemStack(Material.matchMaterial(matClickedString), amount)); inputMap.put((inputMap.size()-1), outputArr); Main.map.put(matClickedString, inputMap); Main.getEconomy().withdrawPlayer(player, (arr[0]*amount)); From ccf8a85640d7cba96f908ac352c92a66d50582ed Mon Sep 17 00:00:00 2001 From: "Noah Clarkson (Unprotesting)" Date: Sat, 28 Nov 2020 09:40:36 +0000 Subject: [PATCH 3/9] Fixed max-sells and max-buys + Fixed max-sells and max-buys and a few other bugs --- Auto-Tune/src/resources/plugin.yml | 3 --- .../Commands/AutoTuneGUIShopUserCommand.java | 19 ++++++++----------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Auto-Tune/src/resources/plugin.yml b/Auto-Tune/src/resources/plugin.yml index b75f4d8..1925f0b 100644 --- a/Auto-Tune/src/resources/plugin.yml +++ b/Auto-Tune/src/resources/plugin.yml @@ -30,9 +30,6 @@ commands: sell: description: Sell items quickly to the shop. usage: / - atadmin: - description: Auto-Tune Admin Command. - usage: / autosell: description: Auto-Tune Auto Sell Command usage: / diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java index 786ff1e..2f64474 100644 --- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java +++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java @@ -1,6 +1,5 @@ package unprotesting.com.github.Commands; -import java.math.BigDecimal; import java.text.DecimalFormat; import java.util.Arrays; import java.util.HashMap; @@ -125,15 +124,12 @@ else if (event.getClick() != ClickType.LEFT) { public void loadGUIMAIN(Player player, Section sec, boolean twoArgs) { int itemAmount = sec.items.size(); int lines = (int)Math.floor(((itemAmount-1)/7)+1); - Main.log("Lines: " + lines); if (lines > 4){ lines = 4; } Gui main = new Gui((lines+2), Config.getMenuTitle()); Integer paneSize = (lines+1)*7; Integer paneAmount = (int) Math.ceil(itemAmount/paneSize)+1; - Main.log("Pane Amount: " + paneAmount); - Main.log("Pane Size: " + paneSize); PaginatedPane pPane = new PaginatedPane(0, 0, 9, (lines+2)); OutlinePane[] shopPanes = new OutlinePane[paneAmount]; for (int i = 0; i < shopPanes.length; i++){ @@ -196,8 +192,7 @@ public void loadGUITRADING(Player player, String itemName, Section sec){ if (max[0] < (currentMax+amounts[finalI])){ player.sendMessage(ChatColor.BOLD + "Cant Purchase " + Integer.toString(amounts[finalI]) + "x of " + itemName); int difference = (currentMax+amounts[finalI]) - max[0]; - Main.log("difference: " + difference); - if (difference != 0 && currentMax != max[0]){ + if (difference != 0 && !(currentMax >= max[0])){ sendPlayerShopMessageAndUpdateGDP(difference, player, itemName, false); Main.maxBuyMap.put(player.getUniqueId(), maxBuyMapRec); } @@ -229,9 +224,11 @@ public void loadGUITRADING(Player player, String itemName, Section sec){ 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]; - if (!(difference < 1)){ + if (difference != 0 && !(currentMax >= max[1])){ sendPlayerShopMessageAndUpdateGDP((difference), player, itemName, true); + Main.maxSellMap.put(player.getUniqueId(), maxSellMapRec); } + player.sendMessage(ChatColor.RED + "Max Sells Reached! - " + max[1] + "/" + max[1]); } else{ removeItems(player, (finalI-7), itemName); @@ -280,21 +277,21 @@ public String loadPriceDisplay(String item){ float timePeriodsInADay = (float)(1/(timePeriod/1440)); ConcurrentHashMap newMap = Main.map.get(item); if (newMap.size() <= timePeriodsInADay){ - return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.BLACK + " - " + ChatColor.GRAY + "%0.0"); + return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.DARK_GRAY + " - " + ChatColor.GRAY + "%0.0"); } Integer oneDayOldTP = (int) Math.floor(newMap.size() - timePeriodsInADay); Double[] arr = newMap.get(oneDayOldTP); double oneDayOldPrice = arr[0]; if (oneDayOldPrice > currentPrice){ double percent = 100*((currentPrice/oneDayOldPrice)-1); - return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.BLACK + " - " + ChatColor.RED + "%-" + df2.format(Math.abs(percent))); + return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.DARK_GRAY + " - " + ChatColor.RED + "%-" + df2.format(Math.abs(percent))); } else if (oneDayOldPrice < currentPrice){ double percent = 100*(1-(oneDayOldPrice/currentPrice)); - return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.BLACK + " - " + ChatColor.GREEN + "%+" + df2.format(Math.abs(percent))); + return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "%+" + df2.format(Math.abs(percent))); } else{ - return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.BLACK + " - " + ChatColor.GRAY + "%0.0"); + return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.DARK_GRAY + " - " + ChatColor.GRAY + "%0.0"); } } From 259dee041c5393f57bf5ec0cb39298f1535fdb93 Mon Sep 17 00:00:00 2001 From: "Noah Clarkson (Unprotesting)" Date: Wed, 2 Dec 2020 17:22:12 +0000 Subject: [PATCH 4/9] LOADS of features, bug fixes and optimizations. + Enchantments, shop improvements and more! --- Auto-Tune/dependency-reduced-pom.xml | 1 + Auto-Tune/pom.xml | 1 + Auto-Tune/src/resources/enchantments.yml | 162 +++++++++++ Auto-Tune/src/resources/plugin.yml | 5 + Auto-Tune/src/resources/shops.yml | 6 + .../github/Commands/AutoTuneBuyCommand.java | 99 +++++++ .../Commands/AutoTuneGUIShopUserCommand.java | 265 ++++++++++-------- .../github/Commands/AutoTuneSellCommand.java | 4 +- .../src/unprotesting/com/github/Main.java | 44 ++- .../com/github/util/EnchantmentAlgorithm.java | 121 ++++++++ .../github/util/EnchantmentPriceHandler.java | 31 ++ .../com/github/util/EnchantmentSetting.java | 22 ++ .../unprotesting/com/github/util/Section.java | 5 + Auto-Tune/target/classes/enchantments.yml | 162 +++++++++++ 14 files changed, 805 insertions(+), 123 deletions(-) create mode 100644 Auto-Tune/src/resources/enchantments.yml create mode 100644 Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java create mode 100644 Auto-Tune/src/unprotesting/com/github/util/EnchantmentAlgorithm.java create mode 100644 Auto-Tune/src/unprotesting/com/github/util/EnchantmentPriceHandler.java create mode 100644 Auto-Tune/src/unprotesting/com/github/util/EnchantmentSetting.java create mode 100644 Auto-Tune/target/classes/enchantments.yml diff --git a/Auto-Tune/dependency-reduced-pom.xml b/Auto-Tune/dependency-reduced-pom.xml index cccd2c7..8a4bcf5 100644 --- a/Auto-Tune/dependency-reduced-pom.xml +++ b/Auto-Tune/dependency-reduced-pom.xml @@ -26,6 +26,7 @@ plugin.yml config.yml shops.yml + enchantments.yml web/trade.html web/trade-short.html diff --git a/Auto-Tune/pom.xml b/Auto-Tune/pom.xml index 8c6b846..842a1b5 100644 --- a/Auto-Tune/pom.xml +++ b/Auto-Tune/pom.xml @@ -104,6 +104,7 @@ plugin.yml config.yml shops.yml + enchantments.yml web/trade.html web/trade-short.html diff --git a/Auto-Tune/src/resources/enchantments.yml b/Auto-Tune/src/resources/enchantments.yml new file mode 100644 index 0000000..71c56db --- /dev/null +++ b/Auto-Tune/src/resources/enchantments.yml @@ -0,0 +1,162 @@ + +# ░█████╗░██╗░░░██╗████████╗░█████╗░░░░░░░████████╗██╗░░░██╗███╗░░██╗███████╗ +# ██╔══██╗██║░░░██║╚══██╔══╝██╔══██╗░░░░░░╚══██╔══╝██║░░░██║████╗░██║██╔════╝ +# ███████║██║░░░██║░░░██║░░░██║░░██║█████╗░░░██║░░░██║░░░██║██╔██╗██║█████╗░░ +# ██╔══██║██║░░░██║░░░██║░░░██║░░██║╚════╝░░░██║░░░██║░░░██║██║╚████║██╔══╝░░ +# ██║░░██║╚██████╔╝░░░██║░░░╚█████╔╝░░░░░░░░░██║░░░╚██████╔╝██║░╚███║███████╗ +# ╚═╝░░╚═╝░╚═════╝░░░░╚═╝░░░░╚════╝░░░░░░░░░░╚═╝░░░░╚═════╝░╚═╝░░╚══╝╚══════╝ + +enchantments: + ARROW_DAMAGE: + price: 600.00 ## <- An added price for buying/selling an item with this enchantment + ratio: 0.6 ## <- Another added percentage of the item bought/sold with this enchantment + ## Info: An item worth usually 100 will cost (100*1.6)+600=760 + ## Provides extra damage when shooting arrows from bows + ARROW_FIRE: + price: 750.00 + ratio: 0.8 + ## Sets entities on fire when hit by arrows shot from a bow + ARROW_INFINITE: + price: 1500.00 + ratio: 1.2 + ## Provides infinite arrows when shooting a bow + ARROW_KNOCKBACK: + price: 900.00 + ratio: 0.75 + ## Provides a knockback when an entity is hit by an arrow from a bow + BINDING_CURSE: + price: 80.00 + ratio: 0.1 + ## Item cannot be removed + CHANNELING: + price: 600.00 + ratio: 1.0 + ## Strikes lightning when a mob is hit with a trident if conditions are stormy + DAMAGE_ALL: + price: 750.00 + ratio: 0.8 + ## Increases damage against all targets + DAMAGE_ARTHROPODS: + price: 700.00 + ratio: 0.85 + ## Increases damage against arthropod targets + DAMAGE_UNDEAD: + price: 700.00 + ratio: 0.85 + ## Increases damage against undead targets + DEPTH_STRIDER: + price: 900.00 + ratio: 0.8 + ## Increases walking speed while in water + DIG_SPEED: + price: 850.00 + ratio: 0.75 + ## Increases the rate at which you mine/dig + DURABILITY: + price: 850.00 + ratio: 0.85 + ## Decreases the rate at which a tool looses durability + FIRE_ASPECT: + price: 1000.00 + ratio: 0.9 + ## When attacking a target, has a chance to set them on fire + FROST_WALKER: + price: 1100.00 + ratio: 1.0 + ## Freezes any still water adjacent to ice / frost which player is walking on + IMPALING: + price: 650.00 + ratio: 0.8 + ## Deals more damage to mobs that live in the ocean + KNOCKBACK: + price: 975.00 + ratio: 0.8 + ## All damage to other targets will knock them back when hit + LOOT_BONUS_BLOCKS: + price: 1250.00 + ratio: 1.45 + ## Provides a chance of gaining extra loot when destroying blocks + LOOT_BONUS_MOBS: + price: 1200.00 + ratio: 1.35 + ## Provides a chance of gaining extra loot when killing monsters + LOYALTY: + price: 1100.00 + ratio: 0.8 + ## Causes a thrown trident to return to the player who threw it + LUCK: + price: 750.00 + ratio: 1.2 + ## Decreases odds of catching worthless junk + LURE: + price: 550.00 + ratio: 0.5 + ## Increases rate of fish biting your hook + MENDING: + price: 4000.00 + ratio: 2.25 + ## Allows mending the item using experience orbs + MULTISHOT: + price: 800.00 + ratio: 0.8 + ## Shoot multiple arrows from crossbows + OXYGEN: + price: 600.00 + ratio: 0.7 + ## Decreases the rate of air loss whilst underwater + PIERCING: + price: 750.00 + ratio: 0.8 + ## Crossbow projectiles pierce entities + PROTECTION_ENVIRONMENTAL: + price: 900.00 + ratio: 0.8 + ## Provides protection against environmental damage + PROTECTION_EXPLOSIONS: + price: 950.00 + ratio: 0.85 + ## Provides protection against explosive damage + PROTECTION_FALL: + price: 950.00 + ratio: 0.85 + ## Provides protection against fall damage + PROTECTION_FIRE: + price: 950.00 + ratio: 0.8 + ## Provides protection against fire damage + PROTECTION_PROJECTILE: + price: 950.00 + ratio: 0.85 + ## Provides protection against projectile damage + QUICK_CHARGE: + price: 800.00 + ratio: 0.85 + ## Charges crossbows quickly + RIPTIDE: + price: 1050.00 + ratio: 0.8 + ## When it is rainy, launches the player in the direction their trident is thrown + SILK_TOUCH: + price: 1300.00 + ratio: 1.2 + ## Allows blocks to drop themselves instead of fragments (for example, stone instead of cobblestone) + SOUL_SPEED: + price: 1450.00 + ratio: 1.5 + ## Walk quicker on soul blocks + SWEEPING_EDGE: + price: 1900.00 + ratio: 0.9 + ## Increases damage against targets when using a sweep attack + THORNS: + price: 1600.00 + ratio: 1.25 + ## Damages the attacker + VANISHING_CURSE: + price: 50.00 + ratio: 0.3 + ## Item disappears instead of dropping + WATER_WORKER: + price: 800.00 + ratio: 0.85 + ## Increases the speed at which a player may mine underwater \ No newline at end of file diff --git a/Auto-Tune/src/resources/plugin.yml b/Auto-Tune/src/resources/plugin.yml index 1925f0b..fdd0c19 100644 --- a/Auto-Tune/src/resources/plugin.yml +++ b/Auto-Tune/src/resources/plugin.yml @@ -47,6 +47,8 @@ commands: usage: atconfig: description: View and change plugin config settings + buy: + description: Buy items not available in the shop permssions: at.help: description: Displays Auto-Tune help information @@ -81,6 +83,9 @@ permssions: at.tutorial: description: Allow players to view tutorial messages default: true + at.buy: + description: Allow players to purchase custom items + default: true diff --git a/Auto-Tune/src/resources/shops.yml b/Auto-Tune/src/resources/shops.yml index 0d8d97d..33a65b1 100644 --- a/Auto-Tune/src/resources/shops.yml +++ b/Auto-Tune/src/resources/shops.yml @@ -20,11 +20,14 @@ ## Info: Make sure you put a decimal point and two digits to create a double for the shop algorithim to accept and parse to a price-value ## Info: Most of these values will be almost useless once the economy has started, to use these values again delete the data.db file ## Info: Material names are available here: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html +## Info: To remove an item use /at remove to remove it from the global map ## Options: 'price: ' set the defualt starting price of the item ## Options: 'locked: ' set the price to be locked or variable (variable by default). ## Options: 'sell-difference: ' set a custom sell-price-difference (default set in config). ## Options: 'max-buy': set a maximum quantity that can be purchased in a time-period ## Options: 'max-sell': set a maximum quantity that can be sold in a time-period +## Options: 'enchantment': set an items enchantment +## Options: 'enchantment': set an items enchantment level ## Example: @@ -34,6 +37,8 @@ ## sell-difference: 0.0 <- Example of a set sell-difference item ## max-buy: 10 <- Only 10 items can be bought each time-period - you can increase this on large servers ## max-sell: 12 <- Only 12 items can be sold each time-period - you can increase this on large servers + ## enchantment: 'DAMAGE_ALL' <- Example of set enchanted item - Note: Enchantment price calculation must be turned off! + ## enchantment-level: 1 <- Enchantment level, look above shops: COAL: @@ -656,6 +661,7 @@ shops: max-buy: 32 max-sell: 48 section: 'Other' + ## Shop sections configuration sections: 'Natural Resources': diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java new file mode 100644 index 0000000..dfc4f61 --- /dev/null +++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java @@ -0,0 +1,99 @@ +package unprotesting.com.github.Commands; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import unprotesting.com.github.Main; +import unprotesting.com.github.util.Config; +import unprotesting.com.github.util.EnchantmentAlgorithm; +import unprotesting.com.github.util.EnchantmentSetting; + +public class AutoTuneBuyCommand implements CommandExecutor { + + public static List shopTypes = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + if (sender instanceof Player){ + Player player = (Player) sender; + 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; + } + } + 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() + setting.price + " | Item Multiplier: " + setting.ratio + "x"); + } + return true; + } + else{ + player.sendMessage("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(); + if (is != null){ + Enchantment ench = Enchantment.getByName(setting.name); + try{ + is.addEnchantment(ench, 1); + } + catch(IllegalArgumentException ex){ + player.sendMessage(ChatColor.RED + "Cannot enchant item: " + is.getType().toString() + " with enchantment " + setting.name); + ex.printStackTrace(); + return true; + } + double price = EnchantmentAlgorithm.calculatePriceWithEnch(is); + 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[1] == null){ + arr[1] = 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; + } + 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{ + Main.sendMessage(sender, "&cPlayers only."); + return true; + } + return false; + } + +} diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java index 2f64474..0fe4b63 100644 --- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java +++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java @@ -16,6 +16,7 @@ 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.ClickType; @@ -40,7 +41,7 @@ public class AutoTuneGUIShopUserCommand implements CommandExecutor { public static Integer SBPanePos = 1; - public static Integer[] amounts = {1, 2, 4, 8, 16, 32, 64}; + public static Integer[] amounts = { 1, 2, 4, 8, 16, 32, 64 }; @Override public boolean onCommand(CommandSender sender, Command command, String shop, String[] args) { @@ -53,62 +54,59 @@ public boolean onCommand(CommandSender sender, Command command, String shop, Str if (Config.getMenuRows() == 6) { SBPanePos = 2; } - if (args.length == 0){ - if (p.hasPermission("at.shop") || p.isOp()) - { + if (args.length == 0) { + if (p.hasPermission("at.shop") || p.isOp()) { loadGUISECTIONS(p); + } else if (!(p.hasPermission("at.shop")) && !(p.isOp())) { + TextHandler.noPermssion(p); } - else if (!(p.hasPermission("at.shop")) && !(p.isOp())){TextHandler.noPermssion(p);} return true; } - if (args.length == 1){ + if (args.length == 1) { String inputSection = null; - try{ + try { inputSection = args[0]; - } - catch(ClassCastException ex){ + } catch (ClassCastException ex) { p.sendMessage("Unknown shop format: " + args[0]); return false; - } - catch(ArrayIndexOutOfBoundsException ex){ + } catch (ArrayIndexOutOfBoundsException ex) { return false; } - for (int i = 0; i < Main.sectionedItems.length; i++){ - if (Main.sectionedItems[i].name.toLowerCase().equals(inputSection)){ + for (int i = 0; i < Main.sectionedItems.length; i++) { + if (Main.sectionedItems[i].name.toLowerCase().equals(inputSection)) { loadGUIMAIN(p, Main.sectionedItems[i], true); return true; } } - } - else{ + } else { return false; } } return false; } - public void loadGUISECTIONS(Player player){ - int lines = (int)Math.floor(((Main.sectionedItems.length)/7)+1); - if (lines > 4){ + public void loadGUISECTIONS(Player player) { + int lines = (int) Math.floor(((Main.sectionedItems.length) / 7) + 1); + if (lines > 4) { lines = 4; } - Gui front = new Gui((lines+2), Config.getMenuTitle()); + Gui front = new Gui((lines + 2), Config.getMenuTitle()); OutlinePane pane = new OutlinePane(1, 1, 7, lines); - for (int i = 0; i < Main.sectionedItems.length; i++){ + for (int i = 0; i < Main.sectionedItems.length; i++) { ItemStack is = new ItemStack((Main.sectionedItems[i].image)); ItemMeta im = is.getItemMeta(); im.setDisplayName(ChatColor.GOLD + Main.sectionedItems[i].name); - im.setLore(Arrays.asList(ChatColor.WHITE + "Click to enter the " + (Main.sectionedItems[i].name.toLowerCase()) + " shop!")); + im.setLore(Arrays.asList( + ChatColor.WHITE + "Click to enter the " + (Main.sectionedItems[i].name.toLowerCase()) + " shop!")); is.setItemMeta(im); final Section inputSection = Main.sectionedItems[i]; - GuiItem gItem = new GuiItem(is, event ->{ + GuiItem gItem = new GuiItem(is, event -> { final Player playernew = player; if (event.getClick() == ClickType.LEFT) { event.setCancelled(true); player.getOpenInventory().close(); loadGUIMAIN(player, inputSection, false); - } - else if (event.getClick() != ClickType.LEFT) { + } else if (event.getClick() != ClickType.LEFT) { event.setCancelled(true); playernew.setItemOnCursor(null); } @@ -123,51 +121,49 @@ else if (event.getClick() != ClickType.LEFT) { public void loadGUIMAIN(Player player, Section sec, boolean twoArgs) { int itemAmount = sec.items.size(); - int lines = (int)Math.floor(((itemAmount-1)/7)+1); - if (lines > 4){ + int lines = (int) Math.floor(((itemAmount - 1) / 7) + 1); + if (lines > 4) { lines = 4; } - Gui main = new Gui((lines+2), Config.getMenuTitle()); - Integer paneSize = (lines+1)*7; - Integer paneAmount = (int) Math.ceil(itemAmount/paneSize)+1; - PaginatedPane pPane = new PaginatedPane(0, 0, 9, (lines+2)); + Gui main = new Gui((lines + 2), Config.getMenuTitle()); + Integer paneSize = (lines + 1) * 7; + Integer paneAmount = (int) Math.ceil(itemAmount / paneSize) + 1; + PaginatedPane pPane = new PaginatedPane(0, 0, 9, (lines + 2)); OutlinePane[] shopPanes = new OutlinePane[paneAmount]; - for (int i = 0; i < shopPanes.length; i++){ + for (int i = 0; i < shopPanes.length; i++) { shopPanes[i] = new OutlinePane(1, 1, 7, lines); - for(int k = 0; k < paneSize; k++){ - if(k+(i*paneSize) < sec.items.size()){ - String itemName = sec.items.get(k+(i*paneSize)); + for (int k = 0; k < paneSize; k++) { + if (k + (i * paneSize) < sec.items.size()) { + String itemName = sec.items.get(k + (i * paneSize)); ItemStack iStack = loadShopItem(itemName, sec); - GuiItem item = new GuiItem(iStack, event ->{ - if (event.getClick() == ClickType.LEFT){ + GuiItem item = new GuiItem(iStack, event -> { + if (event.getClick() == ClickType.LEFT) { event.setCancelled(true); player.getOpenInventory().close(); loadGUITRADING(player, itemName, sec); - } - else{ + } else { event.setCancelled(true); } }); shopPanes[i].addItem(item); - } - else{ + } else { break; } } } - for (int i = 0; i < shopPanes.length; i++){ + for (int i = 0; i < shopPanes.length; i++) { pPane.addPane(i, shopPanes[i]); } main.addPane(pPane); - StaticPane[] panes = loadPagePanes(pPane, (lines+1), main); + StaticPane[] panes = loadPagePanes(pPane, (lines + 1), main); panes[0].setVisible(false); panes[1].setVisible(true); - if (pPane.getPages() == 1){ + if (pPane.getPages() == 1) { panes[1].setVisible(false); } main.addPane(panes[0]); main.addPane(panes[1]); - if (twoArgs == false || (twoArgs == true && sec.showBackButton == true)){ + if (twoArgs == false || (twoArgs == true && sec.showBackButton == true)) { main.addPane(loadMainMenuBackPane(pPane)); } CommandSender cSender = player; @@ -175,63 +171,71 @@ public void loadGUIMAIN(Player player, Section sec, boolean twoArgs) { main.show((HumanEntity) cSender); } - public void loadGUITRADING(Player player, String itemName, Section sec){ + public void loadGUITRADING(Player player, String itemName, Section sec) { Gui main = new Gui(4, Config.getMenuTitle()); OutlinePane front = new OutlinePane(1, 1, 7, 2); - for (int i = 0; i < 14; i++){ + for (int i = 0; i < 14; i++) { final int finalI = i; ItemStack iStack; GuiItem gItem; - if (i < 7){ - iStack = loadTradingItem(itemName, amounts[i], true); - gItem = new GuiItem(iStack, event ->{ + if (i < 7) { + iStack = loadTradingItem(itemName, amounts[i], true, sec); + gItem = new GuiItem(iStack, event -> { event.setCancelled(true); ConcurrentHashMap maxBuyMapRec = Main.maxBuyMap.get(player.getUniqueId()); int currentMax = maxBuyMapRec.get(itemName); Integer[] max = sec.itemMaxBuySell.get(itemName); - if (max[0] < (currentMax+amounts[finalI])){ - player.sendMessage(ChatColor.BOLD + "Cant Purchase " + Integer.toString(amounts[finalI]) + "x of " + itemName); - int difference = (currentMax+amounts[finalI]) - max[0]; - if (difference != 0 && !(currentMax >= max[0])){ - sendPlayerShopMessageAndUpdateGDP(difference, player, itemName, false); - Main.maxBuyMap.put(player.getUniqueId(), maxBuyMapRec); + if (max[0] < (currentMax + amounts[finalI])) { + player.sendMessage(ChatColor.BOLD + "Cant Purchase " + Integer.toString(amounts[finalI]) + + "x of " + itemName); + int difference = (currentMax + amounts[finalI]) - max[0]; + if (difference != 0 && !(currentMax >= max[0])) { + ItemStack is = new ItemStack(Material.matchMaterial(itemName), amounts[finalI]); + is = checkForEnchantAndApply(is, sec); + HashMap unableItems = player.getInventory().addItem(is); + if (unableItems.size() > 0) { + player.sendMessage(ChatColor.BOLD + "Cant Purchase " + Integer.toString(amounts[finalI]) + + "x of " + itemName); + } else { + sendPlayerShopMessageAndUpdateGDP(difference, player, itemName, false); + Main.maxBuyMap.put(player.getUniqueId(), maxBuyMapRec); + } } player.sendMessage(ChatColor.RED + "Max Buys Reached! - " + max[0] + "/" + max[0]); - } - else{ + } else { try { - HashMap unableItems = player.getInventory().addItem(new ItemStack(Material.matchMaterial(itemName), amounts[finalI])); - if (unableItems.size() > 0){ - player.sendMessage(ChatColor.BOLD + "Cant Purchase " + Integer.toString(amounts[finalI]) + "x of " + itemName); - } - else{ + ItemStack is = new ItemStack(Material.matchMaterial(itemName), amounts[finalI]); + is = checkForEnchantAndApply(is, sec); + HashMap unableItems = player.getInventory().addItem(is); + if (unableItems.size() > 0) { + player.sendMessage(ChatColor.BOLD + "Cant Purchase " + Integer.toString(amounts[finalI]) + + "x of " + itemName); + } else { sendPlayerShopMessageAndUpdateGDP(amounts[finalI], player, itemName, false); } - } - catch(IllegalArgumentException ex){ + } catch (IllegalArgumentException ex) { } } }); - } - else{ - iStack = loadTradingItem(itemName, amounts[i-7], false); - gItem = new GuiItem(iStack, event ->{ + } else { + iStack = loadTradingItem(itemName, amounts[i - 7], false, sec); + gItem = new GuiItem(iStack, event -> { event.setCancelled(true); ConcurrentHashMap maxSellMapRec = Main.maxSellMap.get(player.getUniqueId()); int currentMax = maxSellMapRec.get(itemName); Integer[] max = sec.itemMaxBuySell.get(itemName); - 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]; - if (difference != 0 && !(currentMax >= max[1])){ + 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]; + if (difference != 0 && !(currentMax >= max[1])) { sendPlayerShopMessageAndUpdateGDP((difference), player, itemName, true); Main.maxSellMap.put(player.getUniqueId(), maxSellMapRec); } player.sendMessage(ChatColor.RED + "Max Sells Reached! - " + max[1] + "/" + max[1]); - } - else{ - removeItems(player, (finalI-7), itemName); + } else { + removeItems(player, (finalI - 7), itemName, sec); } }); } @@ -244,74 +248,113 @@ public void loadGUITRADING(Player player, String itemName, Section sec){ main.show((HumanEntity) cSender); } - public void removeItems(Player player, int finalI, String itemName){ + public void removeItems(Player player, int finalI, String itemName, Section sec) { try { - HashMap takenItems = player.getInventory().removeItem(new ItemStack(Material.matchMaterial(itemName), amounts[finalI])); - if (takenItems.size() > 0){ - player.sendMessage(ChatColor.BOLD + "Cant sell " + Integer.toString(amounts[finalI]) + "x of " + itemName); - } - else{ + ItemStack iStack = new ItemStack(Material.matchMaterial(itemName), amounts[finalI]); + iStack = checkForEnchantAndApply(iStack, sec); + HashMap takenItems = player.getInventory().removeItem(iStack); + if (takenItems.size() > 0) { + player.sendMessage( + ChatColor.BOLD + "Cant sell " + Integer.toString(amounts[finalI]) + "x of " + itemName); + } else { sendPlayerShopMessageAndUpdateGDP(amounts[finalI], player, itemName, true); } - } - catch(IllegalArgumentException ex){ + } catch (IllegalArgumentException ex) { } } - public ItemStack loadShopItem(String itemName, Section sec){ + public ItemStack loadShopItem(String itemName, Section sec) { ItemStack iStack = new ItemStack(Material.matchMaterial(itemName)); ItemMeta iMeta = iStack.getItemMeta(); Integer[] maxBuySellForItem = sec.itemMaxBuySell.get(itemName); iMeta.setDisplayName(ChatColor.GOLD + itemName); - iMeta.setLore(Arrays.asList((ChatColor.GRAY + "Click to purchase/sell"), - (loadPriceDisplay(itemName)), - (ChatColor.WHITE + "Max Buys: " + maxBuySellForItem[0] + " per " + Config.getTimePeriod() + "min"), - (ChatColor.WHITE + "Max Sells: " + maxBuySellForItem[1] + " per " + Config.getTimePeriod() + "min"))); + iMeta.setLore(Arrays.asList((ChatColor.GRAY + "Click to purchase/sell"), (loadPriceDisplay(itemName)), + (ChatColor.WHITE + "Max Buys: " + maxBuySellForItem[0] + " per " + Config.getTimePeriod() + "min"), + (ChatColor.WHITE + "Max Sells: " + maxBuySellForItem[1] + " per " + Config.getTimePeriod() + "min"))); iStack.setItemMeta(iMeta); + iStack = checkForEnchantAndApply(iStack, sec); return iStack; } - public String loadPriceDisplay(String item){ + public String loadPriceDisplay(String item) { double currentPrice = getItemPrice(item, false); float timePeriod = (float) Config.getTimePeriod(); - float timePeriodsInADay = (float)(1/(timePeriod/1440)); + float timePeriodsInADay = (float) (1 / (timePeriod / 1440)); ConcurrentHashMap newMap = Main.map.get(item); - if (newMap.size() <= timePeriodsInADay){ - return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.DARK_GRAY + " - " + ChatColor.GRAY + "%0.0"); + if (newMap.size() <= timePeriodsInADay) { + return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.DARK_GRAY + + " - " + ChatColor.GRAY + "%0.0"); } Integer oneDayOldTP = (int) Math.floor(newMap.size() - timePeriodsInADay); Double[] arr = newMap.get(oneDayOldTP); double oneDayOldPrice = arr[0]; - if (oneDayOldPrice > currentPrice){ - double percent = 100*((currentPrice/oneDayOldPrice)-1); - return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.DARK_GRAY + " - " + ChatColor.RED + "%-" + df2.format(Math.abs(percent))); - } - else if (oneDayOldPrice < currentPrice){ - double percent = 100*(1-(oneDayOldPrice/currentPrice)); - return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.DARK_GRAY + " - " + ChatColor.GREEN + "%+" + df2.format(Math.abs(percent))); - } - else{ - return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.DARK_GRAY + " - " + ChatColor.GRAY + "%0.0"); + if (oneDayOldPrice > currentPrice) { + double percent = 100 * ((currentPrice / oneDayOldPrice) - 1); + return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.DARK_GRAY + + " - " + ChatColor.RED + "%-" + df2.format(Math.abs(percent))); + } else if (oneDayOldPrice < currentPrice) { + double percent = 100 * (1 - (oneDayOldPrice / currentPrice)); + return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.DARK_GRAY + + " - " + ChatColor.GREEN + "%+" + df2.format(Math.abs(percent))); + } else { + return (ChatColor.WHITE + Config.getCurrencySymbol() + df2.format(currentPrice) + ChatColor.DARK_GRAY + + " - " + ChatColor.GRAY + "%0.0"); } } - public ItemStack loadTradingItem(String itemName, int number, boolean buy){ + public ItemStack loadTradingItem(String itemName, int number, boolean buy, Section sec) { ItemStack iStack = new ItemStack(Material.matchMaterial(itemName), number); ItemMeta iMeta = iStack.getItemMeta(); iMeta.setDisplayName(ChatColor.GOLD + itemName); - if (buy){ - iMeta.setLore(Arrays.asList((ChatColor.WHITE + "$" + df2.format(getItemPrice(itemName, false)*number)), - (ChatColor.GRAY + "Purchase " + number + "x "))); - iStack.setItemMeta(iMeta); + if (buy) { + iMeta.setLore(Arrays.asList((ChatColor.WHITE + "$" + df2.format(getItemPrice(itemName, false) * number)), + (ChatColor.GRAY + "Purchase " + number + "x "))); + iStack.setItemMeta(iMeta); } - if (!buy){ - iMeta.setLore(Arrays.asList((ChatColor.WHITE + "$" + df2.format(getItemPrice(itemName, true)*number)), - (ChatColor.GRAY + "Sell " + number + "x "))); - iStack.setItemMeta(iMeta); + if (!buy) { + iMeta.setLore(Arrays.asList((ChatColor.WHITE + "$" + df2.format(getItemPrice(itemName, true) * number)), + (ChatColor.GRAY + "Sell " + number + "x "))); + iStack.setItemMeta(iMeta); } + iStack = checkForEnchantAndApply(iStack, sec); return iStack; } + public ItemStack checkForEnchantAndApply(ItemStack is, Section sec) { + for (String enchantedItem : sec.enchantedItems) { + if (is.getType().toString().contains(enchantedItem)) { + ConfigurationSection config = Main.getShopConfig().getConfigurationSection("shops") + .getConfigurationSection((is.getType().toString())); + String enchantmentName = config.getString("enchantment", "none"); + ItemMeta meta = is.getItemMeta(); + Enchantment ench = Enchantment.getByName(enchantmentName); + int level = config.getInt("enchantment-level", 0); + if (level == 0){ + return is; + } + else if (enchantmentName.contains("none")){ + Main.debugLog("Enchantment " + enchantmentName + " is null"); + return is; + } + else if (ench == null){ + Main.debugLog("Enchantment " + enchantmentName + " is null"); + return is; + } + try{ + meta.addEnchant(ench, level, true); + is.setItemMeta(meta); + } + catch(IllegalArgumentException ex){ + Main.debugLog("IllegalArgumentException at shop " + is.getType().toString() + " enchantment " + enchantmentName + " is illegal"); + ex.printStackTrace(); + return is; + } + return is; + } + } + return is; + } + public boolean hasAvaliableSlot(Player player) { InventoryView invview = player.getOpenInventory(); Inventory inv = invview.getBottomInventory(); diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java index cb72690..d2a5c2e 100644 --- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java +++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java @@ -18,6 +18,7 @@ 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; public class AutoTuneSellCommand implements CommandExecutor { @@ -122,7 +123,8 @@ public static void sellItems(Player player, ItemStack[] items, Boolean autoSell) Double[] tempPutDouble = {tempDoublearray[0], buyAmount, sellAmount}; tempMap1.put(tempMapSize-1, tempPutDouble); Main.map.put(itemString, tempMap1); - moneyToGive += quantity * sellPrice; + double enchPrice = EnchantmentAlgorithm.calculatePriceWithEnch(item); + moneyToGive += quantity * enchPrice; } if (couldntSell == true && !autoSell) { diff --git a/Auto-Tune/src/unprotesting/com/github/Main.java b/Auto-Tune/src/unprotesting/com/github/Main.java index f073c51..35f42a9 100644 --- a/Auto-Tune/src/unprotesting/com/github/Main.java +++ b/Auto-Tune/src/unprotesting/com/github/Main.java @@ -12,6 +12,8 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.HashMap; +import java.util.List; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -55,6 +57,7 @@ import unprotesting.com.github.Commands.AutoTuneGDPCommand; import unprotesting.com.github.Commands.AutoTuneAutoSellCommand; import unprotesting.com.github.Commands.AutoTuneAutoTuneConfigCommand; +import unprotesting.com.github.Commands.AutoTuneBuyCommand; import unprotesting.com.github.Commands.AutoTuneCommand; import unprotesting.com.github.Commands.AutoTuneGUIShopUserCommand; import unprotesting.com.github.Commands.AutoTuneLoanCommand; @@ -67,6 +70,9 @@ import unprotesting.com.github.util.ChatHandler; import unprotesting.com.github.util.Config; import unprotesting.com.github.util.EconomyShopConfigManager; +import unprotesting.com.github.util.EnchantmentAlgorithm; +import unprotesting.com.github.util.EnchantmentPriceHandler; +import unprotesting.com.github.util.EnchantmentSetting; import unprotesting.com.github.util.HttpPostRequestor; import unprotesting.com.github.util.InflationEventHandler; import unprotesting.com.github.util.JoinEventHandler; @@ -94,7 +100,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; + public static DB db, memDB, tempDB, loanDB, enchDB; public static HTreeMap tempdatadata; public static ConcurrentMap> map; public static ConcurrentMap> maxBuyMap = new ConcurrentHashMap>(); @@ -112,17 +118,14 @@ public final class Main extends JavaPlugin implements Listener { public static Boolean locked = null; public static Boolean falseBool = false; + @Getter + public static ConcurrentMap> enchMap; + static @Getter private File configf; @Getter -public static File shopf; - -@Getter -private static File tradef; - -@Getter -private static File tradeShortf; +public static File shopf, tradef, tradeShortf, enchf; public static String basicVolatilityAlgorithim; public static String priceModel; @@ -145,7 +148,7 @@ public final class Main extends JavaPlugin implements Listener { @Getter @Setter - static private FileConfiguration mainConfig, shopConfig; + static private FileConfiguration mainConfig, shopConfig, enchantmentConfig; @Getter @Setter @@ -228,6 +231,7 @@ public void onEnable() { this.getCommand("loans").setExecutor(new AutoTuneLoansCommand()); this.getCommand("payloan").setExecutor(new AutoTunePaybackLoanCommand()); this.getCommand("gdp").setExecutor(new AutoTuneGDPCommand()); + this.getCommand("buy").setExecutor(new AutoTuneBuyCommand()); basicVolatilityAlgorithim = Config.getBasicVolatilityAlgorithim(); priceModel = Config.getPricingModel().toString(); TextHandler.sendPriceModelData(priceModel); @@ -253,6 +257,11 @@ public void onEnable() { SellDifrunnable(); } loadSections(); + debugLog("Loading Enchatments.."); + EnchantmentAlgorithm.loadEnchantmentSettings(); + debugLog("Loaded " + enchMap.get("Auto-Tune").size() + " enchantments"); + AutoTuneBuyCommand.shopTypes.add("enchantments"); + scheduler.scheduleAsyncRepeatingTask(this, new EnchantmentPriceHandler(), 100, (Config.getTimePeriod()*1200)); } private boolean setupEconomy() { @@ -293,8 +302,8 @@ public void run() { } } - }.runTaskTimerAsynchronously(Main.getINSTANCE(), Config.getTimePeriod() * 20 * 60, - Config.getTimePeriod() * 20 * 60); + }.runTaskTimerAsynchronously(Main.getINSTANCE(), Config.getTimePeriod() * 20, + Config.getTimePeriod() * 1200); } @@ -613,6 +622,7 @@ public void createFiles() { configf = new File(getDataFolder(), "config.yml"); shopf = new File(getDataFolder(), "shops.yml"); + enchf = new File(getDataFolder(), "enchantments.yml"); tradef = new File("plugins/Auto-Tune/web/", "trade.html"); tradeShortf = new File("plugins/Auto-Tune/web/", "trade-short.html"); @@ -636,12 +646,20 @@ public void createFiles() { saveResource("shops.yml", false); } + if (!enchf.exists()) { + enchf.getParentFile().mkdirs(); + saveResource("enchantments.yml", false); + } + + mainConfig = new YamlConfiguration(); shopConfig = new YamlConfiguration(); + enchantmentConfig = new YamlConfiguration(); try { mainConfig.load(configf); shopConfig.load(shopf); + enchantmentConfig.load(enchf); } catch (InvalidConfigurationException | IOException e) { e.printStackTrace(); @@ -679,12 +697,16 @@ public static void setupDataFiles() { playerDataConfig = YamlConfiguration.loadConfiguration(playerdata); memDB = DBMaker.memoryDB().checksumHeaderBypass().closeOnJvmShutdown().make(); memMap = memDB.hashMap("memMap", Serializer.INTEGER, Serializer.STRING).createOrOpen(); + enchDB = DBMaker.fileDB("enchantment-data.db").checksumHeaderBypass().closeOnJvmShutdown().make(); + enchMap = (ConcurrentMap>) enchDB.hashMap("enchMap", Serializer.STRING, Serializer.JAVA).createOrOpen(); } else { db = DBMaker.fileDB("data.db").checksumHeaderBypass().closeOnJvmShutdown().make(); map = (ConcurrentMap>) db.hashMap("map").createOrOpen(); playerDataConfig = YamlConfiguration.loadConfiguration(playerdata); memDB = DBMaker.memoryDB().closeOnJvmShutdown().make(); memMap = memDB.hashMap("memMap", Serializer.INTEGER, Serializer.STRING).createOrOpen(); + enchDB = DBMaker.fileDB("enchantment-data.db").closeOnJvmShutdown().make(); + enchMap = (ConcurrentMap>) enchDB.hashMap("enchMap", Serializer.STRING, Serializer.JAVA).createOrOpen(); } tempDB = DBMaker.fileDB("plugins/Auto-Tune/temp/tempdata.db").checksumHeaderBypass().closeOnJvmShutdown().make(); tempdatadata = tempDB.hashMap("tempdatadata", Serializer.STRING, Serializer.DOUBLE).createOrOpen(); diff --git a/Auto-Tune/src/unprotesting/com/github/util/EnchantmentAlgorithm.java b/Auto-Tune/src/unprotesting/com/github/util/EnchantmentAlgorithm.java new file mode 100644 index 0000000..41ca37a --- /dev/null +++ b/Auto-Tune/src/unprotesting/com/github/util/EnchantmentAlgorithm.java @@ -0,0 +1,121 @@ +package unprotesting.com.github.util; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.json.simple.parser.ParseException; + +import unprotesting.com.github.Main; + +public class EnchantmentAlgorithm { + + public static void loadEnchantmentSettings() { + ConfigurationSection config = Main.getEnchantmentConfig().getConfigurationSection("enchantments"); + ConcurrentHashMap newMap = 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); + } + } + } 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); + } + + public static double calculatePriceWithEnch(ItemStack is) { + ItemMeta iMeta = is.getItemMeta(); + Map enchants = iMeta.getEnchants(); + ConcurrentHashMap inMap = Main.map.get(is.getType().toString()); + double price = 0.0; + if (inMap != null) { + price = inMap.get(inMap.size() - 1)[0]; + } + double cachePrice = 0; + for (Map.Entry ench : enchants.entrySet()) { + String enchName = ench.getKey().getName(); + EnchantmentSetting setting = Main.enchMap.get("Auto-Tune").get(enchName); + Double enchPrice = setting.price; + Double ratio = setting.ratio; + cachePrice = cachePrice + (price * ratio) + enchPrice; + } + if (cachePrice == 0) { + return price; + } else { + return cachePrice; + } + } + + public static ConcurrentHashMap loadAverageBuyAndSellValue(ConcurrentHashMap map, EnchantmentSetting setting) + throws ParseException { + map.put(map.size(), new Double[]{setting.price, 0.0, 0.0}); + for (Integer i : map.keySet()){ + Double[] arr = map.get(i); + Integer tempSize = map.keySet().size(); + Integer x = 0; + Double price = arr[0]; + Integer expvalues = 0; + Double tempbuys = 0.0; + Double tempsells = 0.0; + Double buys = 0.0; + Double sells = 0.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 = map.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++; + } + if (Config.isInflationEnabled()){ + buys = buys + buys * 0.01 * Config.getInflationValue(); + } + Double avBuy = buys / (expvalues); + Double avSells = sells / (expvalues); + if (avBuy > avSells){ + Main.debugLog("AvBuyValue > AvSellValue for " + setting.name); + } + if (avBuy < avSells){ + Main.debugLog("AvBuyValue < AvSellValue for " + setting.name); + } + if (avBuy == avSells){ + Main.debugLog("AvBuyValue = AvSellValue for " + setting.name); + } + Double newSpotPrice = HttpPostRequestor.sendRequestForPrice("Variable", "Exponential", Config.getApiKey(), + Config.getEmail(), setting.name, price, avBuy, avSells, Config.getBasicMaxFixedVolatility(), + Config.getBasicMinFixedVolatility()); + Double[] temporary = { newSpotPrice, 0.0, 0.0 }; + map.put(map.size(), temporary); + } + return map; + } +} diff --git a/Auto-Tune/src/unprotesting/com/github/util/EnchantmentPriceHandler.java b/Auto-Tune/src/unprotesting/com/github/util/EnchantmentPriceHandler.java new file mode 100644 index 0000000..886d435 --- /dev/null +++ b/Auto-Tune/src/unprotesting/com/github/util/EnchantmentPriceHandler.java @@ -0,0 +1,31 @@ +package unprotesting.com.github.util; + +import java.util.concurrent.ConcurrentHashMap; + +import org.json.simple.parser.ParseException; + +import unprotesting.com.github.Main; + +public class EnchantmentPriceHandler implements Runnable { + + @Override + public void run() { + Main.debugLog("Loading Enchantment Price Update Algorithm"); + for (String str : Main.enchMap.get("Auto-Tune").keySet()) { + ConcurrentHashMap inputMap = Main.enchMap.get("Auto-Tune"); + EnchantmentSetting setting = inputMap.get(str); + ConcurrentHashMap buySellMap = setting.buySellData; + try { + buySellMap = EnchantmentAlgorithm.loadAverageBuyAndSellValue(buySellMap, setting); + } catch (ParseException e) { + e.printStackTrace(); + } + setting.buySellData = buySellMap; + Double[] arr = buySellMap.get(buySellMap.size()-1); + setting.price = arr[0]; + inputMap.put(setting.name, setting); + Main.enchMap.put("Auto-Tune", inputMap); + } + } + +} diff --git a/Auto-Tune/src/unprotesting/com/github/util/EnchantmentSetting.java b/Auto-Tune/src/unprotesting/com/github/util/EnchantmentSetting.java new file mode 100644 index 0000000..89cace4 --- /dev/null +++ b/Auto-Tune/src/unprotesting/com/github/util/EnchantmentSetting.java @@ -0,0 +1,22 @@ +package unprotesting.com.github.util; + +import java.io.Serializable; +import java.util.concurrent.ConcurrentHashMap; + +import unprotesting.com.github.Main; + +public class EnchantmentSetting implements Serializable{ + + private static final long serialVersionUID = 2393067834138849688L; + public ConcurrentHashMap buySellData; + public String name; + public double price; + public double ratio; + + public EnchantmentSetting(String name){ + this.name = name; + price = Main.getEnchantmentConfig().getDouble("enchantments." + name + ".price"); + ratio = Main.getEnchantmentConfig().getDouble("enchantments." + name + ".ratio"); + buySellData = new ConcurrentHashMap (); + } +} diff --git a/Auto-Tune/src/unprotesting/com/github/util/Section.java b/Auto-Tune/src/unprotesting/com/github/util/Section.java index 7d7077e..07f5738 100644 --- a/Auto-Tune/src/unprotesting/com/github/util/Section.java +++ b/Auto-Tune/src/unprotesting/com/github/util/Section.java @@ -15,6 +15,7 @@ public class Section { public Material image = Material.matchMaterial("GRASS_BLOCK"); public boolean showBackButton = true; public ConcurrentHashMap itemMaxBuySell = new ConcurrentHashMap(); + public List enchantedItems = new ArrayList(); public Section(String name){ this.name = name; @@ -30,9 +31,13 @@ public Section(String name){ image = Material.matchMaterial(Main.getShopConfig().getConfigurationSection("sections." + section).getString("block")); for (String shop : Main.getShopConfig().getConfigurationSection("shops").getKeys(false)){ String shopSection = Main.getShopConfig().getConfigurationSection("shops." + shop).getString("section"); + String enchantment = Main.getShopConfig().getConfigurationSection("shops." + shop).getString("enchantment", "none"); try{ if (shopSection.equals(section)){ items.add(shop); + if (!enchantment.contains("none")){ + enchantedItems.add(shop); + } } } catch(NullPointerException ex){ diff --git a/Auto-Tune/target/classes/enchantments.yml b/Auto-Tune/target/classes/enchantments.yml new file mode 100644 index 0000000..71c56db --- /dev/null +++ b/Auto-Tune/target/classes/enchantments.yml @@ -0,0 +1,162 @@ + +# ░█████╗░██╗░░░██╗████████╗░█████╗░░░░░░░████████╗██╗░░░██╗███╗░░██╗███████╗ +# ██╔══██╗██║░░░██║╚══██╔══╝██╔══██╗░░░░░░╚══██╔══╝██║░░░██║████╗░██║██╔════╝ +# ███████║██║░░░██║░░░██║░░░██║░░██║█████╗░░░██║░░░██║░░░██║██╔██╗██║█████╗░░ +# ██╔══██║██║░░░██║░░░██║░░░██║░░██║╚════╝░░░██║░░░██║░░░██║██║╚████║██╔══╝░░ +# ██║░░██║╚██████╔╝░░░██║░░░╚█████╔╝░░░░░░░░░██║░░░╚██████╔╝██║░╚███║███████╗ +# ╚═╝░░╚═╝░╚═════╝░░░░╚═╝░░░░╚════╝░░░░░░░░░░╚═╝░░░░╚═════╝░╚═╝░░╚══╝╚══════╝ + +enchantments: + ARROW_DAMAGE: + price: 600.00 ## <- An added price for buying/selling an item with this enchantment + ratio: 0.6 ## <- Another added percentage of the item bought/sold with this enchantment + ## Info: An item worth usually 100 will cost (100*1.6)+600=760 + ## Provides extra damage when shooting arrows from bows + ARROW_FIRE: + price: 750.00 + ratio: 0.8 + ## Sets entities on fire when hit by arrows shot from a bow + ARROW_INFINITE: + price: 1500.00 + ratio: 1.2 + ## Provides infinite arrows when shooting a bow + ARROW_KNOCKBACK: + price: 900.00 + ratio: 0.75 + ## Provides a knockback when an entity is hit by an arrow from a bow + BINDING_CURSE: + price: 80.00 + ratio: 0.1 + ## Item cannot be removed + CHANNELING: + price: 600.00 + ratio: 1.0 + ## Strikes lightning when a mob is hit with a trident if conditions are stormy + DAMAGE_ALL: + price: 750.00 + ratio: 0.8 + ## Increases damage against all targets + DAMAGE_ARTHROPODS: + price: 700.00 + ratio: 0.85 + ## Increases damage against arthropod targets + DAMAGE_UNDEAD: + price: 700.00 + ratio: 0.85 + ## Increases damage against undead targets + DEPTH_STRIDER: + price: 900.00 + ratio: 0.8 + ## Increases walking speed while in water + DIG_SPEED: + price: 850.00 + ratio: 0.75 + ## Increases the rate at which you mine/dig + DURABILITY: + price: 850.00 + ratio: 0.85 + ## Decreases the rate at which a tool looses durability + FIRE_ASPECT: + price: 1000.00 + ratio: 0.9 + ## When attacking a target, has a chance to set them on fire + FROST_WALKER: + price: 1100.00 + ratio: 1.0 + ## Freezes any still water adjacent to ice / frost which player is walking on + IMPALING: + price: 650.00 + ratio: 0.8 + ## Deals more damage to mobs that live in the ocean + KNOCKBACK: + price: 975.00 + ratio: 0.8 + ## All damage to other targets will knock them back when hit + LOOT_BONUS_BLOCKS: + price: 1250.00 + ratio: 1.45 + ## Provides a chance of gaining extra loot when destroying blocks + LOOT_BONUS_MOBS: + price: 1200.00 + ratio: 1.35 + ## Provides a chance of gaining extra loot when killing monsters + LOYALTY: + price: 1100.00 + ratio: 0.8 + ## Causes a thrown trident to return to the player who threw it + LUCK: + price: 750.00 + ratio: 1.2 + ## Decreases odds of catching worthless junk + LURE: + price: 550.00 + ratio: 0.5 + ## Increases rate of fish biting your hook + MENDING: + price: 4000.00 + ratio: 2.25 + ## Allows mending the item using experience orbs + MULTISHOT: + price: 800.00 + ratio: 0.8 + ## Shoot multiple arrows from crossbows + OXYGEN: + price: 600.00 + ratio: 0.7 + ## Decreases the rate of air loss whilst underwater + PIERCING: + price: 750.00 + ratio: 0.8 + ## Crossbow projectiles pierce entities + PROTECTION_ENVIRONMENTAL: + price: 900.00 + ratio: 0.8 + ## Provides protection against environmental damage + PROTECTION_EXPLOSIONS: + price: 950.00 + ratio: 0.85 + ## Provides protection against explosive damage + PROTECTION_FALL: + price: 950.00 + ratio: 0.85 + ## Provides protection against fall damage + PROTECTION_FIRE: + price: 950.00 + ratio: 0.8 + ## Provides protection against fire damage + PROTECTION_PROJECTILE: + price: 950.00 + ratio: 0.85 + ## Provides protection against projectile damage + QUICK_CHARGE: + price: 800.00 + ratio: 0.85 + ## Charges crossbows quickly + RIPTIDE: + price: 1050.00 + ratio: 0.8 + ## When it is rainy, launches the player in the direction their trident is thrown + SILK_TOUCH: + price: 1300.00 + ratio: 1.2 + ## Allows blocks to drop themselves instead of fragments (for example, stone instead of cobblestone) + SOUL_SPEED: + price: 1450.00 + ratio: 1.5 + ## Walk quicker on soul blocks + SWEEPING_EDGE: + price: 1900.00 + ratio: 0.9 + ## Increases damage against targets when using a sweep attack + THORNS: + price: 1600.00 + ratio: 1.25 + ## Damages the attacker + VANISHING_CURSE: + price: 50.00 + ratio: 0.3 + ## Item disappears instead of dropping + WATER_WORKER: + price: 800.00 + ratio: 0.85 + ## Increases the speed at which a player may mine underwater \ No newline at end of file From 7bf4bde9ae9c82c1999691f636f168cbf474162f Mon Sep 17 00:00:00 2001 From: "Noah Clarkson (Unprotesting)" Date: Wed, 2 Dec 2020 18:36:07 +0000 Subject: [PATCH 5/9] More bug fixes and stability improvements + More bug fixes and stability improvements --- Auto-Tune/dependency-reduced-pom.xml | 2 +- Auto-Tune/pom.xml | 2 +- .../github/Commands/AutoTuneBuyCommand.java | 4 +- .../Commands/AutoTuneGUIShopUserCommand.java | 25 +++- .../github/Commands/AutoTuneSellCommand.java | 5 +- .../src/unprotesting/com/github/Main.java | 4 +- .../com/github/util/EnchantmentAlgorithm.java | 115 ++++++++++-------- 7 files changed, 94 insertions(+), 63 deletions(-) diff --git a/Auto-Tune/dependency-reduced-pom.xml b/Auto-Tune/dependency-reduced-pom.xml index 8a4bcf5..b90dba7 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.11.1 + 0.12.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 842a1b5..5774195 100644 --- a/Auto-Tune/pom.xml +++ b/Auto-Tune/pom.xml @@ -9,7 +9,7 @@ unprotesting.com.github Auto-Tune - 0.11.1 + 0.12.0-pre-release-1 Auto-Tune https://github.com/Unprotesting/Auto-Tune diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java index dfc4f61..c90738e 100644 --- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java +++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java @@ -40,12 +40,12 @@ public boolean onCommand(CommandSender sender, Command command, String label, St 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() + setting.price + " | Item Multiplier: " + setting.ratio + "x"); + " | Price : "+ Config.getCurrencySymbol() + AutoTuneGUIShopUserCommand.df2.format(setting.price) + " | Item Multiplier: " + setting.ratio + "x"); } return true; } else{ - player.sendMessage("Shop " + args[0] + "not found!"); + player.sendMessage(ChatColor.RED + "Shop " + args[0] + " not found!"); return false; } } diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java index 0fe4b63..74e0c4f 100644 --- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java +++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java @@ -190,14 +190,14 @@ public void loadGUITRADING(Player player, String itemName, Section sec) { + "x of " + itemName); int difference = (currentMax + amounts[finalI]) - max[0]; if (difference != 0 && !(currentMax >= max[0])) { - ItemStack is = new ItemStack(Material.matchMaterial(itemName), amounts[finalI]); + ItemStack is = new ItemStack(Material.matchMaterial(itemName), (amounts[finalI]-difference)); is = checkForEnchantAndApply(is, sec); HashMap unableItems = player.getInventory().addItem(is); if (unableItems.size() > 0) { player.sendMessage(ChatColor.BOLD + "Cant Purchase " + Integer.toString(amounts[finalI]) + "x of " + itemName); } else { - sendPlayerShopMessageAndUpdateGDP(difference, player, itemName, false); + sendPlayerShopMessageAndUpdateGDP((amounts[finalI]-difference), player, itemName, false); Main.maxBuyMap.put(player.getUniqueId(), maxBuyMapRec); } } @@ -230,7 +230,7 @@ public void loadGUITRADING(Player player, String itemName, Section sec) { + "x of " + itemName); int difference = (currentMax + amounts[finalI - 7]) - max[1]; if (difference != 0 && !(currentMax >= max[1])) { - sendPlayerShopMessageAndUpdateGDP((difference), player, itemName, true); + removeItems(player, (amounts[finalI-7]-difference), itemName, sec); Main.maxSellMap.put(player.getUniqueId(), maxSellMapRec); } player.sendMessage(ChatColor.RED + "Max Sells Reached! - " + max[1] + "/" + max[1]); @@ -494,11 +494,24 @@ 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)}; - Main.tempdatadata.put("GDP", (Main.tempdatadata.get("GDP")+(arr[0]*amount))); + Double price = arr[0] - (arr[0]*0.01*getSellDifference(matClickedString)); + Main.tempdatadata.put("GDP", (Main.tempdatadata.get("GDP")+(price*amount))); inputMap.put((inputMap.size()-1), outputArr); Main.map.put(matClickedString, inputMap); - Main.getEconomy().depositPlayer(player, (arr[0]*amount)); - player.sendMessage(ChatColor.GOLD + "Sold " + amount + "x " + matClickedString + " for " + ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(arr[0]*amount)); + Main.getEconomy().depositPlayer(player, (price*amount)); + player.sendMessage(ChatColor.GOLD + "Sold " + amount + "x " + matClickedString + " for " + ChatColor.GREEN + Config.getCurrencySymbol() + df2.format(price*amount)); } } + + public static double getSellDifference(String item){ + ConfigurationSection config = Main.getShopConfig().getConfigurationSection("shops").getConfigurationSection((item)); + Double sellpricedif = Config.getSellPriceDifference(); + try{ + sellpricedif = config.getDouble("sell-difference", sellpricedif); + } + catch(NullPointerException ex){ + sellpricedif = Config.getSellPriceDifference(); + } + return sellpricedif; + } } \ No newline at end of file diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java index d2a5c2e..67e91e0 100644 --- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java +++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java @@ -124,7 +124,9 @@ public static void sellItems(Player player, ItemStack[] items, Boolean autoSell) tempMap1.put(tempMapSize-1, tempPutDouble); Main.map.put(itemString, tempMap1); double enchPrice = EnchantmentAlgorithm.calculatePriceWithEnch(item); - moneyToGive += quantity * enchPrice; + moneyToGive += quantity * enchPrice; + moneyToGive = moneyToGive - (moneyToGive*0.01*sellpricedif2); + EnchantmentAlgorithm.updateEnchantSellData(item); } if (couldntSell == true && !autoSell) { @@ -152,7 +154,6 @@ public void loadSellGUI(Player player, CommandSender sender2) { GUI.addPane(SellingPane); GUI.setOnClose(this::onSellClose); GUI.show((HumanEntity) sender2); - } private void onSellClose(InventoryCloseEvent event) { diff --git a/Auto-Tune/src/unprotesting/com/github/Main.java b/Auto-Tune/src/unprotesting/com/github/Main.java index 35f42a9..7178cad 100644 --- a/Auto-Tune/src/unprotesting/com/github/Main.java +++ b/Auto-Tune/src/unprotesting/com/github/Main.java @@ -261,7 +261,7 @@ public void onEnable() { EnchantmentAlgorithm.loadEnchantmentSettings(); debugLog("Loaded " + enchMap.get("Auto-Tune").size() + " enchantments"); AutoTuneBuyCommand.shopTypes.add("enchantments"); - scheduler.scheduleAsyncRepeatingTask(this, new EnchantmentPriceHandler(), 100, (Config.getTimePeriod()*1200)); + scheduler.scheduleAsyncRepeatingTask(this, new EnchantmentPriceHandler(), 1200*Config.getTimePeriod(), (Config.getTimePeriod()*1200)); } private boolean setupEconomy() { @@ -302,7 +302,7 @@ public void run() { } } - }.runTaskTimerAsynchronously(Main.getINSTANCE(), Config.getTimePeriod() * 20, + }.runTaskTimerAsynchronously(Main.getINSTANCE(), Config.getTimePeriod() * 600, Config.getTimePeriod() * 1200); } diff --git a/Auto-Tune/src/unprotesting/com/github/util/EnchantmentAlgorithm.java b/Auto-Tune/src/unprotesting/com/github/util/EnchantmentAlgorithm.java index 41ca37a..78a318f 100644 --- a/Auto-Tune/src/unprotesting/com/github/util/EnchantmentAlgorithm.java +++ b/Auto-Tune/src/unprotesting/com/github/util/EnchantmentAlgorithm.java @@ -60,62 +60,79 @@ public static double calculatePriceWithEnch(ItemStack is) { } } + public static void updateEnchantSellData(ItemStack is){ + 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); + ConcurrentHashMap map = setting.buySellData; + Integer size = map.size()-1; + Double[] arr = map.get(size); + arr[2] += 1; + 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); + } + } + public static ConcurrentHashMap loadAverageBuyAndSellValue(ConcurrentHashMap map, EnchantmentSetting setting) throws ParseException { map.put(map.size(), new Double[]{setting.price, 0.0, 0.0}); - for (Integer i : map.keySet()){ - Double[] arr = map.get(i); - Integer tempSize = map.keySet().size(); - Integer x = 0; - Double price = arr[0]; - Integer expvalues = 0; - Double tempbuys = 0.0; - Double tempsells = 0.0; - Double buys = 0.0; - Double sells = 0.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 = map.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++; - } - if (Config.isInflationEnabled()){ - buys = buys + buys * 0.01 * Config.getInflationValue(); - } - Double avBuy = buys / (expvalues); - Double avSells = sells / (expvalues); - if (avBuy > avSells){ - Main.debugLog("AvBuyValue > AvSellValue for " + setting.name); + // for (Integer i : map.keySet()){ + Integer tempSize = map.size()-1; + Double[] arr = map.get(tempSize); + Integer x = 0; + Double price = arr[0]; + Integer expvalues = 0; + Double tempbuys = 0.0; + Double tempsells = 0.0; + Double buys = 0.0; + Double sells = 0.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; } - if (avBuy < avSells){ - Main.debugLog("AvBuyValue < AvSellValue for " + setting.name); + Double[] key = map.get((tempSize - 1) - inty); + tempbuys = key[1]; + tempbuys = tempbuys * key[0]; + if (tempbuys == 0) { + tempbuys = key[0]; } - if (avBuy == avSells){ - Main.debugLog("AvBuyValue = AvSellValue for " + setting.name); + buys = buys + tempbuys; + tempsells = key[2]; + tempsells = tempsells * key[0]; + if (tempsells == 0) { + tempsells = key[0]; } - Double newSpotPrice = HttpPostRequestor.sendRequestForPrice("Variable", "Exponential", Config.getApiKey(), - Config.getEmail(), setting.name, price, avBuy, avSells, Config.getBasicMaxFixedVolatility(), - Config.getBasicMinFixedVolatility()); - Double[] temporary = { newSpotPrice, 0.0, 0.0 }; - map.put(map.size(), temporary); + sells = sells + tempsells; + x++; + } + if (Config.isInflationEnabled()){ + buys = buys + buys * 0.01 * Config.getInflationValue(); + } + Double avBuy = buys / (expvalues); + Double avSells = sells / (expvalues); + if (avBuy > avSells){ + Main.debugLog("AvBuyValue > AvSellValue for " + setting.name); + } + if (avBuy < avSells){ + Main.debugLog("AvBuyValue < AvSellValue for " + setting.name); + } + if (avBuy == avSells){ + Main.debugLog("AvBuyValue = AvSellValue for " + setting.name); } + Double newSpotPrice = HttpPostRequestor.sendRequestForPrice("Variable", "Exponential", Config.getApiKey(), + Config.getEmail(), setting.name, price, avBuy, avSells, Config.getBasicMaxFixedVolatility(), + Config.getBasicMinFixedVolatility()); + Double[] temporary = { newSpotPrice, 0.0, 0.0 }; + map.put(map.size(), temporary); return map; } } From 766ffa715d6f8a0c94644236ff923606cde37bc8 Mon Sep 17 00:00:00 2001 From: "Noah Clarkson (Unprotesting)" Date: Wed, 2 Dec 2020 19:00:27 +0000 Subject: [PATCH 6/9] Fixed incorrect prices for selling items in sell panel + Fixed incorrect prices for selling items in sell panel --- .../com/github/Commands/AutoTuneGUIShopUserCommand.java | 2 +- .../unprotesting/com/github/Commands/AutoTuneSellCommand.java | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java index 74e0c4f..71684f7 100644 --- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java +++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java @@ -387,7 +387,7 @@ public Double getItemPrice(String item, boolean sell){ return arr[0]; } else{ - return getSellPriceDifference(item); + return arr[0] - (arr[0]*0.01*getSellPriceDifference(item)); } } diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java index 67e91e0..efc2113 100644 --- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java +++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java @@ -116,7 +116,6 @@ public static void sellItems(Player player, ItemStack[] items, Boolean autoSell) catch(NullPointerException ex){ sellpricedif2 = Config.getSellPriceDifference(); } - Double sellPrice = (tempDoublearray[0]) - (tempDoublearray[0]*0.01*sellpricedif2); Double buyAmount = tempDoublearray[1]; Double sellAmount = tempDoublearray[2]; sellAmount = quantity + sellAmount; @@ -124,10 +123,9 @@ public static void sellItems(Player player, ItemStack[] items, Boolean autoSell) tempMap1.put(tempMapSize-1, tempPutDouble); Main.map.put(itemString, tempMap1); double enchPrice = EnchantmentAlgorithm.calculatePriceWithEnch(item); - moneyToGive += quantity * enchPrice; + moneyToGive += (quantity * enchPrice); moneyToGive = moneyToGive - (moneyToGive*0.01*sellpricedif2); EnchantmentAlgorithm.updateEnchantSellData(item); - } if (couldntSell == true && !autoSell) { player.sendMessage(ChatColor.BOLD + "Cant sell " + Integer.toString(countSell) + "x of item"); From 4a2884bad12626ad9004d7107f92a8088719de8b Mon Sep 17 00:00:00 2001 From: "Noah Clarkson (Unprotesting)" Date: Thu, 3 Dec 2020 19:38:00 +0000 Subject: [PATCH 7/9] + Added durability aglorithm and fixed more bugs + Added durability aglorithm and fixed more bugs + Added config options to decrease exploitability of enchantments and tools. --- Auto-Tune/src/resources/config.yml | 9 + Auto-Tune/src/resources/shops.yml | 220 +++++++++++++++++- .../github/Commands/AutoTuneBuyCommand.java | 4 +- .../github/Commands/AutoTuneSellCommand.java | 3 +- .../src/unprotesting/com/github/Main.java | 2 + .../unprotesting/com/github/util/Config.java | 6 +- .../com/github/util/DurabilityAlgorithm.java | 21 ++ .../com/github/util/EnchantmentAlgorithm.java | 39 +++- 8 files changed, 294 insertions(+), 10 deletions(-) create mode 100644 Auto-Tune/src/unprotesting/com/github/util/DurabilityAlgorithm.java diff --git a/Auto-Tune/src/resources/config.yml b/Auto-Tune/src/resources/config.yml index 461e155..34816c7 100644 --- a/Auto-Tune/src/resources/config.yml +++ b/Auto-Tune/src/resources/config.yml @@ -133,6 +133,15 @@ intrest-rate-update-period: 1200 ## Example: -10.00 max-debt-value: -10000.00 +## The percentage value to decrease items sold with enchantments +## Info: Stacked enchantments etc. can become very expensive so a number between 5% - 15% is usually fine +## Info: This doesn't affect buys +enchantment-limiter: 7.50 + +## 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 +durability-limiter: 5.00 + ## -- Other Settings -- ## Enable debug mode for more info on price calculations diff --git a/Auto-Tune/src/resources/shops.yml b/Auto-Tune/src/resources/shops.yml index 33a65b1..05fa129 100644 --- a/Auto-Tune/src/resources/shops.yml +++ b/Auto-Tune/src/resources/shops.yml @@ -521,11 +521,6 @@ shops: max-buy: 16 max-sell: 32 section: 'Blocks' - BUCKET: - price: 7.50 - max-buy: 16 - max-sell: 32 - section: 'Other' FURNACE: price: 8.5 max-buy: 32 @@ -661,6 +656,218 @@ shops: max-buy: 32 max-sell: 48 section: 'Other' + WOODEN_PICKAXE: + price: 8.0 + max-buy: 4 + max-sell: 8 + section: 'Tools' + WOODEN_AXE: + price: 7.5 + max-buy: 4 + max-sell: 8 + section: 'Tools' + WOODEN_SWORD: + price: 6.5 + max-buy: 4 + max-sell: 8 + section: 'Tools' + WOODEN_SHOVEL: + price: 3.5 + max-buy: 4 + max-sell: 8 + section: 'Tools' + WOODEN_HOE: + price: 3.5 + max-buy: 4 + max-sell: 8 + section: 'Tools' + STONE_PICKAXE: + price: 11.0 + max-buy: 4 + max-sell: 8 + section: 'Tools' + STONE_AXE: + price: 10.5 + max-buy: 4 + max-sell: 8 + section: 'Tools' + STONE_SWORD: + price: 9.0 + max-buy: 4 + max-sell: 8 + section: 'Tools' + STONE_SHOVEL: + price: 5.0 + max-buy: 4 + max-sell: 8 + section: 'Tools' + STONE_HOE: + price: 5.0 + max-buy: 4 + max-sell: 8 + section: 'Tools' + GOLDEN_PICKAXE: + price: 12.0 + max-buy: 3 + max-sell: 8 + section: 'Tools' + GOLDEN_AXE: + price: 11.5 + max-buy: 3 + max-sell: 8 + section: 'Tools' + GOLDEN_SWORD: + price: 10.0 + max-buy: 3 + max-sell: 8 + section: 'Tools' + GOLDEN_SHOVEL: + price: 6.0 + max-buy: 3 + max-sell: 8 + section: 'Tools' + GOLDEN_HOE: + price: 6.0 + max-buy: 3 + max-sell: 8 + section: 'Tools' + IRON_PICKAXE: + price: 18.0 + max-buy: 3 + max-sell: 6 + section: 'Tools' + IRON_AXE: + price: 17.5 + max-buy: 3 + max-sell: 6 + section: 'Tools' + IRON_SWORD: + price: 13.0 + max-buy: 3 + max-sell: 6 + section: 'Tools' + IRON_SHOVEL: + price: 7.0 + max-buy: 3 + max-sell: 6 + section: 'Tools' + IRON_HOE: + price: 7.0 + max-buy: 3 + max-sell: 6 + section: 'Tools' + DIAMOND_PICKAXE: + price: 260.0 + max-buy: 2 + max-sell: 3 + section: 'Tools' + DIAMOND_AXE: + price: 250.0 + max-buy: 2 + max-sell: 3 + section: 'Tools' + DIAMOND_SWORD: + price: 180.0 + max-buy: 2 + max-sell: 3 + section: 'Tools' + DIAMOND_SHOVEL: + price: 110.0 + max-buy: 2 + max-sell: 3 + section: 'Tools' + DIAMOND_HOE: + price: 110.0 + max-buy: 2 + max-sell: 3 + section: 'Tools' + LEATHER_HELMET: + price: 22.50 + max-buy: 2 + max-sell: 4 + section: 'Tools' + LEATHER_CHESTPLATE: + price: 46.00 + max-buy: 2 + max-sell: 3 + section: 'Tools' + LEATHER_LEGGINGS: + price: 25.50 + max-buy: 2 + max-sell: 3 + section: 'Tools' + LEATHER_BOOTS: + price: 20.00 + max-buy: 2 + max-sell: 4 + section: 'Tools' + IRON_HELMET: + price: 45.50 + max-buy: 2 + max-sell: 4 + section: 'Tools' + IRON_CHESTPLATE: + price: 86.00 + max-buy: 2 + max-sell: 3 + section: 'Tools' + IRON_LEGGINGS: + price: 65.50 + max-buy: 2 + max-sell: 3 + section: 'Tools' + IRON_BOOTS: + price: 38.00 + max-buy: 2 + max-sell: 4 + section: 'Tools' + GOLDEN_HELMET: + price: 40.50 + max-buy: 2 + max-sell: 4 + section: 'Tools' + GOLDEN_CHESTPLATE: + price: 80.00 + max-buy: 2 + max-sell: 3 + section: 'Tools' + GOLDEN_LEGGINGS: + price: 60.50 + max-buy: 2 + max-sell: 3 + section: 'Tools' + GOLDEN_BOOTS: + price: 30.00 + max-buy: 2 + max-sell: 4 + section: 'Tools' + DIAMOND_HELMET: + price: 425.50 + max-buy: 2 + max-sell: 4 + section: 'Tools' + DIAMOND_CHESTPLATE: + price: 900.00 + max-buy: 2 + max-sell: 3 + section: 'Tools' + DIAMOND_LEGGINGS: + price: 620.50 + max-buy: 2 + max-sell: 3 + section: 'Tools' + DIAMOND_BOOTS: + price: 350.00 + max-buy: 2 + max-sell: 4 + section: 'Tools' + BUCKET: + price: 7.50 + max-buy: 16 + max-sell: 26 + section: 'Tools' + + ## Shop sections configuration sections: @@ -679,6 +886,9 @@ sections: 'Farming': block: 'OAK_SAPLING' back-menu-button-enabled: true + 'Tools': + block: 'DIAMOND_PICKAXE' + back-menu-button-enabled: true 'Other': block: 'STICK' back-menu-button-enabled: true diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java index c90738e..6900bc8 100644 --- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java +++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java @@ -21,9 +21,9 @@ public class AutoTuneBuyCommand implements CommandExecutor { public static List shopTypes = new ArrayList(); + @Deprecated @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player){ Player player = (Player) sender; if (args.length == 0){ @@ -64,7 +64,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St ex.printStackTrace(); return true; } - double price = EnchantmentAlgorithm.calculatePriceWithEnch(is); + double price = EnchantmentAlgorithm.calculatePriceWithEnch(is, true); 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)); diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java index efc2113..f68cce9 100644 --- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java +++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneSellCommand.java @@ -59,6 +59,7 @@ public static String getItemStringForItemStack(ItemStack item) { return item.getType().toString().toUpperCase(); } + @Deprecated public static void sellItems(Player player, ItemStack[] items, Boolean autoSell) { double moneyToGive = 0; boolean couldntSell = false; @@ -122,7 +123,7 @@ public static void sellItems(Player player, ItemStack[] items, Boolean autoSell) Double[] tempPutDouble = {tempDoublearray[0], buyAmount, sellAmount}; tempMap1.put(tempMapSize-1, tempPutDouble); Main.map.put(itemString, tempMap1); - double enchPrice = EnchantmentAlgorithm.calculatePriceWithEnch(item); + double enchPrice = EnchantmentAlgorithm.calculatePriceWithEnch(item, false); moneyToGive += (quantity * enchPrice); moneyToGive = moneyToGive - (moneyToGive*0.01*sellpricedif2); EnchantmentAlgorithm.updateEnchantSellData(item); diff --git a/Auto-Tune/src/unprotesting/com/github/Main.java b/Auto-Tune/src/unprotesting/com/github/Main.java index 7178cad..cc88423 100644 --- a/Auto-Tune/src/unprotesting/com/github/Main.java +++ b/Auto-Tune/src/unprotesting/com/github/Main.java @@ -23,6 +23,7 @@ import com.github.stefvanschie.inventoryframework.Gui; import com.github.stefvanschie.inventoryframework.pane.OutlinePane; +import com.google.errorprone.annotations.RestrictedApi; import com.sun.net.httpserver.HttpServer; import org.bukkit.Bukkit; @@ -160,6 +161,7 @@ public void onDisable() { } @Override + @Deprecated public void onEnable() { Bukkit.getServer().getPluginManager().registerEvents(new JoinEventHandler(), this); Bukkit.getServer().getPluginManager().registerEvents(new ChatHandler(), this); diff --git a/Auto-Tune/src/unprotesting/com/github/util/Config.java b/Auto-Tune/src/unprotesting/com/github/util/Config.java index 6ea599e..e4bfe28 100644 --- a/Auto-Tune/src/unprotesting/com/github/util/Config.java +++ b/Auto-Tune/src/unprotesting/com/github/util/Config.java @@ -62,7 +62,9 @@ public final class Config { inflationValue, intrestRate, maxDebt, - shopConfigGUIShopSellValue; + shopConfigGUIShopSellValue, + enchantmentLimiter, + durabilityLimiter; public static void loadDefaults() { @@ -108,6 +110,8 @@ public static void loadDefaults() { Config.setInflationValue(Main.getMainConfig().getDouble("static-inflation-value", 0.1)); Config.setDataSelectionZ(Main.getMainConfig().getDouble("data-selection-z", 1.6)); Config.setSellPriceDifference(Main.getMainConfig().getDouble("sell-price-difference", 2.5)); + Config.setEnchantmentLimiter(Main.getMainConfig().getDouble("enchantment-limiter", 7.5)); + Config.setDurabilityLimiter(Main.getMainConfig().getDouble("durability-limiter", 5.0)); Config.setIntrestRate(Main.getMainConfig().getDouble("intrest-rate", 0.001)); Config.setMaxDebt(Main.getMainConfig().getDouble("max-debt-value", -5000.00)); Config.setSellPriceDifferenceVariationStart(Main.getMainConfig().getDouble("sell-price-difference-variation-start", 25.0)); diff --git a/Auto-Tune/src/unprotesting/com/github/util/DurabilityAlgorithm.java b/Auto-Tune/src/unprotesting/com/github/util/DurabilityAlgorithm.java new file mode 100644 index 0000000..5ff4386 --- /dev/null +++ b/Auto-Tune/src/unprotesting/com/github/util/DurabilityAlgorithm.java @@ -0,0 +1,21 @@ +package unprotesting.com.github.util; + +import org.bukkit.inventory.ItemStack; + +import unprotesting.com.github.Main; + +public class DurabilityAlgorithm { + + @Deprecated + public static double calculateDurability(ItemStack is){ + Double durability = (double) is.getDurability(); + double maxDurability = (double) is.getType().getMaxDurability(); + if (durability == 0 ){ + return 100.00; + } + double current = maxDurability - durability; + double output = (current/maxDurability)*100; + return output; + } + +} \ No newline at end of file diff --git a/Auto-Tune/src/unprotesting/com/github/util/EnchantmentAlgorithm.java b/Auto-Tune/src/unprotesting/com/github/util/EnchantmentAlgorithm.java index 78a318f..00db4ae 100644 --- a/Auto-Tune/src/unprotesting/com/github/util/EnchantmentAlgorithm.java +++ b/Auto-Tune/src/unprotesting/com/github/util/EnchantmentAlgorithm.java @@ -37,7 +37,8 @@ public static void loadEnchantmentSettings() { Main.enchMap.put("Auto-Tune", newMap); } - public static double calculatePriceWithEnch(ItemStack is) { + @Deprecated + public static double calculatePriceWithEnch(ItemStack is, boolean buy) { ItemMeta iMeta = is.getItemMeta(); Map enchants = iMeta.getEnchants(); ConcurrentHashMap inMap = Main.map.get(is.getType().toString()); @@ -51,8 +52,23 @@ public static double calculatePriceWithEnch(ItemStack is) { EnchantmentSetting setting = Main.enchMap.get("Auto-Tune").get(enchName); Double enchPrice = setting.price; Double ratio = setting.ratio; + if (!buy){ + enchPrice = enchPrice - (enchPrice*0.01*Config.getEnchantmentLimiter()); + } cachePrice = cachePrice + (price * ratio) + enchPrice; } + double durability = DurabilityAlgorithm.calculateDurability(is); + if (durability != 100.00){ + if (cachePrice == 0) { + price = price*durability*0.01; + price = price - price*0.01*Config.getDurabilityLimiter(); + return price; + } else { + cachePrice = cachePrice*durability*0.01; + cachePrice = cachePrice - cachePrice*0.01*Config.getDurabilityLimiter(); + return cachePrice; + } + } if (cachePrice == 0) { return price; } else { @@ -69,6 +85,15 @@ public static void updateEnchantSellData(ItemStack is){ ConcurrentHashMap map = setting.buySellData; Integer size = map.size()-1; Double[] arr = map.get(size); + if (arr == null){ + arr = new Double[]{setting.price, 0.0, 0.0}; + } + if (arr[2] == null){ + arr[2] = 0.0; + } + if (arr[1] == null){ + arr[1] = 0.0; + } arr[2] += 1; map.put(size, arr); setting.buySellData = map; @@ -100,6 +125,18 @@ public static ConcurrentHashMap loadAverageBuyAndSellValue(Co break; } Double[] key = map.get((tempSize - 1) - inty); + if (key == null){ + key = new Double[]{setting.price, 0.0, 0.0}; + } + if (key[0] == null){ + key[0] = setting.price; + } + if (key[1] == null){ + key[1] = 0.0; + } + if (key[2] == null){ + key[2] = 0.0; + } tempbuys = key[1]; tempbuys = tempbuys * key[0]; if (tempbuys == 0) { From cee3df83905079e5e463382f535cc438154de412 Mon Sep 17 00:00:00 2001 From: "Noah Clarkson (Unprotesting)" Date: Sat, 5 Dec 2020 11:10:05 +0000 Subject: [PATCH 8/9] Fixed buy command returning errors + Fixed buy command returning errors --- .../github/Commands/AutoTuneBuyCommand.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java index 6900bc8..c19adb5 100644 --- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java +++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java @@ -2,9 +2,11 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -54,25 +56,45 @@ public boolean onCommand(CommandSender sender, Command command, String label, St 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){ - Enchantment ench = Enchantment.getByName(setting.name); try{ - is.addEnchantment(ench, 1); + if (!enchantExists){ + is.addEnchantment(ench, 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; } - double price = EnchantmentAlgorithm.calculatePriceWithEnch(is, true); + ItemStack test = new ItemStack(mat); + test.addEnchantment(ench, 1); + double price = EnchantmentAlgorithm.calculatePriceWithEnch(new ItemStack(mat), true); 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; From ddfb88df781de6f5ba6174d87edf2f78efcf97b1 Mon Sep 17 00:00:00 2001 From: "Noah Clarkson (Unprotesting)" Date: Sat, 5 Dec 2020 11:17:23 +0000 Subject: [PATCH 9/9] Update shops.yml --- Auto-Tune/src/resources/shops.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Auto-Tune/src/resources/shops.yml b/Auto-Tune/src/resources/shops.yml index 05fa129..420c045 100644 --- a/Auto-Tune/src/resources/shops.yml +++ b/Auto-Tune/src/resources/shops.yml @@ -861,6 +861,16 @@ shops: max-buy: 2 max-sell: 4 section: 'Tools' + FISHING_ROD: + price: 25.00 + max-buy: 3 + max-sell: 4 + section: 'Tools' + BOW: + price: 28.00 + max-buy: 3 + max-sell: 4 + section: 'Tools' BUCKET: price: 7.50 max-buy: 16