From 744e7692843c65049e45f666973e1e37adcc7e9a Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Wed, 31 May 2023 13:06:27 +0200 Subject: Removing the neu AH (#627) * Removed the neu ah. * make compile * make command say its removed * just what i wanted, an empty file --------- Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: nopo --- .../moulberry/notenoughupdates/NEUOverlay.java | 4 - .../notenoughupdates/auction/APIManager.java | 790 +------- .../notenoughupdates/auction/CustomAH.java | 2001 -------------------- .../notenoughupdates/auction/CustomAHGui.java | 32 - .../notenoughupdates/listener/ChatListener.java | 8 - .../listener/NEUEventListener.java | 4 +- .../notenoughupdates/listener/RenderListener.java | 68 +- .../notenoughupdates/mbgui/MBGuiGroupFloating.java | 14 +- .../notenoughupdates/options/NEUConfig.java | 12 +- .../options/seperateSections/NeuAuctionHouse.java | 73 - .../notenoughupdates/commands/misc/AhCommand.kt | 36 +- 11 files changed, 33 insertions(+), 3009 deletions(-) delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAHGui.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/NeuAuctionHouse.java (limited to 'src') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index 000158a4..c6f0785d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -23,7 +23,6 @@ import com.google.common.collect.Lists; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.auction.CustomAHGui; import io.github.moulberry.notenoughupdates.core.BackgroundBlur; import io.github.moulberry.notenoughupdates.core.GuiScreenElementWrapper; import io.github.moulberry.notenoughupdates.core.util.lerp.LerpingInteger; @@ -1567,9 +1566,6 @@ public class NEUOverlay extends Gui { public float getWidthMult() { float scaleFMult = 1; if (Utils.peekGuiScale().getScaleFactor() == 4) scaleFMult *= 0.9f; - if (manager.auctionManager.customAH.isRenderOverAuctionView() || - Minecraft.getMinecraft().currentScreen instanceof CustomAHGui) - scaleFMult *= 0.8f; return (float) Math.max(0.5, Math.min(1.5, NotEnoughUpdates.INSTANCE.config.itemlist.paneWidthMult)) * scaleFMult; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java index 1faac488..58d8c23b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java @@ -19,59 +19,29 @@ package io.github.moulberry.notenoughupdates.auction; -import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.ItemPriceInformation; import io.github.moulberry.notenoughupdates.NEUManager; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.miscgui.pricegraph.LocalGraphDataProvider; import io.github.moulberry.notenoughupdates.recipes.Ingredient; import io.github.moulberry.notenoughupdates.recipes.ItemShopRecipe; import io.github.moulberry.notenoughupdates.recipes.NeuRecipe; -import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.event.ClickEvent; -import net.minecraft.event.HoverEvent; import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.ChatStyle; -import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.Base64; -import java.util.ConcurrentModificationException; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.NoSuchElementException; import java.util.Set; -import java.util.TreeMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.function.Consumer; import java.util.regex.Matcher; import java.util.regex.Pattern; public class APIManager { private final NEUManager manager; - public final CustomAH customAH; - private final TreeMap auctionMap = new TreeMap<>(); - public HashMap> internalnameToAucIdMap = new HashMap<>(); - private final HashSet playerBids = new HashSet<>(); - private final HashSet playerBidsNotified = new HashSet<>(); - private final HashSet playerBidsFinishedNotified = new HashSet<>(); private final int LOWEST_BIN_UPDATE_INTERVAL = 2 * 60 * 1000; // 2 minutes private final int AUCTION_AVG_UPDATE_INTERVAL = 5 * 60 * 1000; // 5 minutes private final int BAZAAR_UPDATE_INTERVAL = 5 * 60 * 1000; // 5 minutes @@ -79,165 +49,21 @@ public class APIManager { private JsonObject lowestBins = null; private JsonObject auctionPricesAvgLowestBinJson = null; - private LinkedList pagesToDownload = null; - private JsonObject bazaarJson = null; private JsonObject auctionPricesJson = null; private final HashMap craftCost = new HashMap<>(); - public TreeMap>> extrasToAucIdMap = new TreeMap<>(); - private boolean didFirstUpdate = false; - private long lastAuctionUpdate = 0; - private long lastShortAuctionUpdate = 0; - private long lastCustomAHSearch = 0; - private long lastCleanup = 0; private long lastAuctionAvgUpdate = 0; private long lastBazaarUpdate = 0; private long lastLowestBinUpdate = 0; - private long lastApiUpdate = 0; - private long firstHypixelApiUpdate = 0; - - public int activeAuctions = 0; - public int uniqueItems = 0; - public int totalTags = 0; - public int internalnameTaggedAuctions = 0; - public int taggedAuctions = 0; - public int processMillis = 0; - public APIManager(NEUManager manager) { this.manager = manager; - customAH = new CustomAH(manager); - } - - public TreeMap getAuctionItems() { - return auctionMap; - } - - public HashSet getPlayerBids() { - return playerBids; - } - - public HashSet getAuctionsForInternalname(String internalname) { - return internalnameToAucIdMap.computeIfAbsent(internalname, k -> new HashSet<>()); - } - - public class Auction { - public String auctioneerUuid; - public long end; - public long starting_bid; - public int highest_bid_amount; - public int bid_count; - public boolean bin; - public String category; - public String rarity; - public int dungeonTier; - public String item_tag_str; - public NBTTagCompound item_tag = null; - private ItemStack stack; - - public int enchLevel = 0; //0 = clean, 1 = ench, 2 = ench/hpb - - public Auction( - String auctioneerUuid, long end, long starting_bid, int highest_bid_amount, int bid_count, - boolean bin, String category, String rarity, int dungeonTier, String item_tag_str - ) { - this.auctioneerUuid = auctioneerUuid; - this.end = end; - this.starting_bid = starting_bid; - this.highest_bid_amount = highest_bid_amount; - this.bid_count = bid_count; - this.bin = bin; - this.category = category; - this.dungeonTier = dungeonTier; - this.rarity = rarity; - this.item_tag_str = item_tag_str; - } - - public ItemStack getStack() { - if (item_tag == null && item_tag_str != null) { - try { - item_tag = CompressedStreamTools.readCompressed( - new ByteArrayInputStream(Base64.getDecoder().decode(item_tag_str))); - item_tag_str = null; - } catch (IOException e) { - return null; - } - } - if (stack != null) { - return stack; - } else { - JsonObject item = manager.getJsonFromNBT(item_tag); - if (item == null) return null; - ItemStack stack = manager.jsonToStack(item, false); - - JsonObject itemDefault = manager.getItemInformation().get(item.get("internalname").getAsString()); - - if (stack != null && itemDefault != null) { - ItemStack stackDefault = manager.jsonToStack(itemDefault, true); - if (stack.isItemEqual(stackDefault)) { - //Item types are the same, compare lore - - String[] stackLore = manager.getLoreFromNBT(stack.getTagCompound()); - String[] defaultLore = manager.getLoreFromNBT(stackDefault.getTagCompound()); - - boolean loreMatches = stackLore != null && defaultLore != null && stackLore.length == defaultLore.length; - if (loreMatches) { - for (int i = 0; i < stackLore.length; i++) { - if (!stackLore[i].equals(defaultLore[i])) { - loreMatches = false; - break; - } - } - } - if (loreMatches) { - stack = stackDefault; - } - } - } - this.stack = stack; - return stack; - } - } - } - - public void markNeedsUpdate() { - firstHypixelApiUpdate = 0; - pagesToDownload = null; - - auctionMap.clear(); - internalnameToAucIdMap.clear(); - extrasToAucIdMap.clear(); } public void tick() { - customAH.tick(); long currentTime = System.currentTimeMillis(); - if (NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.enableNeuAuctionHouse && - NotEnoughUpdates.INSTANCE.config.apiData.apiKey != null && - !NotEnoughUpdates.INSTANCE.config.apiData.apiKey.isEmpty()) { - if (currentTime - lastAuctionUpdate > 60 * 1000) { - lastAuctionUpdate = currentTime; - updatePageTick(); - } - if (currentTime - lastShortAuctionUpdate > 10 * 1000) { - lastShortAuctionUpdate = currentTime; - updatePageTickShort(); - ahNotification(); - } - if (currentTime - lastCleanup > 60 * 1000) { - lastCleanup = currentTime; - cleanup(); - } - if (currentTime - lastCustomAHSearch > 60 * 1000) { - lastCustomAHSearch = currentTime; - if (Minecraft.getMinecraft().currentScreen instanceof CustomAHGui || customAH.isRenderOverAuctionView()) { - customAH.updateSearch(); - calculateStats(); - } - } - } if (currentTime - lastAuctionAvgUpdate > AUCTION_AVG_UPDATE_INTERVAL) { lastAuctionAvgUpdate = currentTime - AUCTION_AVG_UPDATE_INTERVAL + 60 * 1000; // Try again in 1 minute on failure updateAvgPrices(); @@ -252,22 +78,6 @@ public class APIManager { } } - private String niceAucId(String aucId) { - if (aucId.length() != 32) return aucId; - - StringBuilder niceAucId = new StringBuilder(); - niceAucId.append(aucId, 0, 8); - niceAucId.append("-"); - niceAucId.append(aucId, 8, 12); - niceAucId.append("-"); - niceAucId.append(aucId, 12, 16); - niceAucId.append("-"); - niceAucId.append(aucId, 16, 20); - niceAucId.append("-"); - niceAucId.append(aucId, 20, 32); - return niceAucId.toString(); - } - public Set getLowestBinKeySet() { if (lowestBins == null) return new HashSet<>(); HashSet keys = new HashSet<>(); @@ -310,415 +120,10 @@ public class APIManager { }); } - private void ahNotification() { - playerBidsNotified.retainAll(playerBids); - playerBidsFinishedNotified.retainAll(playerBids); - if (NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.ahNotification <= 0) { - return; - } - for (String aucid : playerBids) { - Auction auc = auctionMap.get(aucid); - if (!playerBidsNotified.contains(aucid)) { - if (auc != null && - auc.end - System.currentTimeMillis() < - 1000 * 60 * NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.ahNotification) { - ChatComponentText message = new ChatComponentText( - EnumChatFormatting.YELLOW + - "The " + - auc.getStack().getDisplayName() + - EnumChatFormatting.YELLOW + - " you have bid on is ending soon! Click here to view."); - ChatStyle clickEvent = new ChatStyle().setChatClickEvent( - new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/viewauction " + niceAucId(aucid))); - clickEvent.setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ChatComponentText( - EnumChatFormatting.YELLOW + - "View auction"))); - message.setChatStyle(clickEvent); - Minecraft.getMinecraft().thePlayer.addChatMessage(message); - - playerBidsNotified.add(aucid); - } - } - if (!playerBidsFinishedNotified.contains(aucid)) { - if (auc != null && auc.end < System.currentTimeMillis()) { - ChatComponentText message = new ChatComponentText( - EnumChatFormatting.YELLOW + - "The " + - auc.getStack().getDisplayName() + - EnumChatFormatting.YELLOW + - " you have bid on (might) have ended! Click here to view."); - ChatStyle clickEvent = new ChatStyle().setChatClickEvent( - new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/viewauction " + niceAucId(aucid))); - clickEvent.setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ChatComponentText( - EnumChatFormatting.YELLOW + - "View auction"))); - message.setChatStyle(clickEvent); - Minecraft.getMinecraft().thePlayer.addChatMessage(message); - - playerBidsFinishedNotified.add(aucid); - } - } - } - } - public long getLastLowestBinUpdateTime() { return lastLowestBinUpdate; } - private final ExecutorService es = Executors.newSingleThreadExecutor(); - - private void cleanup() { - es.submit(() -> { - try { - long currTime = System.currentTimeMillis(); - Set toRemove = new HashSet<>(); - for (Map.Entry entry : auctionMap.entrySet()) { - long timeToEnd = entry.getValue().end - currTime; - if (timeToEnd < -120 * 1000) { //2 minutes - toRemove.add(entry.getKey()); - } - } - toRemove.removeAll(playerBids); - remove(toRemove); - } catch (ConcurrentModificationException e) { - lastCleanup = System.currentTimeMillis() - 110 * 1000; - } - }); - } - - private void remove(Set toRemove) { - for (String aucid : toRemove) { - auctionMap.remove(aucid); - } - for (HashMap> extrasMap : extrasToAucIdMap.values()) { - for (HashSet aucids : extrasMap.values()) { - for (String aucid : toRemove) { - aucids.remove(aucid); - } - } - } - for (HashSet aucids : internalnameToAucIdMap.values()) { - aucids.removeAll(toRemove); - } - } - - private void updatePageTickShort() { - if (pagesToDownload == null || pagesToDownload.isEmpty()) return; - - if (firstHypixelApiUpdate == 0 || (System.currentTimeMillis() - firstHypixelApiUpdate) % (60 * 1000) > 15 * 1000) - return; - - JsonObject disable = Constants.DISABLE; - if (disable != null && disable.has("auctions_new") && disable.get("auctions_new").getAsBoolean()) return; - - while (!pagesToDownload.isEmpty()) { - try { - int page = pagesToDownload.pop(); - getPageFromAPI(page); - } catch (NoSuchElementException ignored) { - return; - } //Weird race condition? - } - } - - private void updatePageTick() { - JsonObject disable = Constants.DISABLE; - if (disable != null && disable.has("auctions_new") && disable.get("auctions_new").getAsBoolean()) return; - - if (pagesToDownload == null) { - getPageFromAPI(0); - } - - Consumer process = jsonObject -> { - if (jsonObject.get("success").getAsBoolean()) { - JsonArray new_auctions = jsonObject.get("new_auctions").getAsJsonArray(); - for (JsonElement auctionElement : new_auctions) { - JsonObject auction = auctionElement.getAsJsonObject(); - //System.out.println("New auction " + auction); - processAuction(auction); - } - JsonArray new_bids = jsonObject.get("new_bids").getAsJsonArray(); - for (JsonElement newBidElement : new_bids) { - JsonObject newBid = newBidElement.getAsJsonObject(); - String newBidUUID = newBid.get("uuid").getAsString(); - //System.out.println("new bid" + newBidUUID); - int newBidAmount = newBid.get("highest_bid_amount").getAsInt(); - int end = newBid.get("end").getAsInt(); - int bid_count = newBid.get("bid_count").getAsInt(); - - Auction auc = auctionMap.get(newBidUUID); - if (auc != null) { - //System.out.println("Setting auction " + newBidUUID + " price to " + newBidAmount); - auc.highest_bid_amount = newBidAmount; - auc.end = end; - auc.bid_count = bid_count; - } - } - Set toRemove = new HashSet<>(); - JsonArray removed_auctions = jsonObject.get("removed_auctions").getAsJsonArray(); - for (JsonElement removedAuctionsElement : removed_auctions) { - String removed = removedAuctionsElement.getAsString(); - toRemove.add(removed); - } - remove(toRemove); - } - }; - - manager.apiUtils.newMoulberryRequest("auctionLast.json.gz") - .gunzip().requestJson().thenAcceptAsync(process); - - manager.apiUtils - .newMoulberryRequest("auction.json.gz") - .gunzip().requestJson() - .thenAcceptAsync(jsonObject -> { - if (jsonObject.get("success").getAsBoolean()) { - long apiUpdate = (long) jsonObject.get("time").getAsFloat(); - if (lastApiUpdate == apiUpdate) { - lastAuctionUpdate -= 30 * 1000; - } - lastApiUpdate = apiUpdate; - - process.accept(jsonObject); - } - }); - - } - - public void calculateStats() { - try { - uniqueItems = internalnameToAucIdMap.size(); - Set aucs = new HashSet<>(); - for (HashSet aucids : internalnameToAucIdMap.values()) { - aucs.addAll(aucids); - } - internalnameTaggedAuctions = aucs.size(); - totalTags = extrasToAucIdMap.size(); - aucs = new HashSet<>(); - for (HashMap> extrasMap : extrasToAucIdMap.values()) { - for (HashSet aucids : extrasMap.values()) { - aucs.addAll(aucids); - } - } - taggedAuctions = aucs.size(); - } catch (Exception ignored) { - } - } - - //String[] rarityArr = new String[] { - // "COMMON", "UNCOMMON", "RARE", "EPIC", "LEGENDARY", "MYTHIC", "SPECIAL", "VERY SPECIAL", "SUPREME", - //}; - - public int checkItemType(String lore, boolean contains, String... typeMatches) { - String[] split = lore.split("\n"); - for (int i = split.length - 1; i >= 0; i--) { - String line = split[i]; - for (String rarity : Utils.rarityArr) { - for (int j = 0; j < typeMatches.length; j++) { - if (contains) { - if (line.trim().contains(rarity + " " + typeMatches[j])) { - return j; - } else if (line.trim().contains(rarity + " DUNGEON " + typeMatches[j])) { - return j; - } - } else { - if (line.trim().endsWith(rarity + " " + typeMatches[j])) { - return j; - } else if (line.trim().endsWith(rarity + " DUNGEON " + typeMatches[j])) { - return j; - } - } - } - } - } - return -1; - } - - private final String[] romans = new String[]{ - "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", - "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XIX", "XX" - }; - - String[] categoryItemType = new String[]{ - "sword", "fishingrod", "pickaxe", "axe", - "shovel", "petitem", "travelscroll", "reforgestone", "bow" - }; - String playerUUID = null; - - private void processAuction(JsonObject auction) { - if (playerUUID == null) - playerUUID = Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replaceAll("-", ""); - - String auctionUuid = auction.get("uuid").getAsString(); - String auctioneerUuid = auction.get("auctioneer").getAsString(); - long end = auction.get("end").getAsLong(); - long starting_bid = auction.get("starting_bid").getAsLong(); - int highest_bid_amount = auction.get("highest_bid_amount").getAsInt(); - int bid_count = auction.get("bids").getAsJsonArray().size(); - boolean bin = false; - if (auction.has("bin")) { - bin = auction.get("bin").getAsBoolean(); - } - String sbCategory = auction.get("category").getAsString(); - String extras = auction.get("extra").getAsString().toLowerCase(); - String item_name = auction.get("item_name").getAsString(); - String item_lore = Utils.fixBrokenAPIColour(auction.get("item_lore").getAsString()); - String item_bytes = auction.get("item_bytes").getAsString(); - String rarity = auction.get("tier").getAsString(); - JsonArray bids = auction.get("bids").getAsJsonArray(); - - try { - NBTTagCompound item_tag; - try { - item_tag = CompressedStreamTools.readCompressed( - new ByteArrayInputStream(Base64.getDecoder().decode(item_bytes))); - } catch (IOException e) { - return; - } - - NBTTagCompound tag = item_tag.getTagList("i", 10).getCompoundTagAt(0).getCompoundTag("tag"); - String internalname = manager.getInternalnameFromNBT(tag); - - NBTTagCompound display = tag.getCompoundTag("display"); - if (display.hasKey("Lore", 9)) { - NBTTagList loreList = new NBTTagList(); - for (String line : item_lore.split("\n")) { - loreList.appendTag(new NBTTagString(line)); - } - display.setTag("Lore", loreList); - } - tag.setTag("display", display); - item_tag.getTagList("i", 10).getCompoundTagAt(0).setTag("tag", tag); - - if (tag.hasKey("ExtraAttributes", 10)) { - NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); - - if (ea.hasKey("enchantments", 10)) { - NBTTagCompound enchantments = ea.getCompoundTag("enchantments"); - for (String key : enchantments.getKeySet()) { - String enchantname = key.toLowerCase().replace("ultimate_", "").replace("_", " "); - int enchantlevel = enchantments.getInteger(key); - String enchantLevelStr; - if (enchantlevel >= 1 && enchantlevel <= 20) { - enchantLevelStr = romans[enchantlevel - 1]; - } else { - enchantLevelStr = String.valueOf(enchantlevel); - } - extras = extras.replace(enchantname, enchantname + " " + enchantLevelStr); - } - } - } - - int index = 0; - for (String str : extras.split(" ")) { - str = Utils.cleanColour(str).toLowerCase(); - if (str.length() > 0) { - HashMap> extrasMap = extrasToAucIdMap.computeIfAbsent(str, k -> new HashMap<>()); - HashSet aucids = extrasMap.computeIfAbsent(index, k -> new HashSet<>()); - aucids.add(auctionUuid); - } - index++; - } - - for (int j = 0; j < bids.size(); j++) { - JsonObject bid = bids.get(j).getAsJsonObject(); - if (bid.get("bidder").getAsString().equalsIgnoreCase(playerUUID)) { - playerBids.add(auctionUuid); - } - } - - int dungeonTier = -1; - if (checkItemType(item_lore, true, "DUNGEON") >= 0) { - dungeonTier = 0; - for (int i = 0; i < item_name.length(); i++) { - char c = item_name.charAt(i); - if (c == 0x272A) { - dungeonTier++; - } - } - } - - //Categories - String category = sbCategory; - int itemType = checkItemType(item_lore, true, "SWORD", "FISHING ROD", "PICKAXE", - "AXE", "SHOVEL", "PET ITEM", "TRAVEL SCROLL", "REFORGE STONE", "BOW" - ); - if (itemType >= 0 && itemType < categoryItemType.length) { - category = categoryItemType[itemType]; - } - if (category.equals("consumables") && extras.contains("enchanted book")) category = "ebook"; - if (category.equals("consumables") && extras.endsWith("potion")) category = "potion"; - if (category.equals("misc") && extras.contains("rune")) category = "rune"; - if (category.equals("misc") && item_lore.split("\n")[0].endsWith("Furniture")) category = "furniture"; - if (item_lore.split("\n")[0].endsWith("Pet") || - item_lore.split("\n")[0].endsWith("Mount")) category = "pet"; - - Auction auction1 = new Auction(auctioneerUuid, end, starting_bid, highest_bid_amount, - bid_count, bin, category, rarity, dungeonTier, item_bytes - ); - - if (tag.hasKey("ench")) { - auction1.enchLevel = 1; - if (tag.hasKey("ExtraAttributes", 10)) { - NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); - - int hotpotatocount = ea.getInteger("hot_potato_count"); - if (hotpotatocount == 10) { - auction1.enchLevel = 2; - } - } - } - - auctionMap.put(auctionUuid, auction1); - internalnameToAucIdMap.computeIfAbsent(internalname, k -> new HashSet<>()).add(auctionUuid); - } catch (Exception e) { - e.printStackTrace(); - } - } - - private void getPageFromAPI(int page) { - //System.out.println("downloading page:"+page); - //System.out.println("Trying to update page: " + page); - HashMap args = new HashMap<>(); - args.put("page", "" + page); - manager.apiUtils - .newAnonymousHypixelApiRequest("skyblock/auctions") - .requestJson() - .thenAcceptAsync(jsonObject -> { - if (jsonObject == null) return; - - if (jsonObject.get("success").getAsBoolean()) { - if (pagesToDownload == null) { - int totalPages = jsonObject.get("totalPages").getAsInt(); - pagesToDownload = new LinkedList<>(); - for (int i = 0; i < totalPages + 2; i++) { - pagesToDownload.add(i); - } - } - if (firstHypixelApiUpdate == 0) { - firstHypixelApiUpdate = jsonObject.get("lastUpdated").getAsLong(); - } - activeAuctions = jsonObject.get("totalAuctions").getAsInt(); - - long startProcess = System.currentTimeMillis(); - JsonArray auctions = jsonObject.get("auctions").getAsJsonArray(); - for (int i = 0; i < auctions.size(); i++) { - JsonObject auction = auctions.get(i).getAsJsonObject(); - - processAuction(auction); - } - processMillis = (int) (System.currentTimeMillis() - startProcess); - } else { - pagesToDownload.addLast(page); - } - }) - .handle((ignored, ex) -> { - if (ex != null) { - pagesToDownload.addLast(page); - } - return null; - }); - } - private static final Pattern BAZAAR_ENCHANTMENT_PATTERN = Pattern.compile("ENCHANTMENT_(\\D*)_(\\d+)"); public String transformHypixelBazaarToNEUItemId(String hypixelId) { @@ -872,11 +277,11 @@ public class APIManager { "ROOKIE_HOE" ); - public boolean isVanillaItem(String internalname) { - if (hardcodedVanillaItems.contains(internalname)) return true; + public boolean isVanillaItem(String internalName) { + if (hardcodedVanillaItems.contains(internalName)) return true; //Removes trailing numbers and underscores, eg. LEAVES_2-3 -> LEAVES - String vanillaName = internalname.split("-")[0]; + String vanillaName = internalName.split("-")[0]; if (manager.getItemInformation().containsKey(vanillaName)) { JsonObject json = manager.getItemInformation().get(vanillaName); if (json != null && json.has("vanilla") && json.get("vanilla").getAsBoolean()) return true; @@ -890,24 +295,24 @@ public class APIManager { public double craftCost = -1; } - public CraftInfo getCraftCost(String internalname) { - return getCraftCost(internalname, new HashSet<>()); + public CraftInfo getCraftCost(String internalName) { + return getCraftCost(internalName, new HashSet<>()); } /** * Recursively calculates the cost of crafting an item from raw materials. */ - private CraftInfo getCraftCost(String internalname, Set visited) { - if (craftCost.containsKey(internalname)) return craftCost.get(internalname); - if (visited.contains(internalname)) return null; - visited.add(internalname); + private CraftInfo getCraftCost(String internalName, Set visited) { + if (craftCost.containsKey(internalName)) return craftCost.get(internalName); + if (visited.contains(internalName)) return null; + visited.add(internalName); - boolean vanillaItem = isVanillaItem(internalname); + boolean vanillaItem = isVanillaItem(internalName); double craftCost = Double.POSITIVE_INFINITY; - JsonObject auctionInfo = getItemAuctionInfo(internalname); - double lowestBin = getLowestBin(internalname); - JsonObject bazaarInfo = getBazaarInfo(internalname); + JsonObject auctionInfo = getItemAuctionInfo(internalName); + double lowestBin = getLowestBin(internalName); + JsonObject bazaarInfo = getBazaarInfo(internalName); if (bazaarInfo != null && bazaarInfo.get("curr_buy") != null) { craftCost = bazaarInfo.get("curr_buy").getAsFloat(); @@ -922,7 +327,7 @@ public class APIManager { } } - Set recipes = manager.getRecipesFor(internalname); + Set recipes = manager.getRecipesFor(internalName); boolean fromRecipe = false; if (recipes != null) RECIPE_ITER: @@ -946,7 +351,7 @@ public class APIManager { } int resultCount = 0; for (Ingredient item : recipe.getOutputs()) - if (item.getInternalItemId().equals(internalname)) + if (item.getInternalItemId().equals(internalName)) resultCount += item.getCount(); if (resultCount == 0) @@ -957,7 +362,7 @@ public class APIManager { craftCost = craftPricePer; } } - visited.remove(internalname); + visited.remove(internalName); if (Double.isInfinite(craftCost)) { return null; } @@ -965,168 +370,7 @@ public class APIManager { craftInfo.vanillaItem = vanillaItem; craftInfo.craftCost = craftCost; craftInfo.fromRecipe = fromRecipe; - this.craftCost.put(internalname, craftInfo); + this.craftCost.put(internalName, craftInfo); return craftInfo; } - - /** - * Calculates the cost of enchants + other price modifiers such as pet xp, midas price, etc. - */ - public float getCostOfEnchants(String internalname, NBTTagCompound tag) { - float costOfEnchants = 0; - if (true) return 0; - - JsonObject info = getItemAuctionInfo(internalname); - if (info == null || !info.has("price")) { - return 0; - } - if (auctionPricesJson == null || !auctionPricesJson.has("ench_prices") || !auctionPricesJson.has("ench_maximums")) { - return 0; - } - JsonObject ench_prices = auctionPricesJson.getAsJsonObject("ench_prices"); - JsonObject ench_maximums = auctionPricesJson.getAsJsonObject("ench_maximums"); - if (!ench_prices.has(internalname) || !ench_maximums.has(internalname)) { - return 0; - } - JsonObject iid_variables = ench_prices.getAsJsonObject(internalname); - float ench_maximum = ench_maximums.get(internalname).getAsFloat(); - - int enchants = 0; - float price = getItemAuctionInfo(internalname).get("price").getAsFloat(); - if (tag.hasKey("ExtraAttributes")) { - NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); - if (ea.hasKey("enchantments")) { - - NBTTagCompound enchs = ea.getCompoundTag("enchantments"); - for (String ench : enchs.getKeySet()) { - enchants++; - int level = enchs.getInteger(ench); - - for (Map.Entry entry : iid_variables.entrySet()) { - if (matchEnch(ench, level, entry.getKey())) { - costOfEnchants += entry.getValue().getAsJsonObject().get("A").getAsFloat() * price + - entry.getValue().getAsJsonObject().get("B").getAsFloat(); - break; - } - } - } - } - } - return costOfEnchants; - } - - /** - * Checks whether a certain enchant (ench name + lvl) matches an enchant id - * eg. PROTECTION_GE6 will match -> ench_name = PROTECTION, lvl >= 6 - */ - private boolean matchEnch(String ench, int level, String id) { - if (!id.contains(":")) { - return false; - } - - String idEnch = id.split(":")[0]; - String idLevel = id.split(":")[1]; - - if (!ench.equalsIgnoreCase(idEnch)) { - return false; - } - - if (String.valueOf(level).equalsIgnoreCase(idLevel)) { - return true; - } - - if (idLevel.startsWith("LE")) { - int idLevelI = Integer.parseInt(idLevel.substring(2)); - return level <= idLevelI; - } else if (idLevel.startsWith("GE")) { - int idLevelI = Integer.parseInt(idLevel.substring(2)); - return level >= idLevelI; - } - - return false; - } - - /*ScheduledExecutorService auctionUpdateSES = Executors.newSingleThreadScheduledExecutor(); - private AtomicInteger auctionUpdateId = new AtomicInteger(0); - public void updateAuctions() { - HashMap pages = new HashMap<>(); - - HashMap args = new HashMap<>(); - args.put("page", "0"); - AtomicInteger totalPages = new AtomicInteger(1); - AtomicInteger currentPages = new AtomicInteger(0); - manager.hypixelApi.getHypixelApiAsync(NotEnoughUpdates.INSTANCE.config.apiKey.apiKey, "skyblock/auctions", - args, jsonObject -> { - if (jsonObject.get("success").getAsBoolean()) { - pages.put(0, jsonObject); - totalPages.set(jsonObject.get("totalPages").getAsInt()); - currentPages.incrementAndGet(); - - for (int i = 1; i < totalPages.get(); i++) { - int j = i; - HashMap args2 = new HashMap<>(); - args2.put("page", "" + i); - manager.hypixelApi.getHypixelApiAsync(NotEnoughUpdates.INSTANCE.config.apiKey.apiKey, "skyblock/auctions", - args2, jsonObject2 -> { - if (jsonObject2.get("success").getAsBoolean()) { - pages.put(j, jsonObject2); - currentPages.incrementAndGet(); - } else { - currentPages.incrementAndGet(); - } - } - ); - } - } - } - ); - - long startTime = System.currentTimeMillis(); - - int currentAuctionUpdateId = auctionUpdateId.incrementAndGet(); - - auctionUpdateSES.schedule(new Runnable() { - public void run() { - if(auctionUpdateId.get() != currentAuctionUpdateId) return; - System.out.println(currentPages.get() + "/" + totalPages.get()); - if (System.currentTimeMillis() - startTime > 20000) return; - - if (currentPages.get() == totalPages.get()) { - TreeMap auctionItemsTemp = new TreeMap<>(); - - for (int pageNum : pages.keySet()) { - System.out.println(pageNum + "/" + pages.size()); - JsonObject page = pages.get(pageNum); - JsonArray auctions = page.get("auctions").getAsJsonArray(); - for (int i = 0; i < auctions.size(); i++) { - JsonObject auction = auctions.get(i).getAsJsonObject(); - - String auctionUuid = auction.get("uuid").getAsString(); - String auctioneerUuid = auction.get("auctioneer").getAsString(); - long end = auction.get("end").getAsLong(); - int starting_bid = auction.get("starting_bid").getAsInt(); - int highest_bid_amount = auction.get("highest_bid_amount").getAsInt(); - int bid_count = auction.get("bids").getAsJsonArray().size(); - boolean bin = false; - if(auction.has("bin")) { - bin = auction.get("bin").getAsBoolean(); - } - String category = auction.get("category").getAsString(); - String extras = auction.get("item_lore").getAsString().replaceAll("\n"," ") + " " + - auction.get("extra").getAsString(); - String item_bytes = auction.get("item_bytes").getAsString(); - - auctionItemsTemp.put(auctionUuid, new Auction(auctioneerUuid, end, starting_bid, highest_bid_amount, - bid_count, bin, category, extras, item_bytes)); - } - } - auctionItems = auctionItemsTemp; - customAH.updateSearch(); - return; - } - - auctionUpdateSES.schedule(this, 1000L, TimeUnit.MILLISECONDS); - } - }, 3000L, TimeUnit.MILLISECONDS); - }*/ } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java b/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java deleted file mode 100644 index e1ccdef7..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/CustomAH.java +++ /dev/null @@ -1,2001 +0,0 @@ -/* - * Copyright (C) 2022 NotEnoughUpdates contributors - * - * This file is part of NotEnoughUpdates. - * - * NotEnoughUpdates is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * NotEnoughUpdates is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with NotEnoughUpdates. If not, see . - */ - -package io.github.moulberry.notenoughupdates.auction; - -import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.ItemPriceInformation; -import io.github.moulberry.notenoughupdates.NEUManager; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiTextField; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.gui.inventory.GuiChest; -import net.minecraft.client.gui.inventory.GuiEditSign; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.inventory.ContainerChest; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.tileentity.TileEntitySign; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL14; - -import java.awt.*; -import java.awt.datatransfer.StringSelection; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.ConcurrentModificationException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static io.github.moulberry.notenoughupdates.util.GuiTextures.auction_accept; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.auction_price; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.auction_view; -import static io.github.moulberry.notenoughupdates.util.GuiTextures.auction_view_buttons; - -public class CustomAH extends Gui { - private enum PriceFilter { - Greater, - Less, - Equal - } - - private static final ResourceLocation creativeTabSearch = - new ResourceLocation("textures/gui/container/creative_inventory/tab_item_search.png"); - private static final ResourceLocation creativeInventoryTabs = - new ResourceLocation("textures/gui/container/creative_inventory/tabs.png"); - - private HashSet auctionIds = new HashSet<>(); - private List sortedAuctionIds = new ArrayList<>(); - - private boolean scrollClicked = false; - - private long lastUpdateSearch; - private long lastSearchFieldUpdate; - private boolean shouldUpdateSearch = false; - private boolean shouldSortItems = false; - - private long startingBid = 0; - private String currentAucId = null; - - private int clickedMainCategory = -1; - private int clickedSubCategory = -1; - - private GuiTextField searchField = null; - private GuiTextField priceField = null; - private GuiTextField priceFilterField = null; - private GuiTextField binPriceFilterField = null; - - private final int binPriceFilterYOffset = 86; - - private boolean renderOverAuctionView = false; - private long lastRenderDisable = 0; - - private long currAucIdSetTimer = 0; - private long resetCurrAucIdTimer = 0; - - private int eventButton; - private long lastMouseEvent; - public long lastOpen; - public long lastGuiScreenSwitch; - private PriceFilter currentPriceFilterType = PriceFilter.Greater; - private PriceFilter currentBinPriceFilterType = PriceFilter.Greater; - - private final int splits = 2; - - public String latestBid; - public long latestBidMillis; - - private final int ySplit = 35; - private final int ySplitSize = 18; - - private float scrollAmount; - - public int guiLeft = -1; - public int guiTop = -1; - - private String lastSearch = ""; - - private final Category CATEGORY_SWORD = new Category("sword", "Swords", "diamond_sword"); - private final Category CATEGORY_ARMOR = new Category("armor", "Armor", "diamond_chestplate"); - private final Category CATEGORY_BOWS = new Category("bow", "Bows", "bow"); - private final Category CATEGORY_ACCESSORIES = new Category("accessories", "Accessories", "diamond"); - - private final Category CATEGORY_FISHING_ROD = new Category("fishingrod", "Fishing Rods", "fishing_rod"); - private final Category CATEGORY_PICKAXE = new Category("pickaxe", "Pickaxes", "iron_pickaxe"); - private final Category CATEGORY_AXE = new Category("axe", "Axes", "iron_axe"); - private final Category CATEGORY_SHOVEL = new Category("shovel", "Shovels", "iron_shovel"); - - private final Category CATEGORY_PET_ITEM = new Category("petitem", "Pet Items", "lead"); - - private final Category CATEGORY_EBOOKS = new Category("ebook", "Enchanted Books", "enchanted_book"); - private final Category CATEGORY_POTIONS = new Category("potion", "Potions", "potion"); - private final Category CATEGORY_TRAVEL_SCROLLS = new Category("travelscroll", "Travel Scrolls", "map"); - - private final Category CATEGORY_REFORGE_STONES = new Category("reforgestone", "Reforge Stones", "anvil"); - private final Category CATEGORY_RUNES = new Category("rune", "Runes", "magma_cream"); - private final Category CATEGORY_FURNITURE = new Category("furniture", "Furniture", "armor_stand"); - - private final Category CATEGORY_COMBAT = new Category("weapon", "Combat", "golden_sword", CATEGORY_SWORD, - CATEGORY_BOWS, CATEGORY_ARMOR, CATEGORY_ACCESSORIES - ); - private final Category CATEGORY_TOOL = new Category( - "", - "Tools", - "diamond_pickaxe", - CATEGORY_FISHING_ROD, - CATEGORY_PICKAXE, - CATEGORY_AXE, - CATEGORY_SHOVEL - ); - private final Category CATEGORY_PET = new Category("pet", "Pets", "bone", CATEGORY_PET_ITEM); - private final Category CATEGORY_CONSUMABLES = new Category( - "consumables", - "Consumables", - "apple", - CATEGORY_EBOOKS, - CATEGORY_POTIONS, - CATEGORY_TRAVEL_SCROLLS - ); - private final Category CATEGORY_BLOCKS = new Category("blocks", "Blocks", "cobblestone"); - private final Category CATEGORY_MISC = new Category("misc", "Misc", "stick", CATEGORY_REFORGE_STONES, CATEGORY_RUNES, - CATEGORY_FURNITURE - ); - - private final Category[] mainCategories = new Category[]{ - CATEGORY_COMBAT, CATEGORY_TOOL, CATEGORY_PET, - CATEGORY_CONSUMABLES, CATEGORY_BLOCKS, CATEGORY_MISC - }; - - private static final int SORT_MODE_HIGH = 0; - private static final int SORT_MODE_LOW = 1; - private static final int SORT_MODE_SOON = 2; - - private static final String[] rarityColours = { - "" + EnumChatFormatting.WHITE, - "" + EnumChatFormatting.GREEN, "" + EnumChatFormatting.BLUE, "" + EnumChatFormatting.DARK_PURPLE, - "" + EnumChatFormatting.GOLD, "" + EnumChatFormatting.LIGHT_PURPLE, "" + EnumChatFormatting.RED, - "" + EnumChatFormatting.RED, "" + EnumChatFormatting.AQUA, "" + EnumChatFormatting.AQUA - }; - - private static final int BIN_FILTER_ALL = 0; - private static final int BIN_FILTER_BIN = 1; - private static final int BIN_FILTER_AUC = 2; - - private static final int ENCH_FILTER_ALL = 0; - private static final int ENCH_FILTER_CLEAN = 1; - private static final int ENCH_FILTER_ENCH = 2; - private static final int ENCH_FILTER_ENCHHPB = 3; - - private static final int DUNGEON_FILTER_ALL = 0; - private static final int DUNGEON_FILTER_DUNGEON = 1; - private static final int DUNGEON_FILTER_1 = 2; - private static final int DUNGEON_FILTER_2 = 3; - private static final int DUNGEON_FILTER_3 = 4; - private static final int DUNGEON_FILTER_4 = 5; - private static final int DUNGEON_FILTER_5 = 6; - - private int dungeonFilter = DUNGEON_FILTER_ALL; - private int sortMode = SORT_MODE_HIGH; - private int rarityFilter = -1; - private boolean filterMyAuctions = false; - private int binFilter = BIN_FILTER_ALL; - private int enchFilter = ENCH_FILTER_ALL; - - private static final ItemStack DUNGEON_SORT = Utils.createItemStack( - Item.getItemFromBlock(Blocks.deadbush), - EnumChatFormatting.GREEN + "Dungeon Sorting" - ); - private static final ItemStack CONTROL_SORT = Utils.createItemStack( - Item.getItemFromBlock(Blocks.hopper), - EnumChatFormatting.GREEN + "Sort" - ); - private static final ItemStack CONTROL_TIER = Utils.createItemStack( - Items.ender_eye, - EnumChatFormatting.GREEN + "Item Tier" - ); - private static final ItemStack CONTROL_MYAUC = Utils.createItemStack( - Items.gold_ingot, - EnumChatFormatting.GREEN + "My Auctions" - ); - private static final ItemStack CONTROL_BIN = Utils.createItemStack( - Item.getItemFromBlock(Blocks.golden_rail), - EnumChatFormatting.GREEN + "BIN Filter" - ); - private static final ItemStack CONTROL_ENCH = Utils.createItemStack( - Items.enchanted_book, - EnumChatFormatting.GREEN + "Enchant Filter" - ); - private static final ItemStack CONTROL_STATS = Utils.createItemStack( - Item.getItemFromBlock(Blocks.command_block), - EnumChatFormatting.GREEN + "Stats for nerds" - ); - private final ItemStack[] controls = - {DUNGEON_SORT, CONTROL_SORT, CONTROL_TIER, null, CONTROL_MYAUC, null, CONTROL_BIN, CONTROL_ENCH, CONTROL_STATS}; - - private final NEUManager manager; - - public CustomAH(NEUManager manager) { - this.manager = manager; - } - - public void clearSearch() { - if (searchField == null || priceField == null) init(); - if (System.currentTimeMillis() - lastOpen < 1000) Mouse.setGrabbed(false); - - rarityFilter = -1; - filterMyAuctions = false; - enchFilter = ENCH_FILTER_ALL; - dungeonFilter = DUNGEON_FILTER_ALL; - - searchField.setText(""); - searchField.setFocused(true); - priceField.setText(""); - } - - public void setSearch(String search) { - if (search == null) { - searchField.setText(lastSearch); - } else { - searchField.setText(search); - } - updateSearch(); - } - - public void tick() { - if (!NotEnoughUpdates.INSTANCE.config.neuAuctionHouse.enableNeuAuctionHouse) return; - if (Minecraft.getMinecraft().currentScreen instanceof CustomAHGui || renderOverAuctionView) { - if (shouldUpdateSearch) updateSearch(); - if (shouldSortItems) { - sortItems(); - shouldSortItems = false; - } - } - } - - public static class Category { - public String categoryMatch; - public Category[] subcategories; - public String displayName; - public ItemStack displayItem; - - public Category(String categoryMatch, String displayName, String displayItem, Category... subcategories) { - this.categoryMatch = categoryMatch; - this.subcategories = subcategories; - this.displayName = displayName; - this.displayItem = new ItemStack(Item.getByNameOrId(displayItem)); - } - - public String[] getTotalCategories() { - String[] categories = new String[1 + subcategories.length]; - categories[0] = categoryMatch; - - for (int i = 0; i < subcategories.length; i++) { - categories[i + 1] = subcategories[i].categoryMatch; - } - return categories; - } - } - - private void init() { - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - this.searchField = new GuiTextField(0, fr, this.guiLeft + 82, this.guiTop + 6, - 84, fr.FONT_HEIGHT - ); - this.priceField = new GuiTextField(1, fr, this.guiLeft + 82, this.guiTop + 6, - 84, fr.FONT_HEIGHT - ); - this.priceFilterField = new GuiTextField(2, fr, this.guiLeft + 82, this.guiTop + 6, - 84, fr.FONT_HEIGHT - ); - this.binPriceFilterField = new GuiTextField(3, fr, this.guiLeft + 82, this.guiTop - 6, 84, fr.FONT_HEIGHT); - - this.searchField.setMaxStringLength(30); - this.searchField.setEnableBackgroundDrawing(false); - this.searchField.setTextColor(16777215); - this.searchField.setVisible(true); - this.searchField.setCanLoseFocus(true); - this.searchField.setFocused(true); - this.searchField.setText(""); - - this.priceField.setMaxStringLength(10); - this.priceField.setEnableBackgroundDrawing(false); - this.priceField.setTextColor(16777215); - this.priceField.setVisible(true); - this.priceField.setCanLoseFocus(true); - this.priceField.setFocused(false); - this.priceField.setText(""); - - this.priceFilterField.setMaxStringLength(10); - this.priceFilterField.setEnableBackgroundDrawing(false); - this.priceFilterField.setTextColor(16777215); - this.priceFilterField.setVisible(true); - this.priceFilterField.setCanLoseFocus(true); - this.priceFilterField.setFocused(false); - this.priceFilterField.setText(""); - - this.binPriceFilterField.setMaxStringLength(10); - this.binPriceFilterField.setEnableBackgroundDrawing(false); - this.binPriceFilterField.setTextColor(16777215); - this.binPriceFilterField.setVisible(true); - this.binPriceFilterField.setCanLoseFocus(true); - this.binPriceFilterField.setFocused(false); - this.binPriceFilterField.setText(""); - } - - public boolean isRenderOverAuctionView() { - return renderOverAuctionView || (System.currentTimeMillis() - lastRenderDisable) < 500; - } - - public void setRenderOverAuctionView(boolean renderOverAuctionView) { - if (this.renderOverAuctionView && !renderOverAuctionView) lastRenderDisable = System.currentTimeMillis(); - this.renderOverAuctionView = renderOverAuctionView; - } - - public int getXSize() { - return 195; - } - - public int getYSize() { - return 136 + ySplitSize * splits; - } - - private String prettyTime(long millis) { - long seconds = millis / 1000 % 60; - long minutes = (millis / 1000 / 60) % 60; - long hours = (millis / 1000 / 60 / 60) % 24; - long days = (millis / 1000 / 60 / 60 / 24); - - String endsIn = ""; - if (millis < 0) { - endsIn += "Ended!"; - } else if (minutes == 0 && hours == 0 && days == 0) { - endsIn += seconds + "s"; - } else if (hours == 0 && days == 0) { - endsIn += minutes + "m" + seconds + "s"; - } else if (days == 0) { - if (hours <= 6) { - endsIn += hours + "h" + minutes + "m" + seconds + "s"; - } else { - endsIn += hours + "h"; - } - } else { - endsIn += days + "d" + hours + "h"; - } - - return endsIn; - } - - public List getTooltipForAucId(String aucId) { - APIManager.Auction auc = manager.auctionManager.getAuctionItems().get(aucId); - - List tooltip = new ArrayList<>(); - - for (String line : auc.getStack().getTooltip(Minecraft.getMinecraft().thePlayer, false)) { - tooltip.add(EnumChatFormatting.GRAY + line); - } - - long timeUntilEnd = auc.end - System.currentTimeMillis(); - String endsIn = EnumChatFormatting.YELLOW + prettyTime(timeUntilEnd); - - NumberFormat format = NumberFormat.getInstance(Locale.US); - - tooltip.add(EnumChatFormatting.DARK_GRAY + "" + EnumChatFormatting.STRIKETHROUGH + "-----------------"); - tooltip.add(EnumChatFormatting.GRAY + "Seller: [CLICK TO SEE]"); - - if (auc.bin) { - tooltip.add(EnumChatFormatting.GRAY + "Buy it now: " + - EnumChatFormatting.GOLD + format.format(auc.starting_bid)); - } else { - if (auc.bid_count > 0) { - tooltip.add(EnumChatFormatting.GRAY + "Bids: " + EnumChatFormatting.GREEN + auc.bid_count + " bids"); - tooltip.add(""); - tooltip.add(EnumChatFormatting.GRAY + "Top bid: " + - EnumChatFormatting.GOLD + format.format(auc.highest_bid_amount)); - tooltip.add(EnumChatFormatting.GRAY + "Bidder: [CLICK TO SEE]"); - } else { - tooltip.add(EnumChatFormatting.GRAY + "Starting bid: " + - EnumChatFormatting.GOLD + format.format(auc.starting_bid)); - } - } - - if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.showPriceInfoAucItem) { - String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(auc.getStack()); - if (internalname != null) { - if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) && !Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) { - tooltip.add(""); - tooltip.add(EnumChatFormatting.GRAY + "[SHIFT for Price Info]"); - } else { - ItemPriceInformation.addToTooltip(tooltip, internalname, auc.getStack()); - } - } - } - - tooltip.add(""); - tooltip.add(EnumChatFormatting.GRAY + "Ends in: " + endsIn); - tooltip.add(""); - tooltip.add(EnumChatFormatting.YELLOW + "Click to inspect!"); - - return tooltip; - } - - public boolean isEditingPrice() { - return Minecraft.getMinecraft().currentScreen instanceof GuiEditSign; - } - - private boolean isGuiFiller(ItemStack stack) { - return stack == null || !stack.hasTagCompound() || !stack.getTagCompound().hasKey("AttributeModifiers"); - } - - private void drawCategorySide(int i) { - boolean clicked = i == clickedSubCategory; - - int x = guiLeft - 28; - int y = guiTop + 17 + 28 * (i + 1); - float uMin = 28 / 256f; - float uMax = 56 / 256f; - float vMin = 0 + (clicked ? 32 / 256f : 0); - float vMax = 32 / 256f + (clicked ? 32 / 256f : 0); - float catWidth = 32; - float catHeight = 28; - - GlStateManager.enableTexture2D(); - GlStateManager.enableBlend(); - GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); - - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldrenderer = tessellator.getWorldRenderer(); - worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); - worldrenderer - .pos(x, y + catHeight, 0.0D) - .tex(uMax, vMin).endVertex(); - worldrenderer - .pos(x + catWidth, y + catHeight, 0.0D) - .tex(uMax, vMax).endVertex(); - worldrenderer - .pos(x + catWidth, y, 0.0D) - .tex(uMin, vMax).endVertex(); - worldrenderer - .pos(x, y, 0.0D) - .tex(uMin, vMin).endVertex(); - tessellator.draw(); - - GlStateManager.disableBlend(); - } - - private final HashMap timeParseMap = new HashMap() {{ - Pattern dayPattern = Pattern.compile("([0-9]+)d"); - Pattern hourPattern = Pattern.compile("([0-9]+)h"); - Pattern minutePattern = Pattern.compile("([0-9]+)m"); - Pattern secondPattern = Pattern.compile("([0-9]+)s"); - - put(dayPattern, 24 * 60 * 60 * 1000L); - put(hourPattern, 60 * 60 * 1000L); - put(minutePattern, 60 * 1000L); - put(secondPattern, 1000L); - }}; - - public long prettyTimeToMillis(String endsInStr) { - if (endsInStr != null) { - long timeUntilEnd = 0; - - String timeStr = Utils.cleanColour(endsInStr); - - for (Map.Entry timeEntry : timeParseMap.entrySet()) { - Matcher matcher = timeEntry.getKey().matcher(timeStr); - if (matcher.find()) { - String days = matcher.group(1); - timeUntilEnd += Long.parseLong(days) * timeEntry.getValue(); - } - } - - return timeUntilEnd; - } - - return -1; - } - - public String findStrStart(ItemStack stack, String toFind) { - if (stack.hasTagCompound()) { - //ยง7Ends in: - for (String line : manager.getLoreFromNBT(stack.getTagCompound())) { - if (line.trim().startsWith(toFind)) { - return line.substring(toFind.length()); - } - } - } - - return null; - } - - public String findEndsInStr(ItemStack stack) { - return findStrStart(stack, EnumChatFormatting.GRAY + "Ends in: "); - } - - public void drawScreen(int mouseX, int mouseY) { - if (System.currentTimeMillis() - lastOpen < 1000) Mouse.setGrabbed(false); - - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - int width = scaledResolution.getScaledWidth(); - int height = scaledResolution.getScaledHeight(); - - boolean hasPopup = false; - - if (searchField == null || priceField == null || priceFilterField == null) init(); - - GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - - guiLeft = (width - getXSize()) / 2; - guiTop = (height - getYSize()) / 2; - this.searchField.xPosition = guiLeft + 82; - this.searchField.yPosition = guiTop + 6; - - if (!isEditingPrice()) priceField.setText("IAUSHDIUAH"); - - if ((Minecraft.getMinecraft().currentScreen instanceof GuiChest || - Minecraft.getMinecraft().currentScreen instanceof GuiEditSign) && currentAucId == null) { - Minecraft.getMinecraft().displayGuiScreen(null); - } - - List tooltipToRender = null; - int black = Color.BLACK.getRGB(); - if (Minecraft.getMinecraft().currentScreen instanceof GuiChest) { - resetCurrAucIdTimer = System.currentTimeMillis(); - GuiChest auctionView = (GuiChest) Minecraft.getMinecraft().currentScreen; - ContainerChest container = (ContainerChest) auctionView.inventorySlots; - String containerName = container.getLowerChestInventory().getDisplayName().getUnformattedText(); - - float slideAmount = 1 - Math.max(0, Math.min(1, (System.currentTimeMillis() - lastGuiScreenSwitch) / 200f)); - int auctionViewLeft = guiLeft + getXSize() + 4 - (int) (slideAmount * (78 + 4)); - if (containerName.trim().equals("Auction View") || containerName.trim().equals("BIN Auction View")) { - hasPopup = true; - Minecraft.getMinecraft().getTextureManager().bindTexture(auction_view); - this.drawTexturedModalRect(auctionViewLeft, guiTop, 0, 0, 78, 172); - - if (auctionViewLeft + 31 > guiLeft + getXSize()) { - try { - ItemStack topStack = auctionView.inventorySlots.getSlot(13).getStack(); - ItemStack leftStack = auctionView.inventorySlots.getSlot(29).getStack(); - ItemStack middleStack = auctionView.inventorySlots.getSlot(31).getStack(); - ItemStack rightStack = auctionView.inventorySlots.getSlot(33).getStack(); - - boolean isBin = isGuiFiller(leftStack) || isGuiFiller(leftStack); - - if (isBin) { - leftStack = middleStack; - middleStack = null; - } - - String endsInStr = findEndsInStr(topStack); - if (endsInStr != null) { - long auctionViewEndsIn = prettyTimeToMillis(endsInStr); - if (auctionViewEndsIn > 0) { - if (System.currentTimeMillis() - currAucIdSetTimer > 1000) { - APIManager.Auction auc = manager.auctionManager.getAuctionItems().get(currentAucId); - if (auc != null) { - auc.end = auctionViewEndsIn + lastGuiScreenSwitch; - } - } - endsInStr = EnumChatFormatting.DARK_PURPLE + prettyTime( - auctionViewEndsIn + lastGuiScreenSwitch - System.currentTimeMillis()); - } - Utils.drawStringCenteredScaledMaxWidth(endsInStr, auctionViewLeft + 39, guiTop + 20, false, 70, 4210752); - } - - Utils.drawItemStack(leftStack, auctionViewLeft + 31, guiTop + 100); - - if (!isGuiFiller(leftStack)) { - NBTTagCompound tag = leftStack.getTagCompound(); - NBTTagCompound display = tag.getCompoundTag("display"); - if (display.hasKey("Lore", 9)) { - NBTTagList list = display.getTagList("Lore", 8); - String line2 = list.getStringTagAt(1); - line2 = Utils.cleanColour(line2); - StringBuilder priceNumbers = new StringBuilder(); - for (int i = 0; i < line2.length(); i++) { - char c = line2.charAt(i); - if ((int) c >= 48 && (int) c <= 57) { - priceNumbers.append(c); - } - } - if (priceNumbers.length() > 0) { - startingBid = Long.parseLong(priceNumbers.toString()); - } - } - } - - Utils.drawItemStack(topStack, auctionViewLeft + 31, guiTop + 35); - - if (!isGuiFiller(middleStack)) { - Minecraft.getMinecraft().getTextureManager().bindTexture(auction_view_buttons); - boolean hover = mouseX > auctionViewLeft + 31 && mouseX < auctionViewLeft + 31 + 16 && - mouseY > guiTop + 126 && mouseY < guiTop + 126 + 16; - this.drawTexturedModalRect(auctionViewLeft + 31, guiTop + 126, hover ? 16 : 0, 0, 16, 16); - } else { - middleStack = null; - } - - if (mouseX > auctionViewLeft + 31 && mouseX < auctionViewLeft + 31 + 16) { - if (mouseY > guiTop + 35 && mouseY < guiTop + 35 + 16) { - if (topStack != null) { - tooltipToRender = topStack.getTooltip(Minecraft.getMinecraft().thePlayer, false); - tooltipToRender.add(""); - tooltipToRender.add(EnumChatFormatting.YELLOW + "Click to copy seller name!"); - } - } else if (mouseY > guiTop + 100 && mouseY < guiTop + 100 + 16) { - if (leftStack != null) - tooltipToRender = leftStack.getTooltip(Minecraft.getMinecraft().thePlayer, false); - } else if (mouseY > guiTop + 61 && mouseY < guiTop + 61 + 16) { - tooltipToRender = new ArrayList<>(); - APIManager.Auction auc = manager.auctionManager.getAuctionItems().get(currentAucId); - if (auc != null) { - tooltipToRender.add(EnumChatFormatting.WHITE + "Price Info"); - - String internalname = manager.getInternalNameForItem(auc.getStack()); - JsonObject auctionInfo = manager.auctionManager.getItemAuctionInfo(internalname); - JsonObject bazaarInfo = manager.auctionManager.getBazaarInfo(internalname); - - boolean hasAuctionPrice = auctionInfo != null; - boolean hasBazaarPrice = bazaarInfo != null; - - long lowestBin = manager.auctionManager.getLowestBin(internalname); - - NumberFormat format = NumberFormat.getInstance(Locale.US); - - APIManager.CraftInfo craftCost = manager.auctionManager.getCraftCost(internalname); - - if (lowestBin > 0) { - tooltipToRender.add( - EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Lowest BIN: " + - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + format.format(lowestBin) + " coins"); - } - if (hasBazaarPrice) { - int bazaarBuyPrice = (int) bazaarInfo.get("avg_buy").getAsFloat(); - tooltipToRender.add( - EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Bazaar Buy: " + - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + format.format(bazaarBuyPrice) + " coins"); - int bazaarSellPrice = (int) bazaarInfo.get("avg_sell").getAsFloat(); - tooltipToRender.add( - EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Bazaar Sell: " + - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + format.format(bazaarSellPrice) + " coins"); - int bazaarInstantBuyPrice = (int) bazaarInfo.get("curr_buy").getAsFloat(); - tooltipToRender.add( - EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Bazaar Insta-Buy: " + - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + format.format(bazaarInstantBuyPrice) + - " coins"); - int bazaarInstantSellPrice = (int) bazaarInfo.get("curr_sell").getAsFloat(); - tooltipToRender.add( - EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Bazaar Insta-Sell: " + - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + format.format(bazaarInstantSellPrice) + - " coins"); - } - if (hasAuctionPrice) { - int auctionPrice = - (int) (auctionInfo.get("price").getAsFloat() / auctionInfo.get("count").getAsFloat()); - tooltipToRender.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "AH Price: " + - EnumChatFormatt