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/github/moulberry/notenoughupdates/ItemPriceInformation.java | |
| 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/github/moulberry/notenoughupdates/ItemPriceInformation.java')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java | 46 |
1 files changed, 44 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; |
