From 112341e9a72e1f3a6e07cd3c38b1fcba6f222ce4 Mon Sep 17 00:00:00 2001 From: Lulonaut <67191924+Lulonaut@users.noreply.github.com> Date: Thu, 2 Dec 2021 12:21:33 +0100 Subject: Add warning to tooltip when price info is not there/outdated (#27) * Make fairy souls save per profile * fix commands * Add back support for toggling in /neu * add patch notes * Add warning when price info couldn't be found is outdated --- .../notenoughupdates/ItemPriceInformation.java | 20 ++++++++++++++++---- .../notenoughupdates/auction/APIManager.java | 8 +++++++- 2 files changed, 23 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java b/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java index 8fbb7c40..b563906e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java @@ -34,12 +34,21 @@ public class ItemPriceInformation { int lowestBin = NotEnoughUpdates.INSTANCE.manager.auctionManager.getLowestBin(internalname); APIManager.CraftInfo craftCost = NotEnoughUpdates.INSTANCE.manager.auctionManager.getCraftCost(internalname); - boolean auctionItem = lowestBin > 0 || lowestBinAvg > 0 || auctionInfo != null; + boolean auctionItem = lowestBin > 0 || lowestBinAvg > 0; + boolean auctionInfoErrored = auctionInfo == null; + if (auctionItem) { + long currentTime = System.currentTimeMillis(); + long lastUpdate = NotEnoughUpdates.INSTANCE.manager.auctionManager.getLastLowestBinUpdateTime(); + //check if info is older than 10 minutes + if (currentTime - lastUpdate > 600 * 1000) { + tooltip.add(EnumChatFormatting.RED + "[NEU] Price info is outdated by more than 10 minutes.\nIt will updated again as soon as the server can be reached again."); + } + } + boolean bazaarItem = bazaarInfo != null; NumberFormat format = NumberFormat.getInstance(Locale.US); boolean shortNumber = NotEnoughUpdates.INSTANCE.config.tooltipTweaks.shortNumberFormatPrices; - if (bazaarItem) { List lines = NotEnoughUpdates.INSTANCE.config.tooltipTweaks.priceInfoBaz; @@ -139,7 +148,7 @@ public class ItemPriceInformation { added = true; } tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Lowest BIN: " + - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + (shortNumber && lowestBin > 1000 ? Utils.shortNumberFormat(lowestBin, 0) : format.format(lowestBin)) + " coins"); + EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + format.format(lowestBin) + " coins"); } break; case 1: @@ -152,7 +161,7 @@ public class ItemPriceInformation { if (auctionInfo.has("clean_price")) { tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "AH Price (Clean): " + EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + (shortNumber && auctionInfo.get("clean_price").getAsFloat() > 1000 ? Utils.shortNumberFormat(auctionInfo.get("clean_price").getAsFloat(), 0) : format.format((int) auctionInfo.get("clean_price").getAsFloat()) - + " coins")); + + " coins")); } else { int auctionPrice = (int) (auctionInfo.get("price").getAsFloat() / auctionInfo.get("count").getAsFloat()); tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "AH Price: " + EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + @@ -246,6 +255,9 @@ 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; } return false; 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 6b421192..70b9e312 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java @@ -206,7 +206,6 @@ public class APIManager { updateBazaar(); } if (currentTime - lastLowestBinUpdate > 2 * 60 * 1000) { - lastLowestBinUpdate = currentTime; updateLowestBin(); } } @@ -251,6 +250,9 @@ public class APIManager { if (lowestBins == null) { lowestBins = new JsonObject(); } + if (!jsonObject.entrySet().isEmpty()) { + lastLowestBinUpdate = System.currentTimeMillis(); + } for (Map.Entry entry : jsonObject.entrySet()) { lowestBins.add(entry.getKey(), entry.getValue()); } @@ -294,6 +296,10 @@ public class APIManager { } } + public long getLastLowestBinUpdateTime() { + return lastLowestBinUpdate; + } + private final ExecutorService es = Executors.newSingleThreadExecutor(); private void cleanup() { -- cgit