diff options
author | Lulonaut <67191924+Lulonaut@users.noreply.github.com> | 2021-12-11 05:13:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-11 15:13:04 +1100 |
commit | 9f8867018ef7232c1e17af54c9818ddcafa26759 (patch) | |
tree | f97b7f1c3ebbaf8845b73c82f07b1e75a8c02b3b /src/main/java/io | |
parent | 9475677afdb86078f3c014b52ef1b0a414f3c5e5 (diff) | |
download | NotEnoughUpdates-9f8867018ef7232c1e17af54c9818ddcafa26759.tar.gz NotEnoughUpdates-9f8867018ef7232c1e17af54c9818ddcafa26759.tar.bz2 NotEnoughUpdates-9f8867018ef7232c1e17af54c9818ddcafa26759.zip |
Store auctionable items locally to only show price warning if the item can actually have a price (#29)
Diffstat (limited to 'src/main/java/io')
3 files changed, 51 insertions, 2 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java b/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java index b563906e..43689d3a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java @@ -1,5 +1,6 @@ package io.github.moulberry.notenoughupdates; +import com.google.gson.Gson; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.auction.APIManager; import io.github.moulberry.notenoughupdates.core.config.KeybindHelper; @@ -10,16 +11,46 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; import org.lwjgl.input.Keyboard; +import java.io.*; +import java.nio.charset.StandardCharsets; import java.text.NumberFormat; +import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.Set; public class ItemPriceInformation { + private static File file; + private static HashSet<String> auctionableItems = null; + private static Gson gson; public static boolean addToTooltip(List<String> tooltip, String internalname, ItemStack stack) { return addToTooltip(tooltip, internalname, stack, true); } + public static void init(File saveLocation, Gson neuGson) { + file = saveLocation; + gson = neuGson; + if (file.exists()) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) { + auctionableItems = gson.fromJson(reader, HashSet.class); + } catch (Exception ignored) {} + } + } + + public static void updateAuctionableItemsList() { + Set<String> items = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfoKeySet(); + if (!items.isEmpty()) { + auctionableItems = (HashSet<String>) items; + try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8))) { + //noinspection ResultOfMethodCallIgnored + file.createNewFile(); + writer.write(gson.toJson(items)); + } catch (IOException ignored) { + } + } + } + public static boolean addToTooltip(List<String> tooltip, String internalname, ItemStack stack, boolean useStackSize) { if (stack.getTagCompound().hasKey("disableNeuTooltip") && stack.getTagCompound().getBoolean("disableNeuTooltip")) { return false; @@ -27,6 +58,9 @@ public class ItemPriceInformation { if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.disablePriceKey && !KeybindHelper.isKeyDown(NotEnoughUpdates.INSTANCE.config.tooltipTweaks.disablePriceKeyKeybind)) { return false; } + if (internalname.equals("SKYBLOCK_MENU")) { + return false; + } JsonObject auctionInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname); JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname); float lowestBinAvg = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAvgBin(internalname); @@ -256,8 +290,16 @@ public class ItemPriceInformation { return added; } else if (auctionInfoErrored) { - tooltip.add(EnumChatFormatting.RED.toString() + EnumChatFormatting.BOLD + "[NEU] Can't find price info! Please be patient."); - return true; + String message = EnumChatFormatting.RED.toString() + EnumChatFormatting.BOLD + "[NEU] API is down"; + if (auctionableItems != null && !auctionableItems.isEmpty()) { + if (auctionableItems.contains(internalname)) { + tooltip.add(message); + return true; + } + } else { + tooltip.add(message + " and no item data is cached"); + return true; + } } return false; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 29eaf38e..c1e1cd0d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -127,6 +127,7 @@ public class NotEnoughUpdates { FairySouls.load(new File(neuDir, "collected_fairy_souls.json"), gson); PetInfoOverlay.loadConfig(new File(neuDir, "petCache.json")); SlotLocking.getInstance().loadConfig(new File(neuDir, "slotLocking.json")); + ItemPriceInformation.init(new File(neuDir, "auctionable_items.json"), gson); if (config == null) { config = new NEUConfig(); 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 70b9e312..6726093d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java @@ -3,6 +3,7 @@ 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.util.Constants; @@ -50,6 +51,7 @@ public class APIManager { public TreeMap<String, HashMap<Integer, HashSet<String>>> extrasToAucIdMap = new TreeMap<>(); + private boolean didFirstUpdate = false; private long lastAuctionUpdate = 0; private long lastShortAuctionUpdate = 0; private long lastCustomAHSearch = 0; @@ -256,6 +258,10 @@ public class APIManager { for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) { lowestBins.add(entry.getKey(), entry.getValue()); } + if (!didFirstUpdate) { + ItemPriceInformation.updateAuctionableItemsList(); + didFirstUpdate = true; + } }, () -> {}); } |