diff options
8 files changed, 187 insertions, 75 deletions
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..c09cb69c --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/chat/filters/ComboFilter.java @@ -0,0 +1,15 @@ +package me.xmrvizzy.skyblocker.chat.filters; + +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; + +public class ComboFilter extends ChatFilter { + public ComboFilter() { + super("^(\\+\\d+ Kill Combo \\+\\d+(% ✯ Magic Find| coins per kill)" + + "|Your Kill Combo has expired! You reached a \\d+ Kill Combo!)$"); + } + + @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..2913d2bb --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/chat/filters/TeleportPadFilter.java @@ -0,0 +1,15 @@ +package me.xmrvizzy.skyblocker.chat.filters; + +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; + +public class TeleportPadFilter extends ChatFilter { + public TeleportPadFilter() { + super("^(Warped from the .* Teleport Pad to the .* Teleport Pad!" + + "|This Teleport Pad does not have a destination set!)$"); + } + + @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/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java index daad1d26..a9593f96 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,114 @@ 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<Text> lines) { int count = stack.getCount(); String name = getInternalNameFromNBT(stack); String timestamp = getTimestamp(stack); List<String> 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"; + name = ""; + } else if (name.contains("RUNE-")) { + //name = "RUNE"; + name = ""; } else { name = name.replace(":", "-"); } - // has(name) check because Skytils keeps old data but Moulberry not - 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))); } } 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,50 +167,71 @@ 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; } 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); } } - public static boolean firstRun = true; + public static int minute = 0; 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 || minute == 0) && (avgPricesJson == null || minute % 5 == 0)) { CompletableFuture.runAsync(PriceInfoTooltip::downloadAvgPrices); - if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN || PriceInfoTooltip.firstRun) + } + if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN || minute == 0) { CompletableFuture.runAsync(PriceInfoTooltip::downloadLowestPrices); - if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice || PriceInfoTooltip.firstRun) + } + if ((SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice || minute == 0) && (bazaarPricesJson == null || minute % 3 == 0)) { CompletableFuture.runAsync(PriceInfoTooltip::downloadBazaarPrices); - if (SkyblockerConfig.get().general.itemTooltip.enableNPCPrice || PriceInfoTooltip.firstRun) + } + if ((SkyblockerConfig.get().general.itemTooltip.enableNPCPrice || minute == 0) && npcPricesJson == null) { CompletableFuture.runAsync(PriceInfoTooltip::downloadNPCPrices); - if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate || PriceInfoTooltip.firstRun) + } + if ((SkyblockerConfig.get().general.itemTooltip.enableMuseumDate || minute == 0) && isMuseumJson == null) { CompletableFuture.runAsync(PriceInfoTooltip::downloadIsMuseum); + } + minute++; } - }; - - firstRun = false; - Timer timer = new Timer("PriceInfoDownloader"); - timer.scheduleAtFixedRate(repeatedTask, 0L, 1000L * 60L); + }, 1200); } private static void downloadAvgPrices() { @@ -214,7 +246,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 +258,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 +270,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 +282,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; } diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 52a7b441..fa2f6b5c 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -16,6 +16,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.", "text.autoconfig.skyblocker.category.richPresence": "Discord Rich Presence", "text.autoconfig.skyblocker.option.richPresence.info": "Skyblock Info", @@ -50,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", diff --git a/src/test/java/me/xmrvizzy/skyblocker/chat/filters/ComboFilterTest.java b/src/test/java/me/xmrvizzy/skyblocker/chat/filters/ComboFilterTest.java new file mode 100644 index 00000000..521668b0 --- /dev/null +++ b/src/test/java/me/xmrvizzy/skyblocker/chat/filters/ComboFilterTest.java @@ -0,0 +1,24 @@ +package me.xmrvizzy.skyblocker.chat.filters; + +import org.junit.jupiter.api.Test; + +public class ComboFilterTest extends ChatFilterTest<ComboFilter> { + public ComboFilterTest() { + super(new ComboFilter()); + } + + @Test + void testComboMF() { + assertFilters("+5 Kill Combo +3% ✯ Magic Find"); + } + + @Test + void testComboCoins() { + assertFilters("+10 Kill Combo +10 coins per kill"); + } + + @Test + void testComboExpired() { + assertFilters("Your Kill Combo has expired! You reached a 11 Kill Combo!"); + } +} diff --git a/src/test/java/me/xmrvizzy/skyblocker/chat/filters/TeleportPadFilterTest.java b/src/test/java/me/xmrvizzy/skyblocker/chat/filters/TeleportPadFilterTest.java new file mode 100644 index 00000000..605d57bb --- /dev/null +++ b/src/test/java/me/xmrvizzy/skyblocker/chat/filters/TeleportPadFilterTest.java @@ -0,0 +1,19 @@ +package me.xmrvizzy.skyblocker.chat.filters; + +import org.junit.jupiter.api.Test; + +public class TeleportPadFilterTest extends ChatFilterTest<TeleportPadFilter> { + public TeleportPadFilterTest() { + super(new TeleportPadFilter()); + } + + @Test + void testTeleport() { + assertFilters("Warped from the Base Teleport Pad to the Minion Teleport Pad!"); + } + + @Test + void testNoDestination() { + assertFilters("This Teleport Pad does not have a destination set!"); + } +}
\ No newline at end of file |