From 3bbf5f7ce3acfa6fa4bfe969a6f8125760618ad9 Mon Sep 17 00:00:00 2001 From: Fix3dll Date: Mon, 21 Feb 2022 02:49:56 +0300 Subject: little fix for other items, change TimerTask to Scheduler --- .../skyblocker/skyblock/item/PriceInfoTooltip.java | 162 ++++++++++++--------- 1 file changed, 94 insertions(+), 68 deletions(-) (limited to 'src/main/java/me/xmrvizzy') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java index daad1d26..b48bcbc9 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java @@ -2,6 +2,7 @@ package me.xmrvizzy.skyblocker.skyblock.item; import com.google.gson.Gson; import com.google.gson.JsonObject; +import me.xmrvizzy.skyblocker.SkyblockerMod; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import net.minecraft.client.MinecraftClient; import net.minecraft.client.item.TooltipContext; @@ -9,6 +10,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; +import net.minecraft.text.TranslatableText; import net.minecraft.util.Formatting; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; @@ -20,105 +22,113 @@ import java.net.URL; import java.time.Month; import java.util.List; import java.util.Locale; -import java.util.Timer; -import java.util.TimerTask; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; import java.util.zip.GZIPInputStream; public class PriceInfoTooltip { + private static final SkyblockerMod skyblocker = SkyblockerMod.getInstance(); private static JsonObject npcPricesJson; private static JsonObject bazaarPricesJson; private static JsonObject avgPricesJson; private static JsonObject lowestPricesJson; private static JsonObject isMuseumJson; + private static boolean nullMsgSend = false; + private final static Gson gson = new Gson(); public static void onInjectTooltip(ItemStack stack, TooltipContext context, List lines) { int count = stack.getCount(); String name = getInternalNameFromNBT(stack); String timestamp = getTimestamp(stack); List listString = lines.stream() - .map(Text::getString) - .collect(Collectors.toList()); + .map(Text::getString).toList(); try { - if (SkyblockerConfig.get().general.itemTooltip.enableNPCPrice - && !listString.contains("NPC Price") && npcPricesJson != null && npcPricesJson.has(name)) { - - lines.add(new LiteralText(String.format("%-21s", "NPC Price:")) - .formatted(Formatting.YELLOW) - .append(getCoinsMessage(npcPricesJson.get(name).getAsDouble(), count))); + if (SkyblockerConfig.get().general.itemTooltip.enableNPCPrice && !listString.contains("NPC Price")) { + if (npcPricesJson.has(name)) { + lines.add(new LiteralText(String.format("%-21s", "NPC Price:")) + .formatted(Formatting.YELLOW) + .append(getCoinsMessage(npcPricesJson.get(name).getAsDouble(), count))); + } } - if ((!listString.contains("Avg. BIN Price") && avgPricesJson != null && avgPricesJson.has(name)) - || (!listString.contains("Lowest BIN Price") && lowestPricesJson != null && lowestPricesJson.has(name))) { + if ((!listString.contains("Avg. BIN Price") && avgPricesJson.has(name)) + || (!listString.contains("Lowest BIN Price") && lowestPricesJson.has(name))) { - if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN) { + if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN && lowestPricesJson.has(name)) { lines.add(new LiteralText(String.format("%-19s", "Lowest BIN Price:")) .formatted(Formatting.GOLD) .append(getCoinsMessage(lowestPricesJson.get(name).getAsDouble(), count))); } - // Change format from Skytils to Moulberry's for Avg. BIN if (name.contains("PET-")) { name = name.replace("PET-", "") - .replace("0", "COMMON") - .replace("1", "UNCOMMON") - .replace("2", "RARE") - .replace("3", "EPIC") - .replace("4", "LEGENDARY") - .replace("5", "MYTHIC") + .replace("COMMON", "0") + .replace("UNCOMMON", "1") + .replace("RARE", "2") + .replace("EPIC", "3") + .replace("LEGENDARY", "4") + .replace("MYTHIC", "5") .replace("-", ";"); } else if (name.contains("ENCHANTED_BOOK-")) { name = name.replace("ENCHANTED_BOOK-", "").replace("-", ";"); + } else if (name.contains("POTION-")) { + name = "POTION"; + } else if (name.contains("RUNE-")) { + name = "RUNE"; } else { name = name.replace(":", "-"); } - // has(name) check because Skytils keeps old data but Moulberry not if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN && avgPricesJson.has(name)) { lines.add(new LiteralText(String.format("%-21s", "Avg. BIN Price:")) .formatted(Formatting.GOLD) .append(getCoinsMessage(avgPricesJson.get(name).getAsDouble(), count))); } } else if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice - && (!listString.contains("Bazaar buy Price") || !listString.contains("Bazaar sell Price")) - && bazaarPricesJson != null && bazaarPricesJson.has(name)) { + && !listString.contains("Bazaar buy Price") || !listString.contains("Bazaar sell Price")) { - JsonObject getItem = bazaarPricesJson.getAsJsonObject(name); - lines.add(new LiteralText(String.format("%-18s", "Bazaar buy Price:")) - .formatted(Formatting.GOLD) - .append(getCoinsMessage(getItem.get("buyPrice").getAsDouble(), count))); - lines.add(new LiteralText(String.format("%-19s", "Bazaar sell Price:")) - .formatted(Formatting.GOLD) - .append(getCoinsMessage(getItem.get("sellPrice").getAsDouble(), count))); + if (bazaarPricesJson.has(name)) { + JsonObject getItem = bazaarPricesJson.getAsJsonObject(name); + lines.add(new LiteralText(String.format("%-18s", "Bazaar buy Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(getItem.get("buyPrice").getAsDouble(), count))); + lines.add(new LiteralText(String.format("%-19s", "Bazaar sell Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(getItem.get("sellPrice").getAsDouble(), count))); + } } - if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate - && !listString.contains("Museum") && isMuseumJson != null && isMuseumJson.has(name)) { - - String itemCategory = isMuseumJson.get(name).toString().replaceAll("\"", ""); - String format = switch (itemCategory) { - case "Weapons" -> "%-18s"; - case "Armor" -> "%-19s"; - default -> "%-20s"; - }; - - lines.add(new LiteralText(String.format(format, "Museum: (" + itemCategory + ")")) - .formatted(Formatting.LIGHT_PURPLE) - .append(new LiteralText(timestamp != null ? timestamp : "").formatted(Formatting.RED))); - } else if (!listString.contains("Obtained") && timestamp != null - && SkyblockerConfig.get().general.itemTooltip.enableMuseumDate) { - + if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate && !listString.contains("Museum")) { + if (isMuseumJson.has(name)) { + String itemCategory = isMuseumJson.get(name).toString().replaceAll("\"", ""); + String format = switch (itemCategory) { + case "Weapons" -> "%-18s"; + case "Armor" -> "%-19s"; + default -> "%-20s"; + }; + + lines.add(new LiteralText(String.format(format, "Museum: (" + itemCategory + ")")) + .formatted(Formatting.LIGHT_PURPLE) + .append(new LiteralText(timestamp != null ? timestamp : "").formatted(Formatting.RED))); + } + } else if (!listString.contains("Obtained") && timestamp != null && SkyblockerConfig.get().general.itemTooltip.enableMuseumDate) { lines.add(new LiteralText(String.format("%-22s", "Obtained: ")) .formatted(Formatting.LIGHT_PURPLE) .append(new LiteralText(timestamp).formatted(Formatting.RED))); } - } catch (Exception e) { + } catch (NullPointerException ex) { + if ((npcPricesJson == null || bazaarPricesJson == null || avgPricesJson == null || lowestPricesJson == null || isMuseumJson == null) + && !nullMsgSend) { + MinecraftClient.getInstance().player.sendMessage(new TranslatableText("skyblocker.itemTooltip.NullMessage"), false); + nullMsgSend = true; + skyblocker.scheduler.schedule(() -> nullMsgSend = false, 1200); + } + } catch (Exception ex) { if (MinecraftClient.getInstance().player == null) { throw new RuntimeException("[Skyblocker] client.player cannot be null!"); } - MinecraftClient.getInstance().player.sendMessage(new LiteralText(e.toString()), false); + MinecraftClient.getInstance().player.sendMessage(new LiteralText(ex.toString()), false); } } @@ -156,13 +166,32 @@ public class PriceInfoTooltip { } if ("ENCHANTED_BOOK".equals(internalName)) { - NbtCompound enchants = ea.getCompound("enchantments"); - - for (String enchName : enchants.getKeys()) { - internalName += "-" + enchName.toUpperCase() + "-" + enchants.getInt(enchName); - break; + if (ea.contains("enchantments")) { + NbtCompound enchants = ea.getCompound("enchantments"); + String enchant = enchants.getKeys().stream().findFirst().get(); + internalName += "-" + enchant.toUpperCase() + "-" + enchants.getInt(enchant); + } + } else if ("PET".equals(internalName)) { + if (ea.contains("petInfo")) { + JsonObject petInfo = gson.fromJson(ea.getString("petInfo"), JsonObject.class); + internalName += "-" + petInfo.get("type").getAsString() + "-" + petInfo.get("tier").getAsString(); + } + } else if ("POTION".equals(internalName)) { + String enhanced = ea.contains("enhanced") ? "-ENHANCED" : ""; + String extended = ea.contains("extended") ? "-EXTENDED" : ""; + String splash = ea.contains("splash") ? "-SPLASH" : ""; + if (ea.contains("potion") && ea.contains("potion_level")) { + internalName += "-" + ea.getString("potion").toUpperCase() + "-" + ea.getInt("potion_level") + + enhanced + extended + splash; + } + } else if ("RUNE".equals(internalName)) { + if (ea.contains("runes")) { + NbtCompound runes = ea.getCompound("runes"); + String rune = runes.getKeys().stream().findFirst().get(); + internalName += "-" + rune.toUpperCase() + "-" + runes.getInt(rune); } } + } return internalName; } @@ -182,24 +211,21 @@ public class PriceInfoTooltip { public static boolean firstRun = true; public static void init() { - TimerTask repeatedTask = new TimerTask() { - public void run() { - if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN || PriceInfoTooltip.firstRun) + skyblocker.scheduler.scheduleCyclic(() -> { + { + if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN || firstRun) CompletableFuture.runAsync(PriceInfoTooltip::downloadAvgPrices); - if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN || PriceInfoTooltip.firstRun) + if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN || firstRun) CompletableFuture.runAsync(PriceInfoTooltip::downloadLowestPrices); - if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice || PriceInfoTooltip.firstRun) + if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice || firstRun) CompletableFuture.runAsync(PriceInfoTooltip::downloadBazaarPrices); - if (SkyblockerConfig.get().general.itemTooltip.enableNPCPrice || PriceInfoTooltip.firstRun) + if (SkyblockerConfig.get().general.itemTooltip.enableNPCPrice || firstRun) CompletableFuture.runAsync(PriceInfoTooltip::downloadNPCPrices); - if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate || PriceInfoTooltip.firstRun) + if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate || firstRun) CompletableFuture.runAsync(PriceInfoTooltip::downloadIsMuseum); } - }; - + }, 1200); firstRun = false; - Timer timer = new Timer("PriceInfoDownloader"); - timer.scheduleAtFixedRate(repeatedTask, 0L, 1000L * 60L); } private static void downloadAvgPrices() { @@ -214,7 +240,7 @@ public class PriceInfoTooltip { } } } catch (IOException e) { - LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download auction item prices!", e); + LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download average BIN prices!", e); } avgPricesJson = result; } @@ -226,7 +252,7 @@ public class PriceInfoTooltip { InputStreamReader reader = new InputStreamReader(apiAddr.openStream()); result = new Gson().fromJson(reader, JsonObject.class); } catch (IOException e) { - LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download bazaar item prices!", e); + LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download bazaar prices!", e); } bazaarPricesJson = result; } @@ -238,7 +264,7 @@ public class PriceInfoTooltip { InputStreamReader reader = new InputStreamReader(apiAddr.openStream()); result = new Gson().fromJson(reader, JsonObject.class); } catch (IOException e) { - LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download lb item prices!", e); + LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download lowest BIN prices!", e); } lowestPricesJson = result; } @@ -250,7 +276,7 @@ public class PriceInfoTooltip { InputStreamReader reader = new InputStreamReader(apiAddr.openStream()); result = new Gson().fromJson(reader, JsonObject.class); } catch (IOException e) { - LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download shop item prices!", e); + LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download NPC prices!", e); } npcPricesJson = result; } -- cgit From 45b0aeba45f78ef5afbb20b34832e74822c3e941 Mon Sep 17 00:00:00 2001 From: Fix3dll Date: Mon, 21 Feb 2022 02:51:40 +0300 Subject: delete unused import --- src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java | 1 - 1 file changed, 1 deletion(-) (limited to 'src/main/java/me/xmrvizzy') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java index b48bcbc9..8f0ce1f2 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java @@ -23,7 +23,6 @@ import java.time.Month; import java.util.List; import java.util.Locale; import java.util.concurrent.CompletableFuture; -import java.util.stream.Collectors; import java.util.zip.GZIPInputStream; public class PriceInfoTooltip { -- cgit From 51f38c0bac92ac21fc01a0fabb4ef7b4a3da7e19 Mon Sep 17 00:00:00 2001 From: Fix3dll Date: Mon, 21 Feb 2022 17:34:16 +0300 Subject: new filters --- src/main/java/me/xmrvizzy/skyblocker/chat/ChatParser.java | 2 ++ .../me/xmrvizzy/skyblocker/chat/filters/ComboFilter.java | 14 ++++++++++++++ .../skyblocker/chat/filters/TeleportPadFilter.java | 14 ++++++++++++++ .../me/xmrvizzy/skyblocker/config/SkyblockerConfig.java | 2 ++ src/main/resources/assets/skyblocker/lang/en_us.json | 2 ++ 5 files changed, 34 insertions(+) create mode 100644 src/main/java/me/xmrvizzy/skyblocker/chat/filters/ComboFilter.java create mode 100644 src/main/java/me/xmrvizzy/skyblocker/chat/filters/TeleportPadFilter.java (limited to 'src/main/java/me/xmrvizzy') diff --git a/src/main/java/me/xmrvizzy/skyblocker/chat/ChatParser.java b/src/main/java/me/xmrvizzy/skyblocker/chat/ChatParser.java index 97ca1f68..f2c67d32 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/chat/ChatParser.java +++ b/src/main/java/me/xmrvizzy/skyblocker/chat/ChatParser.java @@ -19,6 +19,8 @@ public class ChatParser { new HealFilter(), new AbilityFilter(), new AdFilter(), + new TeleportPadFilter(), + new ComboFilter(), new Fetchur(), new Puzzler(), new Trivia(), diff --git a/src/main/java/me/xmrvizzy/skyblocker/chat/filters/ComboFilter.java b/src/main/java/me/xmrvizzy/skyblocker/chat/filters/ComboFilter.java new file mode 100644 index 00000000..718dda11 --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/chat/filters/ComboFilter.java @@ -0,0 +1,14 @@ +package me.xmrvizzy.skyblocker.chat.filters; + +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; + +public class ComboFilter extends ChatFilter { + public ComboFilter() { + super("^.*Kill Combo (\\+|has expired!).*$"); + } + + @Override + public boolean isEnabled() { + return SkyblockerConfig.get().messages.hideCombo; + } +} \ No newline at end of file diff --git a/src/main/java/me/xmrvizzy/skyblocker/chat/filters/TeleportPadFilter.java b/src/main/java/me/xmrvizzy/skyblocker/chat/filters/TeleportPadFilter.java new file mode 100644 index 00000000..1515613a --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/chat/filters/TeleportPadFilter.java @@ -0,0 +1,14 @@ +package me.xmrvizzy.skyblocker.chat.filters; + +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; + +public class TeleportPadFilter extends ChatFilter { + public TeleportPadFilter() { + super("^.*Teleport Pad (does not have a destination set!|to the).*$"); + } + + @Override + public boolean isEnabled() { + return SkyblockerConfig.get().messages.hideTeleportPad; + } +} \ No newline at end of file diff --git a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java index 40b20b98..12aeb001 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java @@ -119,6 +119,8 @@ public class SkyblockerConfig implements ConfigData { public boolean hideImplosion = false; public boolean hideMoltenWave = false; public boolean hideAds = false; + public boolean hideTeleportPad = false; + public boolean hideCombo = false; } public enum Info { PURSE, diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 11944a81..fa2f6b5c 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -51,6 +51,8 @@ "text.autoconfig.skyblocker.option.messages.hideImplosion": "Hide Implosion Message", "text.autoconfig.skyblocker.option.messages.hideMoltenWave": "Hide Molten Wave Message", "text.autoconfig.skyblocker.option.messages.hideAds": "Hide Ads From Public Chat", + "text.autoconfig.skyblocker.option.messages.hideTeleportPad": "Hide Teleport Pad Messages", + "text.autoconfig.skyblocker.option.messages.hideCombo": "Hide Combo Messages", "skyblocker.update.update_message": "§b[§6Skyblocker§b] §2There is a new version available!", "skyblocker.update.update_link": " §2§nClick here§r", -- cgit From 502240b2783f9cb3948e4a3373e998d7b526b25a Mon Sep 17 00:00:00 2001 From: Fix3dll Date: Mon, 21 Feb 2022 21:44:41 +0300 Subject: converting integer to decimal --- .../java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main/java/me/xmrvizzy') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java index 8f0ce1f2..2d1e5f26 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java @@ -197,12 +197,12 @@ public class PriceInfoTooltip { private static Text getCoinsMessage(double price, int count) { if (count == 1) { - String priceString = String.format(Locale.ENGLISH, "%1$,.0f", price); + String priceString = String.format(Locale.ENGLISH, "%1$,.1f", price); return new LiteralText(priceString + " Coins").formatted(Formatting.DARK_AQUA); } else { - String priceString = String.format(Locale.ENGLISH, "%1$,.0f", price * count); + String priceString = String.format(Locale.ENGLISH, "%1$,.1f", price * count); LiteralText priceText = (LiteralText) new LiteralText(priceString + " Coins ").formatted(Formatting.DARK_AQUA); - priceString = String.format(Locale.ENGLISH, "%1$,.0f", price); + priceString = String.format(Locale.ENGLISH, "%1$,.1f", price); LiteralText priceText2 = (LiteralText) new LiteralText( "(" + priceString + " each)").formatted(Formatting.GRAY); return priceText.append(priceText2); } -- cgit From d6562f8d5cb5b5917ba027daa16497901cc583d9 Mon Sep 17 00:00:00 2001 From: Fix3dll Date: Tue, 22 Feb 2022 22:16:29 +0300 Subject: more reliable filters and organise unnecessary query --- .../xmrvizzy/skyblocker/chat/filters/ComboFilter.java | 3 ++- .../skyblocker/chat/filters/TeleportPadFilter.java | 3 ++- .../skyblocker/skyblock/item/PriceInfoTooltip.java | 19 ++++++++++++------- 3 files changed, 16 insertions(+), 9 deletions(-) (limited to 'src/main/java/me/xmrvizzy') diff --git a/src/main/java/me/xmrvizzy/skyblocker/chat/filters/ComboFilter.java b/src/main/java/me/xmrvizzy/skyblocker/chat/filters/ComboFilter.java index 718dda11..c09cb69c 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/chat/filters/ComboFilter.java +++ b/src/main/java/me/xmrvizzy/skyblocker/chat/filters/ComboFilter.java @@ -4,7 +4,8 @@ import me.xmrvizzy.skyblocker.config.SkyblockerConfig; public class ComboFilter extends ChatFilter { public ComboFilter() { - super("^.*Kill Combo (\\+|has expired!).*$"); + super("^(\\+\\d+ Kill Combo \\+\\d+(% ✯ Magic Find| coins per kill)" + + "|Your Kill Combo has expired! You reached a \\d+ Kill Combo!)$"); } @Override diff --git a/src/main/java/me/xmrvizzy/skyblocker/chat/filters/TeleportPadFilter.java b/src/main/java/me/xmrvizzy/skyblocker/chat/filters/TeleportPadFilter.java index 1515613a..2913d2bb 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/chat/filters/TeleportPadFilter.java +++ b/src/main/java/me/xmrvizzy/skyblocker/chat/filters/TeleportPadFilter.java @@ -4,7 +4,8 @@ import me.xmrvizzy.skyblocker.config.SkyblockerConfig; public class TeleportPadFilter extends ChatFilter { public TeleportPadFilter() { - super("^.*Teleport Pad (does not have a destination set!|to the).*$"); + super("^(Warped from the .* Teleport Pad to the .* Teleport Pad!" + + "|This Teleport Pad does not have a destination set!)$"); } @Override diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java index 2d1e5f26..c25c91b5 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java @@ -208,23 +208,28 @@ public class PriceInfoTooltip { } } - public static boolean firstRun = true; + public static int minute = 0; public static void init() { skyblocker.scheduler.scheduleCyclic(() -> { { - if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN || firstRun) + if ((SkyblockerConfig.get().general.itemTooltip.enableAvgBIN || minute == 0) && (avgPricesJson == null || minute % 5 == 0)) { CompletableFuture.runAsync(PriceInfoTooltip::downloadAvgPrices); - if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN || firstRun) + } + if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN || minute == 0) { CompletableFuture.runAsync(PriceInfoTooltip::downloadLowestPrices); - if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice || firstRun) + } + if ((SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice || minute == 0) && minute % 3 == 0) { CompletableFuture.runAsync(PriceInfoTooltip::downloadBazaarPrices); - if (SkyblockerConfig.get().general.itemTooltip.enableNPCPrice || firstRun) + } + if ((SkyblockerConfig.get().general.itemTooltip.enableNPCPrice || minute == 0) && npcPricesJson == null) { CompletableFuture.runAsync(PriceInfoTooltip::downloadNPCPrices); - if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate || firstRun) + } + if ((SkyblockerConfig.get().general.itemTooltip.enableMuseumDate || minute == 0) && isMuseumJson == null) { CompletableFuture.runAsync(PriceInfoTooltip::downloadIsMuseum); + } + minute++; } }, 1200); - firstRun = false; } private static void downloadAvgPrices() { -- cgit From 1df02ab18d65986a6d3dbdfcfb34a252b45a5acb Mon Sep 17 00:00:00 2001 From: Fix3dll Date: Tue, 22 Feb 2022 22:21:05 +0300 Subject: added forgotten null control --- .../java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/me/xmrvizzy') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java index c25c91b5..c2f92acd 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java @@ -218,7 +218,7 @@ public class PriceInfoTooltip { if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN || minute == 0) { CompletableFuture.runAsync(PriceInfoTooltip::downloadLowestPrices); } - if ((SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice || minute == 0) && minute % 3 == 0) { + if ((SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice || minute == 0) && (bazaarPricesJson == null || minute % 3 == 0)) { CompletableFuture.runAsync(PriceInfoTooltip::downloadBazaarPrices); } if ((SkyblockerConfig.get().general.itemTooltip.enableNPCPrice || minute == 0) && npcPricesJson == null) { -- cgit From aa4789fab32d7402a03d5f5d78cb577fa4012267 Mon Sep 17 00:00:00 2001 From: Fix3dll Date: Wed, 23 Feb 2022 11:54:51 +0300 Subject: remove: avg price tag from runes and potions because there is no reliable data in api --- .../me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/main/java/me/xmrvizzy') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java index c2f92acd..a9593f96 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java @@ -72,14 +72,16 @@ public class PriceInfoTooltip { } else if (name.contains("ENCHANTED_BOOK-")) { name = name.replace("ENCHANTED_BOOK-", "").replace("-", ";"); } else if (name.contains("POTION-")) { - name = "POTION"; + //name = "POTION"; + name = ""; } else if (name.contains("RUNE-")) { - name = "RUNE"; + //name = "RUNE"; + name = ""; } else { name = name.replace(":", "-"); } - if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN && avgPricesJson.has(name)) { + if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN && !name.isEmpty() && avgPricesJson.has(name)) { lines.add(new LiteralText(String.format("%-21s", "Avg. BIN Price:")) .formatted(Formatting.GOLD) .append(getCoinsMessage(avgPricesJson.get(name).getAsDouble(), count))); -- cgit From 57fd50d7d657e1ed0c7ef95545bfc4e7e4302607 Mon Sep 17 00:00:00 2001 From: Fix3dll Date: Wed, 23 Feb 2022 18:23:15 +0300 Subject: new avg type --- .../skyblocker/config/SkyblockerConfig.java | 10 +++ .../skyblocker/skyblock/item/PriceInfoTooltip.java | 73 ++++++++++++++++++---- .../resources/assets/skyblocker/lang/en_us.json | 2 + 3 files changed, 74 insertions(+), 11 deletions(-) (limited to 'src/main/java/me/xmrvizzy') diff --git a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java index 12aeb001..f94a422d 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java @@ -72,9 +72,18 @@ public class SkyblockerConfig implements ConfigData { public boolean enableQuicknav = true; } + public enum Average { + ONE_DAY, + THREE_DAY, + BOTH + } + public static class ItemTooltip { public boolean enableNPCPrice = true; public boolean enableAvgBIN = true; + @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + @ConfigEntry.Gui.Tooltip() + public Average avg = Average.THREE_DAY; public boolean enableLowestBIN = true; public boolean enableBazaarPrice = true; public boolean enableMuseumDate = true; @@ -122,6 +131,7 @@ public class SkyblockerConfig implements ConfigData { public boolean hideTeleportPad = false; public boolean hideCombo = false; } + public enum Info { PURSE, BITS, diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java index a9593f96..df3ef3b3 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java @@ -25,11 +25,14 @@ import java.util.Locale; import java.util.concurrent.CompletableFuture; import java.util.zip.GZIPInputStream; +import static me.xmrvizzy.skyblocker.config.SkyblockerConfig.Average.BOTH; + public class PriceInfoTooltip { private static final SkyblockerMod skyblocker = SkyblockerMod.getInstance(); private static JsonObject npcPricesJson; private static JsonObject bazaarPricesJson; - private static JsonObject avgPricesJson; + private static JsonObject oneDayAvgPricesJson; + private static JsonObject threeDayAvgPricesJson; private static JsonObject lowestPricesJson; private static JsonObject isMuseumJson; private static boolean nullMsgSend = false; @@ -51,7 +54,7 @@ public class PriceInfoTooltip { } } - if ((!listString.contains("Avg. BIN Price") && avgPricesJson.has(name)) + if ((!listString.contains("Avg. BIN Price") && (threeDayAvgPricesJson.has(name) || oneDayAvgPricesJson.has(name))) || (!listString.contains("Lowest BIN Price") && lowestPricesJson.has(name))) { if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN && lowestPricesJson.has(name)) { @@ -81,10 +84,24 @@ public class PriceInfoTooltip { name = name.replace(":", "-"); } - if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN && !name.isEmpty() && avgPricesJson.has(name)) { - lines.add(new LiteralText(String.format("%-21s", "Avg. BIN Price:")) - .formatted(Formatting.GOLD) - .append(getCoinsMessage(avgPricesJson.get(name).getAsDouble(), count))); + if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN && !name.isEmpty() + && (threeDayAvgPricesJson.has(name) || oneDayAvgPricesJson.has(name))) { + switch (SkyblockerConfig.get().general.itemTooltip.avg) { + case ONE_DAY -> lines.add(new LiteralText(String.format("%-19s", "1 Day Avg. Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(oneDayAvgPricesJson.get(name).getAsDouble(), count))); + case THREE_DAY -> lines.add(new LiteralText(String.format("%-19s", "3 Day Avg. Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(threeDayAvgPricesJson.get(name).getAsDouble(), count))); + case BOTH -> { + lines.add(new LiteralText(String.format("%-19s", "1 Day Avg. Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(oneDayAvgPricesJson.get(name).getAsDouble(), count))); + lines.add(new LiteralText(String.format("%-19s", "3 Day Avg. Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(threeDayAvgPricesJson.get(name).getAsDouble(), count))); + } + } } } else if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice && !listString.contains("Bazaar buy Price") || !listString.contains("Bazaar sell Price")) { @@ -119,7 +136,8 @@ public class PriceInfoTooltip { .append(new LiteralText(timestamp).formatted(Formatting.RED))); } } catch (NullPointerException ex) { - if ((npcPricesJson == null || bazaarPricesJson == null || avgPricesJson == null || lowestPricesJson == null || isMuseumJson == null) + if ((npcPricesJson == null || bazaarPricesJson == null || oneDayAvgPricesJson == null + || threeDayAvgPricesJson == null || lowestPricesJson == null || isMuseumJson == null) && !nullMsgSend) { MinecraftClient.getInstance().player.sendMessage(new TranslatableText("skyblocker.itemTooltip.NullMessage"), false); nullMsgSend = true; @@ -214,8 +232,22 @@ public class PriceInfoTooltip { public static void init() { skyblocker.scheduler.scheduleCyclic(() -> { { - if ((SkyblockerConfig.get().general.itemTooltip.enableAvgBIN || minute == 0) && (avgPricesJson == null || minute % 5 == 0)) { - CompletableFuture.runAsync(PriceInfoTooltip::downloadAvgPrices); + if ((SkyblockerConfig.get().general.itemTooltip.enableAvgBIN || minute == 0) + && (oneDayAvgPricesJson == null || threeDayAvgPricesJson == null || minute % 5 == 0)) { + SkyblockerConfig.Average avg; + if (oneDayAvgPricesJson == null || threeDayAvgPricesJson == null || minute == 0) { + avg = BOTH; + } else { + avg = SkyblockerConfig.get().general.itemTooltip.avg; + } + switch (avg) { + case ONE_DAY -> CompletableFuture.runAsync(PriceInfoTooltip::download1DayAvgPrices); + case THREE_DAY -> CompletableFuture.runAsync(PriceInfoTooltip::download3DayAvgPrices); + case BOTH -> { + CompletableFuture.runAsync(PriceInfoTooltip::download1DayAvgPrices); + CompletableFuture.runAsync(PriceInfoTooltip::download3DayAvgPrices); + } + } } if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN || minute == 0) { CompletableFuture.runAsync(PriceInfoTooltip::downloadLowestPrices); @@ -234,8 +266,27 @@ public class PriceInfoTooltip { }, 1200); } - private static void downloadAvgPrices() { + private static void download1DayAvgPrices() { + JsonObject result = null; + String avgDay = null; + try { + URL apiAddr = new URL("https://moulberry.codes/auction_averages_lbin/1day.json.gz"); + try (InputStream src = apiAddr.openStream()) { + try (GZIPInputStream gzipOutput = new GZIPInputStream(src)) { + try (InputStreamReader reader = new InputStreamReader(gzipOutput)) { + result = new Gson().fromJson(reader, JsonObject.class); + } + } + } + } catch (IOException e) { + LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download average BIN prices!", e); + } + oneDayAvgPricesJson = result; + } + + private static void download3DayAvgPrices() { JsonObject result = null; + String avgDay = null; try { URL apiAddr = new URL("https://moulberry.codes/auction_averages_lbin/3day.json.gz"); try (InputStream src = apiAddr.openStream()) { @@ -248,7 +299,7 @@ public class PriceInfoTooltip { } catch (IOException e) { LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download average BIN prices!", e); } - avgPricesJson = result; + threeDayAvgPricesJson = result; } private static void downloadBazaarPrices() { diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index fa2f6b5c..17357c49 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -13,6 +13,8 @@ "text.autoconfig.skyblocker.option.general.itemTooltip": "Item Tooltip", "text.autoconfig.skyblocker.option.general.itemTooltip.enableNPCPrice": "Enable NPC Price", "text.autoconfig.skyblocker.option.general.itemTooltip.enableAvgBIN": "Enable Avg. BIN Price", + "text.autoconfig.skyblocker.option.general.itemTooltip.avg": "Average Type", + "text.autoconfig.skyblocker.option.general.itemTooltip.avg.@Tooltip": "You can choose how many days of average price to be", "text.autoconfig.skyblocker.option.general.itemTooltip.enableLowestBIN": "Enable Lowest BIN Price", "text.autoconfig.skyblocker.option.general.itemTooltip.enableBazaarPrice": "Enable Bazaar buy/sell Price", "text.autoconfig.skyblocker.option.general.itemTooltip.enableMuseumDate": "Enable Museum & Date", -- cgit From 225f99d6a7031389bd50fe96d75c4f09250f2186 Mon Sep 17 00:00:00 2001 From: Fix3dll Date: Sat, 26 Feb 2022 14:07:32 +0300 Subject: discord fix --- src/main/java/me/xmrvizzy/skyblocker/discord/DiscordRPCManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main/java/me/xmrvizzy') diff --git a/src/main/java/me/xmrvizzy/skyblocker/discord/DiscordRPCManager.java b/src/main/java/me/xmrvizzy/skyblocker/discord/DiscordRPCManager.java index b854613a..efbc3e56 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/discord/DiscordRPCManager.java +++ b/src/main/java/me/xmrvizzy/skyblocker/discord/DiscordRPCManager.java @@ -4,6 +4,7 @@ import com.google.gson.JsonObject; import com.jagrosh.discordipc.IPCClient; import com.jagrosh.discordipc.IPCListener; import com.jagrosh.discordipc.entities.RichPresence; +import com.jagrosh.discordipc.entities.pipe.PipeStatus; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import me.xmrvizzy.skyblocker.utils.Utils; import org.slf4j.Logger; @@ -77,7 +78,7 @@ public class DiscordRPCManager implements IPCListener{ } public void stop(){ - if (client != null){ + if (client != null && client.getStatus() == PipeStatus.CONNECTED) { logger.info("Closing..."); isConnected = false; client.close(); -- cgit From 2151f35a4211c43233ef708ade50e4508a21e014 Mon Sep 17 00:00:00 2001 From: Fix3dll Date: Sat, 26 Feb 2022 14:15:52 +0300 Subject: remove unnecessary import --- .../java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/main/java/me/xmrvizzy') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java index df3ef3b3..8b23b8cc 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java @@ -25,8 +25,6 @@ import java.util.Locale; import java.util.concurrent.CompletableFuture; import java.util.zip.GZIPInputStream; -import static me.xmrvizzy.skyblocker.config.SkyblockerConfig.Average.BOTH; - public class PriceInfoTooltip { private static final SkyblockerMod skyblocker = SkyblockerMod.getInstance(); private static JsonObject npcPricesJson; @@ -236,7 +234,7 @@ public class PriceInfoTooltip { && (oneDayAvgPricesJson == null || threeDayAvgPricesJson == null || minute % 5 == 0)) { SkyblockerConfig.Average avg; if (oneDayAvgPricesJson == null || threeDayAvgPricesJson == null || minute == 0) { - avg = BOTH; + avg = SkyblockerConfig.Average.BOTH; } else { avg = SkyblockerConfig.get().general.itemTooltip.avg; } -- cgit From 07a6a36118c3d0d21e22abe5a4cc383fdc9414b6 Mon Sep 17 00:00:00 2001 From: Fix3dll Date: Mon, 28 Feb 2022 16:14:52 +0300 Subject: fix: better null handling and requested changes --- .../skyblocker/skyblock/item/PriceInfoTooltip.java | 224 +++++++++++---------- .../resources/assets/skyblocker/lang/en_us.json | 2 +- 2 files changed, 121 insertions(+), 105 deletions(-) (limited to 'src/main/java/me/xmrvizzy') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java index 8b23b8cc..c3bd42a0 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java @@ -6,6 +6,7 @@ import me.xmrvizzy.skyblocker.SkyblockerMod; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import net.minecraft.client.MinecraftClient; import net.minecraft.client.item.TooltipContext; +import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.text.LiteralText; @@ -20,6 +21,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import java.time.Month; +import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.concurrent.CompletableFuture; @@ -27,6 +29,7 @@ import java.util.zip.GZIPInputStream; public class PriceInfoTooltip { private static final SkyblockerMod skyblocker = SkyblockerMod.getInstance(); + private static final ClientPlayerEntity player = MinecraftClient.getInstance().player; private static JsonObject npcPricesJson; private static JsonObject bazaarPricesJson; private static JsonObject oneDayAvgPricesJson; @@ -43,68 +46,103 @@ public class PriceInfoTooltip { List listString = lines.stream() .map(Text::getString).toList(); + if (player == null) { + throw new RuntimeException("[Skyblocker] client.player cannot be null!"); + } + try { if (SkyblockerConfig.get().general.itemTooltip.enableNPCPrice && !listString.contains("NPC Price")) { - if (npcPricesJson.has(name)) { + if (npcPricesJson == null) { + if (!nullMsgSend) { + player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); + nullMsgSend = true; + } + } else if (npcPricesJson.has(name)) { lines.add(new LiteralText(String.format("%-21s", "NPC Price:")) .formatted(Formatting.YELLOW) .append(getCoinsMessage(npcPricesJson.get(name).getAsDouble(), count))); } } - if ((!listString.contains("Avg. BIN Price") && (threeDayAvgPricesJson.has(name) || oneDayAvgPricesJson.has(name))) - || (!listString.contains("Lowest BIN Price") && lowestPricesJson.has(name))) { - - if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN && lowestPricesJson.has(name)) { + if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN && !listString.contains("Lowest BIN Price")) { + if (lowestPricesJson == null) { + if (!nullMsgSend) { + player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); + nullMsgSend = true; + } + } else if (lowestPricesJson.has(name)) { lines.add(new LiteralText(String.format("%-19s", "Lowest BIN Price:")) .formatted(Formatting.GOLD) .append(getCoinsMessage(lowestPricesJson.get(name).getAsDouble(), count))); } + } - if (name.contains("PET-")) { - name = name.replace("PET-", "") - .replace("COMMON", "0") - .replace("UNCOMMON", "1") - .replace("RARE", "2") - .replace("EPIC", "3") - .replace("LEGENDARY", "4") - .replace("MYTHIC", "5") - .replace("-", ";"); - } else if (name.contains("ENCHANTED_BOOK-")) { - name = name.replace("ENCHANTED_BOOK-", "").replace("-", ";"); - } else if (name.contains("POTION-")) { - //name = "POTION"; - name = ""; - } else if (name.contains("RUNE-")) { - //name = "RUNE"; - name = ""; - } else { - name = name.replace(":", "-"); - } + if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN && !listString.contains("Avg. BIN Price")) { + if (threeDayAvgPricesJson == null || oneDayAvgPricesJson == null) { + if (!nullMsgSend) { + player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); + nullMsgSend = true; + } + } else if (threeDayAvgPricesJson.has(name) || oneDayAvgPricesJson.has(name)) { + /* + We are skipping check average prices for potions and runes + because there is no data for their in API. + */ + if (name.contains("PET-")) { + name = name.replace("PET-", "") + .replace("COMMON", "0") + .replace("UNCOMMON", "1") + .replace("RARE", "2") + .replace("EPIC", "3") + .replace("LEGENDARY", "4") + .replace("MYTHIC", "5") + .replace("-", ";"); + } else if (name.contains("ENCHANTED_BOOK-")) { + name = name.replace("ENCHANTED_BOOK-", "").replace("-", ";"); + } else if (name.contains("POTION-")) { + name = ""; + } else if (name.contains("RUNE-")) { + name = ""; + } else { + name = name.replace(":", "-"); + } + + SkyblockerConfig.Average type = SkyblockerConfig.get().general.itemTooltip.avg; - if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN && !name.isEmpty() - && (threeDayAvgPricesJson.has(name) || oneDayAvgPricesJson.has(name))) { - switch (SkyblockerConfig.get().general.itemTooltip.avg) { - case ONE_DAY -> lines.add(new LiteralText(String.format("%-19s", "1 Day Avg. Price:")) - .formatted(Formatting.GOLD) - .append(getCoinsMessage(oneDayAvgPricesJson.get(name).getAsDouble(), count))); - case THREE_DAY -> lines.add(new LiteralText(String.format("%-19s", "3 Day Avg. Price:")) - .formatted(Formatting.GOLD) - .append(getCoinsMessage(threeDayAvgPricesJson.get(name).getAsDouble(), count))); - case BOTH -> { + // "No data" line because of API not keeping old data, it causes NullPointerException + if (!name.isEmpty() && (type == SkyblockerConfig.Average.ONE_DAY || type == SkyblockerConfig.Average.BOTH)) { + if (oneDayAvgPricesJson.get(name) != null) { lines.add(new LiteralText(String.format("%-19s", "1 Day Avg. Price:")) .formatted(Formatting.GOLD) .append(getCoinsMessage(oneDayAvgPricesJson.get(name).getAsDouble(), count))); + } else { + lines.add(new LiteralText(String.format("%-19s", "1 Day Avg. Price:")) + .formatted(Formatting.GOLD) + .append(new LiteralText("No data").formatted(Formatting.RED))); + } + } + if (!name.isEmpty() && (type == SkyblockerConfig.Average.THREE_DAY || type == SkyblockerConfig.Average.BOTH)) { + if (threeDayAvgPricesJson.get(name) != null) { lines.add(new LiteralText(String.format("%-19s", "3 Day Avg. Price:")) .formatted(Formatting.GOLD) .append(getCoinsMessage(threeDayAvgPricesJson.get(name).getAsDouble(), count))); + } else { + lines.add(new LiteralText(String.format("%-19s", "3 Day Avg. Price:")) + .formatted(Formatting.GOLD) + .append(new LiteralText("No data").formatted(Formatting.RED))); } } } - } else if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice - && !listString.contains("Bazaar buy Price") || !listString.contains("Bazaar sell Price")) { + } - if (bazaarPricesJson.has(name)) { + if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice + && (!listString.contains("Bazaar buy Price") || !listString.contains("Bazaar sell Price"))) { + if (bazaarPricesJson == null) { + if (!nullMsgSend) { + player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); + nullMsgSend = true; + } + } else if (bazaarPricesJson.has(name)) { JsonObject getItem = bazaarPricesJson.getAsJsonObject(name); lines.add(new LiteralText(String.format("%-18s", "Bazaar buy Price:")) .formatted(Formatting.GOLD) @@ -116,7 +154,12 @@ public class PriceInfoTooltip { } if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate && !listString.contains("Museum")) { - if (isMuseumJson.has(name)) { + if (isMuseumJson == null) { + if (!nullMsgSend) { + player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); + nullMsgSend = true; + } + } else if (isMuseumJson.has(name)) { String itemCategory = isMuseumJson.get(name).toString().replaceAll("\"", ""); String format = switch (itemCategory) { case "Weapons" -> "%-18s"; @@ -128,24 +171,14 @@ public class PriceInfoTooltip { .formatted(Formatting.LIGHT_PURPLE) .append(new LiteralText(timestamp != null ? timestamp : "").formatted(Formatting.RED))); } - } else if (!listString.contains("Obtained") && timestamp != null && SkyblockerConfig.get().general.itemTooltip.enableMuseumDate) { + } else if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate && !listString.contains("Obtained") && timestamp != null) { lines.add(new LiteralText(String.format("%-22s", "Obtained: ")) .formatted(Formatting.LIGHT_PURPLE) .append(new LiteralText(timestamp).formatted(Formatting.RED))); } - } catch (NullPointerException ex) { - if ((npcPricesJson == null || bazaarPricesJson == null || oneDayAvgPricesJson == null - || threeDayAvgPricesJson == null || lowestPricesJson == null || isMuseumJson == null) - && !nullMsgSend) { - MinecraftClient.getInstance().player.sendMessage(new TranslatableText("skyblocker.itemTooltip.NullMessage"), false); - nullMsgSend = true; - skyblocker.scheduler.schedule(() -> nullMsgSend = false, 1200); - } - } catch (Exception ex) { - if (MinecraftClient.getInstance().player == null) { - throw new RuntimeException("[Skyblocker] client.player cannot be null!"); - } - MinecraftClient.getInstance().player.sendMessage(new LiteralText(ex.toString()), false); + + } catch (Exception e) { + player.sendMessage(new LiteralText(e.toString()), false); } } @@ -229,64 +262,44 @@ public class PriceInfoTooltip { public static int minute = 0; public static void init() { skyblocker.scheduler.scheduleCyclic(() -> { - { - if ((SkyblockerConfig.get().general.itemTooltip.enableAvgBIN || minute == 0) - && (oneDayAvgPricesJson == null || threeDayAvgPricesJson == null || minute % 5 == 0)) { - SkyblockerConfig.Average avg; - if (oneDayAvgPricesJson == null || threeDayAvgPricesJson == null || minute == 0) { - avg = SkyblockerConfig.Average.BOTH; - } else { - avg = SkyblockerConfig.get().general.itemTooltip.avg; - } - switch (avg) { - case ONE_DAY -> CompletableFuture.runAsync(PriceInfoTooltip::download1DayAvgPrices); - case THREE_DAY -> CompletableFuture.runAsync(PriceInfoTooltip::download3DayAvgPrices); - case BOTH -> { - CompletableFuture.runAsync(PriceInfoTooltip::download1DayAvgPrices); - CompletableFuture.runAsync(PriceInfoTooltip::download3DayAvgPrices); - } - } - } - if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN || minute == 0) { - CompletableFuture.runAsync(PriceInfoTooltip::downloadLowestPrices); - } - if ((SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice || minute == 0) && (bazaarPricesJson == null || minute % 3 == 0)) { - CompletableFuture.runAsync(PriceInfoTooltip::downloadBazaarPrices); - } - if ((SkyblockerConfig.get().general.itemTooltip.enableNPCPrice || minute == 0) && npcPricesJson == null) { - CompletableFuture.runAsync(PriceInfoTooltip::downloadNPCPrices); - } - if ((SkyblockerConfig.get().general.itemTooltip.enableMuseumDate || minute == 0) && isMuseumJson == null) { - CompletableFuture.runAsync(PriceInfoTooltip::downloadIsMuseum); + List> futureList = new ArrayList<>(); + if ((SkyblockerConfig.get().general.itemTooltip.enableAvgBIN) && (oneDayAvgPricesJson == null || threeDayAvgPricesJson == null || minute % 5 == 0)) { + SkyblockerConfig.Average type = SkyblockerConfig.get().general.itemTooltip.avg; + + if (type == SkyblockerConfig.Average.BOTH || oneDayAvgPricesJson == null || threeDayAvgPricesJson == null) { + futureList.add(CompletableFuture.runAsync(() -> downloadAvgPrices(SkyblockerConfig.Average.THREE_DAY))); + futureList.add(CompletableFuture.runAsync(() -> downloadAvgPrices(SkyblockerConfig.Average.ONE_DAY))); + } else { + futureList.add(CompletableFuture.runAsync(() -> downloadAvgPrices(type))); } - minute++; } + if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN) { + futureList.add(CompletableFuture.runAsync(PriceInfoTooltip::downloadLowestPrices)); + } + if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice) { + futureList.add(CompletableFuture.runAsync(PriceInfoTooltip::downloadBazaarPrices)); + } + if (SkyblockerConfig.get().general.itemTooltip.enableNPCPrice && npcPricesJson == null) { + futureList.add(CompletableFuture.runAsync(PriceInfoTooltip::downloadNPCPrices)); + } + if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate && isMuseumJson == null) { + futureList.add(CompletableFuture.runAsync(PriceInfoTooltip::downloadIsMuseum)); + } + minute++; + CompletableFuture.allOf(futureList.toArray(new CompletableFuture[0])) + .whenComplete((unused, throwable) -> nullMsgSend = false); }, 1200); } - private static void download1DayAvgPrices() { + private static void downloadAvgPrices(SkyblockerConfig.Average type) { JsonObject result = null; String avgDay = null; - try { - URL apiAddr = new URL("https://moulberry.codes/auction_averages_lbin/1day.json.gz"); - try (InputStream src = apiAddr.openStream()) { - try (GZIPInputStream gzipOutput = new GZIPInputStream(src)) { - try (InputStreamReader reader = new InputStreamReader(gzipOutput)) { - result = new Gson().fromJson(reader, JsonObject.class); - } - } - } - } catch (IOException e) { - LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download average BIN prices!", e); + switch (type) { + case ONE_DAY -> avgDay = "1day.json.gz"; + case THREE_DAY -> avgDay = "3day.json.gz"; } - oneDayAvgPricesJson = result; - } - - private static void download3DayAvgPrices() { - JsonObject result = null; - String avgDay = null; try { - URL apiAddr = new URL("https://moulberry.codes/auction_averages_lbin/3day.json.gz"); + URL apiAddr = new URL("https://moulberry.codes/auction_averages_lbin/" + avgDay); try (InputStream src = apiAddr.openStream()) { try (GZIPInputStream gzipOutput = new GZIPInputStream(src)) { try (InputStreamReader reader = new InputStreamReader(gzipOutput)) { @@ -297,13 +310,16 @@ public class PriceInfoTooltip { } catch (IOException e) { LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download average BIN prices!", e); } - threeDayAvgPricesJson = result; + switch (type) { + case ONE_DAY -> oneDayAvgPricesJson = result; + case THREE_DAY -> threeDayAvgPricesJson = result; + } } private static void downloadBazaarPrices() { JsonObject result = null; try { - URL apiAddr = new URL("https://sky.shiiyu.moe/api/v2/bazaar"); + URL apiAddr = new URL("https://hysky.de/api/bazaar"); InputStreamReader reader = new InputStreamReader(apiAddr.openStream()); result = new Gson().fromJson(reader, JsonObject.class); } catch (IOException e) { diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 17357c49..55c7910c 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -18,7 +18,7 @@ "text.autoconfig.skyblocker.option.general.itemTooltip.enableLowestBIN": "Enable Lowest BIN Price", "text.autoconfig.skyblocker.option.general.itemTooltip.enableBazaarPrice": "Enable Bazaar buy/sell Price", "text.autoconfig.skyblocker.option.general.itemTooltip.enableMuseumDate": "Enable Museum & Date", - "skyblocker.itemTooltip.NullMessage": "§b[§6Skyblocker§b] §cItem price info on tooltip will renew in max 60 seconds.", + "skyblocker.itemTooltip.nullMessage": "§b[§6Skyblocker§b] §cItem price information on tooltip will renew in max 60 seconds. If not, check latest.log", "text.autoconfig.skyblocker.category.richPresence": "Discord Rich Presence", "text.autoconfig.skyblocker.option.richPresence.info": "Skyblock Info", -- cgit From 4db1ed543df7433f98dd6dfd7874e23ed7fd2125 Mon Sep 17 00:00:00 2001 From: Fix3dll Date: Mon, 28 Feb 2022 16:33:16 +0300 Subject: fix: crash fix --- .../skyblocker/skyblock/item/PriceInfoTooltip.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/main/java/me/xmrvizzy') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java index c3bd42a0..bff4c4f9 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java @@ -29,7 +29,7 @@ import java.util.zip.GZIPInputStream; public class PriceInfoTooltip { private static final SkyblockerMod skyblocker = SkyblockerMod.getInstance(); - private static final ClientPlayerEntity player = MinecraftClient.getInstance().player; + private static final MinecraftClient client = MinecraftClient.getInstance(); private static JsonObject npcPricesJson; private static JsonObject bazaarPricesJson; private static JsonObject oneDayAvgPricesJson; @@ -46,15 +46,11 @@ public class PriceInfoTooltip { List listString = lines.stream() .map(Text::getString).toList(); - if (player == null) { - throw new RuntimeException("[Skyblocker] client.player cannot be null!"); - } - try { if (SkyblockerConfig.get().general.itemTooltip.enableNPCPrice && !listString.contains("NPC Price")) { if (npcPricesJson == null) { if (!nullMsgSend) { - player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); + client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); nullMsgSend = true; } } else if (npcPricesJson.has(name)) { @@ -67,7 +63,7 @@ public class PriceInfoTooltip { if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN && !listString.contains("Lowest BIN Price")) { if (lowestPricesJson == null) { if (!nullMsgSend) { - player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); + client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); nullMsgSend = true; } } else if (lowestPricesJson.has(name)) { @@ -80,7 +76,7 @@ public class PriceInfoTooltip { if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN && !listString.contains("Avg. BIN Price")) { if (threeDayAvgPricesJson == null || oneDayAvgPricesJson == null) { if (!nullMsgSend) { - player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); + client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); nullMsgSend = true; } } else if (threeDayAvgPricesJson.has(name) || oneDayAvgPricesJson.has(name)) { @@ -139,7 +135,7 @@ public class PriceInfoTooltip { && (!listString.contains("Bazaar buy Price") || !listString.contains("Bazaar sell Price"))) { if (bazaarPricesJson == null) { if (!nullMsgSend) { - player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); + client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); nullMsgSend = true; } } else if (bazaarPricesJson.has(name)) { @@ -156,7 +152,7 @@ public class PriceInfoTooltip { if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate && !listString.contains("Museum")) { if (isMuseumJson == null) { if (!nullMsgSend) { - player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); + client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); nullMsgSend = true; } } else if (isMuseumJson.has(name)) { @@ -178,7 +174,7 @@ public class PriceInfoTooltip { } } catch (Exception e) { - player.sendMessage(new LiteralText(e.toString()), false); + client.player.sendMessage(new LiteralText(e.toString()), false); } } -- cgit From 7edd1d11abbf21b36316a9668e1dfe80d8986141 Mon Sep 17 00:00:00 2001 From: Fix3dll Date: Mon, 28 Feb 2022 23:20:36 +0300 Subject: add: ClientPlayerEntity null check --- .../java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/main/java/me/xmrvizzy') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java index bff4c4f9..db5082af 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java @@ -6,7 +6,6 @@ import me.xmrvizzy.skyblocker.SkyblockerMod; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import net.minecraft.client.MinecraftClient; import net.minecraft.client.item.TooltipContext; -import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.text.LiteralText; @@ -46,6 +45,10 @@ public class PriceInfoTooltip { List listString = lines.stream() .map(Text::getString).toList(); + if (client.player == null) { + throw new RuntimeException("[Skyblocker] client.player cannot be null!"); + } + try { if (SkyblockerConfig.get().general.itemTooltip.enableNPCPrice && !listString.contains("NPC Price")) { if (npcPricesJson == null) { -- cgit From 5a2d212e684086f7404f129b39720e5f04c1b5ff Mon Sep 17 00:00:00 2001 From: Fix3dll Date: Tue, 1 Mar 2022 00:57:13 +0300 Subject: change: remove unnecessary try-catch --- .../skyblocker/skyblock/item/PriceInfoTooltip.java | 216 ++++++++++----------- 1 file changed, 105 insertions(+), 111 deletions(-) (limited to 'src/main/java/me/xmrvizzy') diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java index db5082af..1d70c5e0 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java @@ -49,137 +49,131 @@ public class PriceInfoTooltip { throw new RuntimeException("[Skyblocker] client.player cannot be null!"); } - try { - if (SkyblockerConfig.get().general.itemTooltip.enableNPCPrice && !listString.contains("NPC Price")) { - if (npcPricesJson == null) { - if (!nullMsgSend) { - client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); - nullMsgSend = true; - } - } else if (npcPricesJson.has(name)) { - lines.add(new LiteralText(String.format("%-21s", "NPC Price:")) - .formatted(Formatting.YELLOW) - .append(getCoinsMessage(npcPricesJson.get(name).getAsDouble(), count))); + if (SkyblockerConfig.get().general.itemTooltip.enableNPCPrice && !listString.contains("NPC Price")) { + if (npcPricesJson == null) { + if (!nullMsgSend) { + client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); + nullMsgSend = true; } + } else if (npcPricesJson.has(name)) { + lines.add(new LiteralText(String.format("%-21s", "NPC Price:")) + .formatted(Formatting.YELLOW) + .append(getCoinsMessage(npcPricesJson.get(name).getAsDouble(), count))); } + } - if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN && !listString.contains("Lowest BIN Price")) { - if (lowestPricesJson == null) { - if (!nullMsgSend) { - client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); - nullMsgSend = true; - } - } else if (lowestPricesJson.has(name)) { - lines.add(new LiteralText(String.format("%-19s", "Lowest BIN Price:")) - .formatted(Formatting.GOLD) - .append(getCoinsMessage(lowestPricesJson.get(name).getAsDouble(), count))); + if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN && !listString.contains("Lowest BIN Price")) { + if (lowestPricesJson == null) { + if (!nullMsgSend) { + client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); + nullMsgSend = true; } + } else if (lowestPricesJson.has(name)) { + lines.add(new LiteralText(String.format("%-19s", "Lowest BIN Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(lowestPricesJson.get(name).getAsDouble(), count))); } + } - if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN && !listString.contains("Avg. BIN Price")) { - if (threeDayAvgPricesJson == null || oneDayAvgPricesJson == null) { - if (!nullMsgSend) { - client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); - nullMsgSend = true; - } - } else if (threeDayAvgPricesJson.has(name) || oneDayAvgPricesJson.has(name)) { - /* - We are skipping check average prices for potions and runes - because there is no data for their in API. - */ - if (name.contains("PET-")) { - name = name.replace("PET-", "") - .replace("COMMON", "0") - .replace("UNCOMMON", "1") - .replace("RARE", "2") - .replace("EPIC", "3") - .replace("LEGENDARY", "4") - .replace("MYTHIC", "5") - .replace("-", ";"); - } else if (name.contains("ENCHANTED_BOOK-")) { - name = name.replace("ENCHANTED_BOOK-", "").replace("-", ";"); - } else if (name.contains("POTION-")) { - name = ""; - } else if (name.contains("RUNE-")) { - name = ""; - } else { - name = name.replace(":", "-"); - } + if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN && !listString.contains("Avg. BIN Price")) { + if (threeDayAvgPricesJson == null || oneDayAvgPricesJson == null) { + if (!nullMsgSend) { + client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); + nullMsgSend = true; + } + } else if (threeDayAvgPricesJson.has(name) || oneDayAvgPricesJson.has(name)) { + /* + We are skipping check average prices for potions and runes + because there is no data for their in API. + */ + if (name.contains("PET-")) { + name = name.replace("PET-", "") + .replace("COMMON", "0") + .replace("UNCOMMON", "1") + .replace("RARE", "2") + .replace("EPIC", "3") + .replace("LEGENDARY", "4") + .replace("MYTHIC", "5") + .replace("-", ";"); + } else if (name.contains("ENCHANTED_BOOK-")) { + name = name.replace("ENCHANTED_BOOK-", "").replace("-", ";"); + } else if (name.contains("POTION-")) { + name = ""; + } else if (name.contains("RUNE-")) { + name = ""; + } else { + name = name.replace(":", "-"); + } - SkyblockerConfig.Average type = SkyblockerConfig.get().general.itemTooltip.avg; + SkyblockerConfig.Average type = SkyblockerConfig.get().general.itemTooltip.avg; - // "No data" line because of API not keeping old data, it causes NullPointerException - if (!name.isEmpty() && (type == SkyblockerConfig.Average.ONE_DAY || type == SkyblockerConfig.Average.BOTH)) { - if (oneDayAvgPricesJson.get(name) != null) { - lines.add(new LiteralText(String.format("%-19s", "1 Day Avg. Price:")) - .formatted(Formatting.GOLD) - .append(getCoinsMessage(oneDayAvgPricesJson.get(name).getAsDouble(), count))); - } else { - lines.add(new LiteralText(String.format("%-19s", "1 Day Avg. Price:")) - .formatted(Formatting.GOLD) - .append(new LiteralText("No data").formatted(Formatting.RED))); - } + // "No data" line because of API not keeping old data, it causes NullPointerException + if (!name.isEmpty() && (type == SkyblockerConfig.Average.ONE_DAY || type == SkyblockerConfig.Average.BOTH)) { + if (oneDayAvgPricesJson.get(name) != null) { + lines.add(new LiteralText(String.format("%-19s", "1 Day Avg. Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(oneDayAvgPricesJson.get(name).getAsDouble(), count))); + } else { + lines.add(new LiteralText(String.format("%-19s", "1 Day Avg. Price:")) + .formatted(Formatting.GOLD) + .append(new LiteralText("No data").formatted(Formatting.RED))); } - if (!name.isEmpty() && (type == SkyblockerConfig.Average.THREE_DAY || type == SkyblockerConfig.Average.BOTH)) { - if (threeDayAvgPricesJson.get(name) != null) { - lines.add(new LiteralText(String.format("%-19s", "3 Day Avg. Price:")) - .formatted(Formatting.GOLD) - .append(getCoinsMessage(threeDayAvgPricesJson.get(name).getAsDouble(), count))); - } else { - lines.add(new LiteralText(String.format("%-19s", "3 Day Avg. Price:")) - .formatted(Formatting.GOLD) - .append(new LiteralText("No data").formatted(Formatting.RED))); - } + } + if (!name.isEmpty() && (type == SkyblockerConfig.Average.THREE_DAY || type == SkyblockerConfig.Average.BOTH)) { + if (threeDayAvgPricesJson.get(name) != null) { + lines.add(new LiteralText(String.format("%-19s", "3 Day Avg. Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(threeDayAvgPricesJson.get(name).getAsDouble(), count))); + } else { + lines.add(new LiteralText(String.format("%-19s", "3 Day Avg. Price:")) + .formatted(Formatting.GOLD) + .append(new LiteralText("No data").formatted(Formatting.RED))); } } } + } - if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice - && (!listString.contains("Bazaar buy Price") || !listString.contains("Bazaar sell Price"))) { - if (bazaarPricesJson == null) { - if (!nullMsgSend) { - client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); - nullMsgSend = true; - } - } else if (bazaarPricesJson.has(name)) { - JsonObject getItem = bazaarPricesJson.getAsJsonObject(name); - lines.add(new LiteralText(String.format("%-18s", "Bazaar buy Price:")) - .formatted(Formatting.GOLD) - .append(getCoinsMessage(getItem.get("buyPrice").getAsDouble(), count))); - lines.add(new LiteralText(String.format("%-19s", "Bazaar sell Price:")) - .formatted(Formatting.GOLD) - .append(getCoinsMessage(getItem.get("sellPrice").getAsDouble(), count))); + if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice + && (!listString.contains("Bazaar buy Price") || !listString.contains("Bazaar sell Price"))) { + if (bazaarPricesJson == null) { + if (!nullMsgSend) { + client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); + nullMsgSend = true; } + } else if (bazaarPricesJson.has(name)) { + JsonObject getItem = bazaarPricesJson.getAsJsonObject(name); + lines.add(new LiteralText(String.format("%-18s", "Bazaar buy Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(getItem.get("buyPrice").getAsDouble(), count))); + lines.add(new LiteralText(String.format("%-19s", "Bazaar sell Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(getItem.get("sellPrice").getAsDouble(), count))); } + } - if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate && !listString.contains("Museum")) { - if (isMuseumJson == null) { - if (!nullMsgSend) { - client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); - nullMsgSend = true; - } - } else if (isMuseumJson.has(name)) { - String itemCategory = isMuseumJson.get(name).toString().replaceAll("\"", ""); - String format = switch (itemCategory) { - case "Weapons" -> "%-18s"; - case "Armor" -> "%-19s"; - default -> "%-20s"; - }; - - lines.add(new LiteralText(String.format(format, "Museum: (" + itemCategory + ")")) - .formatted(Formatting.LIGHT_PURPLE) - .append(new LiteralText(timestamp != null ? timestamp : "").formatted(Formatting.RED))); + if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate && !listString.contains("Museum")) { + if (isMuseumJson == null) { + if (!nullMsgSend) { + client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false); + nullMsgSend = true; } - } else if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate && !listString.contains("Obtained") && timestamp != null) { - lines.add(new LiteralText(String.format("%-22s", "Obtained: ")) + } else if (isMuseumJson.has(name)) { + String itemCategory = isMuseumJson.get(name).toString().replaceAll("\"", ""); + String format = switch (itemCategory) { + case "Weapons" -> "%-18s"; + case "Armor" -> "%-19s"; + default -> "%-20s"; + }; + + lines.add(new LiteralText(String.format(format, "Museum: (" + itemCategory + ")")) .formatted(Formatting.LIGHT_PURPLE) - .append(new LiteralText(timestamp).formatted(Formatting.RED))); + .append(new LiteralText(timestamp != null ? timestamp : "").formatted(Formatting.RED))); } - - } catch (Exception e) { - client.player.sendMessage(new LiteralText(e.toString()), false); + } else if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate && !listString.contains("Obtained") && timestamp != null) { + lines.add(new LiteralText(String.format("%-22s", "Obtained: ")) + .formatted(Formatting.LIGHT_PURPLE) + .append(new LiteralText(timestamp).formatted(Formatting.RED))); } - } public static NbtCompound getInternalNameForItem(ItemStack stack) { -- cgit