From 13b09e3be36ab38b92e14c7d808fb04ecdc65b82 Mon Sep 17 00:00:00 2001 From: Fix3d Date: Wed, 22 Mar 2023 12:01:14 +0300 Subject: a cleaner PriceInfoTooltip --- .../skyblocker/config/SkyblockerConfig.java | 5 +- .../skyblocker/skyblock/item/PriceInfoTooltip.java | 134 +++++++-------------- 2 files changed, 44 insertions(+), 95 deletions(-) diff --git a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java index 97284bc1..4d3ce5e9 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java @@ -6,7 +6,6 @@ import me.shedaniel.autoconfig.annotation.Config; import me.shedaniel.autoconfig.annotation.ConfigEntry; import me.shedaniel.autoconfig.serializer.GsonConfigSerializer; import me.xmrvizzy.skyblocker.chat.ChatFilterResult; -import net.minecraft.item.ItemStack; import java.util.ArrayList; import java.util.List; @@ -219,8 +218,8 @@ public class SkyblockerConfig implements ConfigData { public String toString() { return switch (this) { - case ONE_DAY -> "1 day price"; - case THREE_DAY -> "3 day price"; + case ONE_DAY -> "1 day avg"; + case THREE_DAY -> "3 day avg"; case BOTH -> "Both"; }; } 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 dfc498a1..c7df6a99 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java @@ -9,10 +9,8 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.item.TooltipContext; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; -import net.minecraft.text.LiteralTextContent; import net.minecraft.text.MutableText; import net.minecraft.text.Text; -import net.minecraft.text.TranslatableTextContent; import net.minecraft.util.Formatting; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,8 +23,10 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.zip.GZIPInputStream; @@ -42,6 +42,7 @@ public class PriceInfoTooltip { private static JsonObject isMuseumJson; private static boolean nullMsgSend = false; private final static Gson gson = new Gson(); + private static final Map apiAddresses; public static void onInjectTooltip(ItemStack stack, TooltipContext context, List lines) { if (!Utils.isOnSkyblock || client.player == null) return; @@ -184,7 +185,7 @@ public class PriceInfoTooltip { /** * this method converts the "timestamp" variable into the same date format as Hypixel represents it in the museum. - * Currently there are two types of timestamps the legacy which is built like this + * Currently, there are two types of timestamps the legacy which is built like this * "dd/MM/yy hh:mm" ("25/04/20 16:38") and the current which is built like this * "MM/dd/yy hh:mm aa" ("12/24/20 11:08 PM"). Since Hypixel transforms the two formats into one format without * taking into account of their formats, we do the same. The final result looks like this @@ -194,7 +195,7 @@ public class PriceInfoTooltip { * This causes the museum rank to be much worse than it should be. * * @param stack the item under the pointer - * @return if the item have an "Timestamp" it will be shown formated on the tooltip + * @return if the item have a "Timestamp" it will be shown formated on the tooltip */ public static String getTimestamp(ItemStack stack) { NbtCompound tag = getInternalNameForItem(stack); @@ -289,108 +290,57 @@ public class PriceInfoTooltip { 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))); + futureList.add(CompletableFuture.runAsync(() -> oneDayAvgPricesJson = downloadPrices("1 day avg"))); + futureList.add(CompletableFuture.runAsync(() -> threeDayAvgPricesJson = downloadPrices("3 day avg"))); + } else if (type == SkyblockerConfig.Average.ONE_DAY) { + futureList.add(CompletableFuture.runAsync(() -> oneDayAvgPricesJson = downloadPrices("1 day avg"))); + } else if (type == SkyblockerConfig.Average.THREE_DAY) { + futureList.add(CompletableFuture.runAsync(() -> threeDayAvgPricesJson = downloadPrices("3 day avg"))); } } - 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)); - } + if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN) + futureList.add(CompletableFuture.runAsync(() -> lowestPricesJson = downloadPrices("lowest bin"))); + + if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice) + futureList.add(CompletableFuture.runAsync(() -> bazaarPricesJson = downloadPrices("bazaar"))); + + if (SkyblockerConfig.get().general.itemTooltip.enableNPCPrice && npcPricesJson == null) + futureList.add(CompletableFuture.runAsync(() -> npcPricesJson = downloadPrices("npc"))); + + if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate && isMuseumJson == null) + futureList.add(CompletableFuture.runAsync(() -> isMuseumJson = downloadPrices("museum"))); + minute++; CompletableFuture.allOf(futureList.toArray(new CompletableFuture[0])) .whenComplete((unused, throwable) -> nullMsgSend = false); }, 1200); } - private static void downloadAvgPrices(SkyblockerConfig.Average type) { - JsonObject result = null; - String avgDay = null; - switch (type) { - case ONE_DAY -> avgDay = "1day.json.gz"; - case THREE_DAY -> avgDay = "3day.json.gz"; - } + private static JsonObject downloadPrices(String type) { try { - 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)) { - result = new Gson().fromJson(reader, JsonObject.class); - } - } - } + String url = apiAddresses.get(type); + URL apiAddress = new URL(url); + InputStream src = apiAddress.openStream(); + InputStreamReader reader = new InputStreamReader(url.contains(".gz") ? new GZIPInputStream(src) : src); + return new Gson().fromJson(reader, JsonObject.class); } catch (IOException e) { - LOGGER.warn("[Skyblocker] Failed to download average BIN prices!", e); - } - switch (type) { - case ONE_DAY -> oneDayAvgPricesJson = result; - case THREE_DAY -> threeDayAvgPricesJson = result; - } - } + LOGGER.warn("[Skyblocker] Failed to download " + type + " prices!", e); - private static void downloadBazaarPrices() { - JsonObject result = null; - try { - 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) { - LOGGER.warn("[Skyblocker] Failed to download bazaar prices!", e); - } - bazaarPricesJson = result; - } + if (type.equals("lowest bin")) + lowestPricesJson = downloadPrices("lowest bin backup"); - private static void downloadLowestPrices() { - JsonObject result = null; - try { - URL apiAddr = new URL("https://lb.tricked.pro/lowestbins"); - InputStreamReader reader = new InputStreamReader(apiAddr.openStream()); - result = new Gson().fromJson(reader, JsonObject.class); - } catch (IOException e) { - LOGGER.warn("[Skyblocker] Failed to download lowest BIN prices from the main source!", e); - try { - URL apiAddr = new URL("https://lb2.tricked.pro/lowestbins"); - InputStreamReader reader = new InputStreamReader(apiAddr.openStream()); - result = new Gson().fromJson(reader, JsonObject.class); - } catch (IOException e2) { - LOGGER.warn("[Skyblocker] Failed to download lowest BIN prices from the backup source!", e2); - } + return null; } - lowestPricesJson = result; } - private static void downloadNPCPrices() { - JsonObject result = null; - try { - URL apiAddr = new URL("https://hysky.de/api/npcprice"); - InputStreamReader reader = new InputStreamReader(apiAddr.openStream()); - result = new Gson().fromJson(reader, JsonObject.class); - } catch (IOException e) { - LOGGER.warn("[Skyblocker] Failed to download NPC prices!", e); - } - npcPricesJson = result; + static { + apiAddresses = new HashMap<>(); + apiAddresses.put("1 day avg", "https://moulberry.codes/auction_averages_lbin/1day.json.gz"); + apiAddresses.put("3 day avg", "https://moulberry.codes/auction_averages_lbin/3day.json.gz"); + apiAddresses.put("bazaar", "https://hysky.de/api/bazaar"); + apiAddresses.put("lowest bin", "https://lb.tricked.pro/lowestbins"); + apiAddresses.put("lowest bin backup", "https://lb2.tricked.pro/lowestbins"); + apiAddresses.put("npc", "https://hysky.de/api/npcprice"); + apiAddresses.put("museum", "https://hysky.de/api/museum"); } - - private static void downloadIsMuseum() { - JsonObject result = null; - try { - URL apiAddr = new URL("https://hysky.de/api/museum"); - InputStreamReader reader = new InputStreamReader(apiAddr.openStream()); - result = new Gson().fromJson(reader, JsonObject.class); - } catch (IOException e) { - LOGGER.warn("[Skyblocker] Failed to download museum items!", e); - } - isMuseumJson = result; - } - } -- cgit From f362d95f9b8477c1f8190e79ca390a09adb658c5 Mon Sep 17 00:00:00 2001 From: Fix3d Date: Wed, 22 Mar 2023 12:33:17 +0300 Subject: fix recipe book --- .../java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java index 17e9aebc..7bfa0997 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java @@ -16,7 +16,7 @@ import java.nio.file.Path; import java.util.*; public class ItemRegistry { - protected static final String REMOTE_ITEM_REPO = "https://github.com/KonaeAkira/NotEnoughUpdates-REPO.git"; + protected static final String REMOTE_ITEM_REPO = "https://github.com/NotEnoughUpdates/NotEnoughUpdates-REPO"; protected static final Path LOCAL_ITEM_REPO_DIR = FabricLoader.getInstance().getConfigDir().resolve("skyblocker/item-repo"); private static final Path ITEM_LIST_DIR = LOCAL_ITEM_REPO_DIR.resolve("items"); @@ -135,7 +135,7 @@ class Recipe { private static ItemStack getItemStack(String internalName) { try { if (internalName.length() > 0) { - int count = Integer.parseInt(internalName.split(":")[1]); + int count = Integer.parseInt(internalName.split(":").length > 1 ? internalName.split(":")[1] : "1"); internalName = internalName.split(":")[0]; ItemStack itemStack = ItemRegistry.itemsMap.get(internalName).copy(); itemStack.setCount(count); -- cgit From 4a3b5a00c174d9c7abe2cfaed84ac09bf464650a Mon Sep 17 00:00:00 2001 From: Fix3d Date: Wed, 22 Mar 2023 13:55:34 +0300 Subject: fix freezing while open wiki and... get wiki link from local repo which is same and exist for recipe book --- .../skyblocker/skyblock/item/WikiLookup.java | 29 +++++----------------- .../skyblocker/skyblock/itemlist/ItemRegistry.java | 16 ++++++++++++ 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/WikiLookup.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/WikiLookup.java index afaf487f..76b4e7c3 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/WikiLookup.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/WikiLookup.java @@ -1,9 +1,7 @@ package me.xmrvizzy.skyblocker.skyblock.item; import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; +import me.xmrvizzy.skyblocker.skyblock.itemlist.ItemRegistry; import me.xmrvizzy.skyblocker.utils.Utils; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.minecraft.client.MinecraftClient; @@ -16,11 +14,7 @@ import net.minecraft.text.Text; import net.minecraft.util.Util; import org.lwjgl.glfw.GLFW; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; +import java.util.concurrent.CompletableFuture; public class WikiLookup { public static KeyBinding wikiLookup; @@ -51,23 +45,12 @@ public class WikiLookup { if (Utils.isOnSkyblock) { id = getSkyblockId(slot); try { - //Setting up a connection with the repo - String urlString = "https://raw.githubusercontent.com/NotEnoughUpdates/NotEnoughUpdates-REPO/master/items/" + id + ".json"; - URL url = new URL(urlString); - URLConnection request = url.openConnection(); - request.connect(); - - //yoinking the wiki link - JsonElement root = JsonParser.parseReader(new InputStreamReader((InputStream) request.getContent())); - JsonObject rootobj = root.getAsJsonObject(); - String wikiLink = rootobj.get("info").getAsJsonArray().get(1).getAsString(); - Util.getOperatingSystem().open(wikiLink); - } catch (IOException | NullPointerException e) { - e.printStackTrace(); - client.player.sendMessage(Text.of("Can't locate a wiki article for this item..."), false); + String wikiLink = ItemRegistry.getWikiLink(id); + CompletableFuture.runAsync(() -> Util.getOperatingSystem().open(wikiLink)); } catch (IndexOutOfBoundsException | IllegalStateException e) { e.printStackTrace(); - client.player.sendMessage(Text.of("Error while retrieving wiki article..."), false); + if (client.player != null) + client.player.sendMessage(Text.of("Error while retrieving wiki article..."), false); } } } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java index 7bfa0997..2bb16a34 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java @@ -4,13 +4,16 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.client.MinecraftClient; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import net.minecraft.text.Text; import org.eclipse.jgit.api.Git; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; @@ -24,6 +27,7 @@ public class ItemRegistry { protected static List items = new ArrayList<>(); protected static Map itemsMap = new HashMap<>(); protected static List recipes = new ArrayList<>(); + static final MinecraftClient client = MinecraftClient.getInstance(); // TODO: make async public static void init() { @@ -95,6 +99,18 @@ public class ItemRegistry { }); } + public static String getWikiLink(String internalName) { + try { + String fileContent = Files.readString(ITEM_LIST_DIR.resolve(internalName + ".json")); + JsonObject fileJson = JsonParser.parseString(fileContent).getAsJsonObject(); + return fileJson.get("info").getAsJsonArray().get(1).getAsString(); + } catch (IOException | NullPointerException e) { + e.printStackTrace(); + client.player.sendMessage(Text.of("Can't locate a wiki article for this item..."), false); + return null; + } + } + public static List getRecipes(String internalName) { List result = new ArrayList<>(); for (Recipe recipe : recipes) -- cgit From 47e9ec4135540eb03e2363ddfc6ca7535e77377e Mon Sep 17 00:00:00 2001 From: Fix3d Date: Fri, 24 Mar 2023 19:15:34 +0300 Subject: more readability for PriceInfoTooltip --- .../skyblocker/skyblock/item/PriceInfoTooltip.java | 157 +++++++++++---------- 1 file changed, 81 insertions(+), 76 deletions(-) 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 c7df6a99..608122ad 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java @@ -56,11 +56,9 @@ public class PriceInfoTooltip { if (SkyblockerConfig.get().general.itemTooltip.enableNPCPrice) { if (npcPricesJson == null) { - if (!nullMsgSend) { - client.player.sendMessage(Text.translatable("skyblocker.itemTooltip.nullMessage"), false); - nullMsgSend = true; - } - } else if (npcPricesJson.has(name)) { + nullWarning(); + } + else if (npcPricesJson.has(name)) { lines.add(Text.literal(String.format("%-21s", "NPC Price:")) .formatted(Formatting.YELLOW) .append(getCoinsMessage(npcPricesJson.get(name).getAsDouble(), count))); @@ -70,11 +68,9 @@ public class PriceInfoTooltip { boolean bazaarExist = false; if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice && !bazaarOpened) { if (bazaarPricesJson == null) { - if (!nullMsgSend) { - client.player.sendMessage(Text.translatable("skyblocker.itemTooltip.nullMessage"), false); - nullMsgSend = true; - } - } else if (bazaarPricesJson.has(name)) { + nullWarning(); + } + else if (bazaarPricesJson.has(name)) { JsonObject getItem = bazaarPricesJson.getAsJsonObject(name); lines.add(Text.literal(String.format("%-18s", "Bazaar buy Price:")) .formatted(Formatting.GOLD) @@ -93,11 +89,9 @@ public class PriceInfoTooltip { // bazaarOpened & bazaarExist check for lbin, because Skytils keeps some bazaar item data in lbin api if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN && !bazaarOpened && !bazaarExist) { if (lowestPricesJson == null) { - if (!nullMsgSend) { - client.player.sendMessage(Text.translatable("skyblocker.itemTooltip.nullMessage"), false); - nullMsgSend = true; - } - } else if (lowestPricesJson.has(name)) { + nullWarning(); + } + else if (lowestPricesJson.has(name)) { lines.add(Text.literal(String.format("%-19s", "Lowest BIN Price:")) .formatted(Formatting.GOLD) .append(getCoinsMessage(lowestPricesJson.get(name).getAsDouble(), count))); @@ -106,11 +100,9 @@ public class PriceInfoTooltip { if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN) { if (threeDayAvgPricesJson == null || oneDayAvgPricesJson == null) { - if (!nullMsgSend) { - client.player.sendMessage(Text.translatable("skyblocker.itemTooltip.nullMessage"), false); - nullMsgSend = true; - } - } else if (threeDayAvgPricesJson.has(name) || oneDayAvgPricesJson.has(name)) { + nullWarning(); + } + 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. @@ -156,11 +148,9 @@ public class PriceInfoTooltip { if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate && !bazaarOpened) { if (isMuseumJson == null) { - if (!nullMsgSend) { - client.player.sendMessage(Text.translatable("skyblocker.itemTooltip.nullMessage"), false); - nullMsgSend = true; - } - } else if (isMuseumJson.has(name)) { + nullWarning(); + } + else if (isMuseumJson.has(name)) { String itemCategory = isMuseumJson.get(name).toString().replaceAll("\"", ""); String format = switch (itemCategory) { case "Weapons" -> "%-18s"; @@ -170,15 +160,23 @@ public class PriceInfoTooltip { lines.add(Text.literal(String.format(format, "Museum: (" + itemCategory + ")")) .formatted(Formatting.LIGHT_PURPLE) .append(Text.literal(timestamp != null ? timestamp : "").formatted(Formatting.RED))); - } else if (timestamp != null) { + } + else if (timestamp != null) { lines.add(Text.literal(String.format("%-21s", "Obtained: ")) .formatted(Formatting.LIGHT_PURPLE) .append(Text.literal(timestamp).formatted(Formatting.RED))); } } } + + private static void nullWarning() { + if (!nullMsgSend && client.player != null) { + client.player.sendMessage(Text.translatable("skyblocker.itemTooltip.nullMessage"), false); + nullMsgSend = true; + } + } - public static NbtCompound getInternalNameForItem(ItemStack stack) { + public static NbtCompound getItemNBT(ItemStack stack) { if (stack == null) return null; return stack.getNbt(); } @@ -198,80 +196,85 @@ public class PriceInfoTooltip { * @return if the item have a "Timestamp" it will be shown formated on the tooltip */ public static String getTimestamp(ItemStack stack) { - NbtCompound tag = getInternalNameForItem(stack); - String internalName = null; + NbtCompound tag = getItemNBT(stack); + if (tag != null && tag.contains("ExtraAttributes", 10)) { NbtCompound ea = tag.getCompound("ExtraAttributes"); if (ea.contains("timestamp", 8)) { - internalName = ea.getString("timestamp"); - SimpleDateFormat dt = new SimpleDateFormat("MM/dd/yy"); + SimpleDateFormat nbtFormat = new SimpleDateFormat("MM/dd/yy"); try { - Date date = dt.parse(internalName); - SimpleDateFormat dt1 = new SimpleDateFormat("MMMM dd, yyyy", Locale.ENGLISH); - internalName = dt1.format(date); + Date date = nbtFormat.parse(ea.getString("timestamp")); + SimpleDateFormat skyblockerFormat = new SimpleDateFormat("MMMM dd, yyyy", Locale.ENGLISH); + return skyblockerFormat.format(date); } catch (ParseException e) { LOGGER.warn("[Skyblocker-tooltip] getTimestamp", e); } } } - return internalName; + + return null; } public static String getInternalNameFromNBT(ItemStack stack) { - NbtCompound tag = getInternalNameForItem(stack); - String internalName = null; + NbtCompound tag = getItemNBT(stack); if (tag != null && tag.contains("ExtraAttributes", 10)) { NbtCompound ea = tag.getCompound("ExtraAttributes"); if (ea.contains("id", 8)) { - internalName = ea.getString("id"); - } else { - return null; - } - - if ("ENCHANTED_BOOK".equals(internalName)) { - if (ea.contains("enchantments")) { - NbtCompound enchants = ea.getCompound("enchantments"); - String enchant = enchants.getKeys().stream().findFirst().get(); - internalName += "-" + enchant.toUpperCase(Locale.ENGLISH) + "-" + 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(Locale.ENGLISH) + "-" + ea.getInt("potion_level") - + enhanced + extended + splash; + String internalName = ea.getString("id"); + + // Transformation to API format. + if ("ENCHANTED_BOOK".equals(internalName)) { + if (ea.contains("enchantments")) { + NbtCompound enchants = ea.getCompound("enchantments"); + String enchant = enchants.getKeys().stream().findFirst().get(); + return internalName + "-" + enchant.toUpperCase(Locale.ENGLISH) + "-" + enchants.getInt(enchant); + } + } else if ("PET".equals(internalName)) { + if (ea.contains("petInfo")) { + JsonObject petInfo = gson.fromJson(ea.getString("petInfo"), JsonObject.class); + return 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")) { + return internalName + "-" + ea.getString("potion").toUpperCase(Locale.ENGLISH) + "-" + 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(); + return internalName + "-" + rune.toUpperCase(Locale.ENGLISH) + "-" + runes.getInt(rune); + } } - } else if ("RUNE".equals(internalName)) { - if (ea.contains("runes")) { - NbtCompound runes = ea.getCompound("runes"); - String rune = runes.getKeys().stream().findFirst().get(); - internalName += "-" + rune.toUpperCase(Locale.ENGLISH) + "-" + runes.getInt(rune); - } - } + return internalName; + } + else + return null; } - return internalName; + else + return null; } private static Text getCoinsMessage(double price, int count) { if (count == 1) { String priceString = String.format(Locale.ENGLISH, "%1$,.1f", price); return Text.literal(priceString + " Coins").formatted(Formatting.DARK_AQUA); - } else { - String priceString = String.format(Locale.ENGLISH, "%1$,.1f", price * count); - MutableText priceText = Text.literal(priceString + " Coins ").formatted(Formatting.DARK_AQUA); - priceString = String.format(Locale.ENGLISH, "%1$,.1f", price); - MutableText priceText2 = Text.literal( "(" + priceString + " each)").formatted(Formatting.GRAY); - return priceText.append(priceText2); + } + else { + String priceStringTotal = String.format(Locale.ENGLISH, "%1$,.1f", price * count); + MutableText priceTextTotal = Text.literal(priceStringTotal + " Coins ").formatted(Formatting.DARK_AQUA); + + String priceStringEach = String.format(Locale.ENGLISH, "%1$,.1f", price); + MutableText priceTextEach = Text.literal( "(" + priceStringEach + " each)").formatted(Formatting.GRAY); + + return priceTextTotal.append(priceTextEach); } } @@ -292,9 +295,11 @@ public class PriceInfoTooltip { if (type == SkyblockerConfig.Average.BOTH || oneDayAvgPricesJson == null || threeDayAvgPricesJson == null) { futureList.add(CompletableFuture.runAsync(() -> oneDayAvgPricesJson = downloadPrices("1 day avg"))); futureList.add(CompletableFuture.runAsync(() -> threeDayAvgPricesJson = downloadPrices("3 day avg"))); - } else if (type == SkyblockerConfig.Average.ONE_DAY) { + } + else if (type == SkyblockerConfig.Average.ONE_DAY) { futureList.add(CompletableFuture.runAsync(() -> oneDayAvgPricesJson = downloadPrices("1 day avg"))); - } else if (type == SkyblockerConfig.Average.THREE_DAY) { + } + else if (type == SkyblockerConfig.Average.THREE_DAY) { futureList.add(CompletableFuture.runAsync(() -> threeDayAvgPricesJson = downloadPrices("3 day avg"))); } } -- cgit From ea05cbb827c06ec7480a3006e39ccfec1c7bf137 Mon Sep 17 00:00:00 2001 From: Fix3d Date: Tue, 28 Mar 2023 10:54:30 +0300 Subject: async updateItemRepo --- .../skyblock/itemlist/ItemListWidget.java | 25 ++++++++++++++-------- .../skyblocker/skyblock/itemlist/ItemRegistry.java | 20 ++++++++++++----- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemListWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemListWidget.java index a635cea2..75d53323 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemListWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemListWidget.java @@ -13,7 +13,6 @@ import net.minecraft.client.render.GameRenderer; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.screen.AbstractRecipeScreenHandler; import net.minecraft.text.Text; -import net.minecraft.text.TranslatableTextContent; import net.minecraft.util.Formatting; @Environment(value= EnvType.CLIENT) @@ -39,8 +38,10 @@ public class ItemListWidget extends RecipeBookWidget implements Drawable, Select this.searchField = ((RecipeBookWidgetAccessor)this).getSearchField(); int x = (this.parentWidth - 147) / 2 - this.leftOffset; int y = (this.parentHeight - 166) / 2; - this.results = new SearchResultsWidget(this.client, x , y); - this.updateSearchResult(); + if (ItemRegistry.filesImported) { + this.results = new SearchResultsWidget(this.client, x, y); + this.updateSearchResult(); + } } @Override @@ -56,33 +57,39 @@ public class ItemListWidget extends RecipeBookWidget implements Drawable, Select int j = (this.parentHeight - 166) / 2; this.drawTexture(matrices, i, j, 1, 1, 147, 166); this.searchField = ((RecipeBookWidgetAccessor)this).getSearchField(); - if (!this.searchField.isFocused() && this.searchField.getText().isEmpty()) { + + if (!ItemRegistry.filesImported && !this.searchField.isFocused() && this.searchField.getText().isEmpty()) { + Text hintText = (Text.literal("Loading...")).formatted(Formatting.ITALIC).formatted(Formatting.GRAY); + drawTextWithShadow(matrices, this.client.textRenderer, hintText, i + 25, j + 14, -1); + } else if (!this.searchField.isFocused() && this.searchField.getText().isEmpty()) { Text hintText = (Text.translatable("gui.recipebook.search_hint")).formatted(Formatting.ITALIC).formatted(Formatting.GRAY); drawTextWithShadow(matrices, this.client.textRenderer, hintText, i + 25, j + 14, -1); } else { this.searchField.render(matrices, mouseX, mouseY, delta); } - this.updateSearchResult(); - this.results.render(matrices, mouseX, mouseY, delta); + if (ItemRegistry.filesImported && results != null){ + this.updateSearchResult(); + this.results.render(matrices, mouseX, mouseY, delta); + } matrices.pop(); } } @Override public void drawTooltip(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { - if (this.isOpen()) { + if (this.isOpen() && ItemRegistry.filesImported && results != null) { this.results.drawTooltip(matrices, mouseX, mouseY); } } @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (this.isOpen() && !this.client.player.isSpectator()) { + if (this.isOpen() && !this.client.player.isSpectator() && ItemRegistry.filesImported && results != null) { if (this.searchField.mouseClicked(mouseX, mouseY, button)) { this.results.closeRecipeView(); return true; } - if (this.results.mouseClicked(mouseX, mouseY, button)) return true; + return this.results.mouseClicked(mouseX, mouseY, button); } return false; } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java index 2bb16a34..f0958514 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java @@ -17,8 +17,10 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; +import java.util.concurrent.CompletableFuture; public class ItemRegistry { + private static final Logger LOGGER = LoggerFactory.getLogger(ItemRegistry.class); protected static final String REMOTE_ITEM_REPO = "https://github.com/NotEnoughUpdates/NotEnoughUpdates-REPO"; protected static final Path LOCAL_ITEM_REPO_DIR = FabricLoader.getInstance().getConfigDir().resolve("skyblocker/item-repo"); @@ -27,13 +29,20 @@ public class ItemRegistry { protected static List items = new ArrayList<>(); protected static Map itemsMap = new HashMap<>(); protected static List recipes = new ArrayList<>(); - static final MinecraftClient client = MinecraftClient.getInstance(); + protected static final MinecraftClient client = MinecraftClient.getInstance(); + static boolean filesImported = false; - // TODO: make async public static void init() { - updateItemRepo(); - ItemStackBuilder.init(); - importItemFiles(); + CompletableFuture.runAsync(ItemRegistry::updateItemRepo) + .whenComplete((result, ex) -> { + if (ex == null) { + ItemStackBuilder.init(); + importItemFiles(); + } + else { + LOGGER.error("[Skyblocker-ItemRegistry] " + ex); + } + }); } private static void updateItemRepo() { @@ -97,6 +106,7 @@ public class ItemRegistry { } return lhsFamilyName.compareTo(rhsFamilyName); }); + filesImported = true; } public static String getWikiLink(String internalName) { -- cgit From 16e61da08b98ecaaff5ce71458958178732f6d29 Mon Sep 17 00:00:00 2001 From: Fix3d Date: Wed, 29 Mar 2023 17:17:51 +0300 Subject: conflicts resolved --- .../java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java | 4 +++- .../skyblocker/skyblock/itemlist/ItemListWidget.java | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java index 4d3ce5e9..e711e681 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java @@ -66,7 +66,7 @@ public class SkyblockerConfig implements ConfigData { @ConfigEntry.Category("button8") @ConfigEntry.Gui.CollapsibleObject(startExpanded = false) - public QuickNavItem button8 = new QuickNavItem(true, new ItemData("player_head", 1, "tag:{SkullOwner:{Id:[I;1605800870,415127827,-1236127084,15358548],Properties:{textures:[{Value:\"e3RleHR1cmVzOntTS0lOOnt1cmw6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzg5MWQ1YjI3M2ZmMGJjNTBjOTYwYjJjZDg2ZWVmMWM0MGExYjk0MDMyYWU3MWU3NTQ3NWE1NjhhODI1NzQyMSJ9fX0=\"}]}}}"), "none", "/warp dungeon"); + public QuickNavItem button8 = new QuickNavItem(true, new ItemData("player_head", 1, "tag:{SkullOwner:{Id:[I;1605800870,415127827,-1236127084,15358548],Properties:{textures:[{Value:\"e3RleHR1cmVzOntTS0lOOnt1cmw6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzg5MWQ1YjI3M2ZmMGJjNTBjOTYwYjJjZDg2ZWVmMWM0MGExYjk0MDMyYWU3MWU3NTQ3NWE1NjhhODI1NzQyMSJ9fX0=\"}]}}}"), "none", "/warp dungeon_hub"); @ConfigEntry.Category("button9") @ConfigEntry.Gui.CollapsibleObject(startExpanded = false) @@ -174,6 +174,7 @@ public class SkyblockerConfig implements ConfigData { RIGHT, NONE; + @Override public String toString() { return switch (this) { case LAYER1 -> "Layer 1"; @@ -216,6 +217,7 @@ public class SkyblockerConfig implements ConfigData { THREE_DAY, BOTH; + @Override public String toString() { return switch (this) { case ONE_DAY -> "1 day avg"; diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemListWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemListWidget.java index 75d53323..7434b92b 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemListWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemListWidget.java @@ -49,7 +49,7 @@ public class ItemListWidget extends RecipeBookWidget implements Drawable, Select if (this.isOpen()) { matrices.push(); matrices.translate(0.0D, 0.0D, 100.0D); - RenderSystem.setShader(GameRenderer::getPositionTexShader); + RenderSystem.setShader(GameRenderer::getPositionTexProgram); RenderSystem.setShaderTexture(0, TEXTURE); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); this.searchField = ((RecipeBookWidgetAccessor)this).getSearchField(); @@ -88,9 +88,9 @@ public class ItemListWidget extends RecipeBookWidget implements Drawable, Select if (this.searchField.mouseClicked(mouseX, mouseY, button)) { this.results.closeRecipeView(); return true; - } - return this.results.mouseClicked(mouseX, mouseY, button); - } - return false; + } else + return this.results.mouseClicked(mouseX, mouseY, button); + } else + return false; } -} +} \ No newline at end of file -- cgit From da7f2e8dc92f40764d71a1408dd5d4a9add7625f Mon Sep 17 00:00:00 2001 From: Fix3d Date: Wed, 29 Mar 2023 17:45:11 +0300 Subject: forgotten null check --- .../java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemListWidget.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemListWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemListWidget.java index 7434b92b..86fe580d 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemListWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemListWidget.java @@ -85,7 +85,7 @@ public class ItemListWidget extends RecipeBookWidget implements Drawable, Select @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { if (this.isOpen() && !this.client.player.isSpectator() && ItemRegistry.filesImported && results != null) { - if (this.searchField.mouseClicked(mouseX, mouseY, button)) { + if (this.searchField != null && this.searchField.mouseClicked(mouseX, mouseY, button)) { this.results.closeRecipeView(); return true; } else -- cgit From d7a62f213b0bddae9b1cc925b7626b8f4cb25823 Mon Sep 17 00:00:00 2001 From: Fix3d Date: Sat, 15 Apr 2023 00:33:36 +0300 Subject: fix average price on pets and some cleanup for timestamp --- .../skyblocker/skyblock/item/PriceInfoTooltip.java | 92 ++++++++++++---------- 1 file changed, 49 insertions(+), 43 deletions(-) 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 608122ad..e0cb97aa 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java @@ -51,7 +51,6 @@ public class PriceInfoTooltip { if (name == null) return; int count = stack.getCount(); - String timestamp = getTimestamp(stack); boolean bazaarOpened = lines.stream().anyMatch(each -> each.getString().contains("Buy price:") || each.getString().contains("Sell price:")); if (SkyblockerConfig.get().general.itemTooltip.enableNPCPrice) { @@ -102,46 +101,50 @@ public class PriceInfoTooltip { if (threeDayAvgPricesJson == null || oneDayAvgPricesJson == null) { nullWarning(); } - else if (threeDayAvgPricesJson.has(name) || oneDayAvgPricesJson.has(name)) { + else { /* - We are skipping check average prices for potions and runes - because there is no data for their in API. + We are skipping check average prices for potions, runes + and enchanted books because there is no data for their in API. */ if (name.contains("PET-")) { name = name.replace("PET-", "") - .replace("COMMON", "0") .replace("UNCOMMON", "1") + .replace("COMMON", "0") .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-")) { + } else if (name.contains("POTION-") || name.contains("RUNE-") || name.contains("ENCHANTED_BOOK-")) { name = ""; } else { name = name.replace(":", "-"); } - 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)) { - lines.add(Text.literal(String.format("%-19s", "1 Day Avg. Price:")) - .formatted(Formatting.GOLD) - .append(oneDayAvgPricesJson.get(name) == null - ? Text.literal("No data").formatted(Formatting.RED) - : getCoinsMessage(oneDayAvgPricesJson.get(name).getAsDouble(), count))); - } - if (!name.isEmpty() && (type == SkyblockerConfig.Average.THREE_DAY || type == SkyblockerConfig.Average.BOTH)) { - lines.add(Text.literal(String.format("%-19s", "3 Day Avg. Price:")) - .formatted(Formatting.GOLD) - .append(threeDayAvgPricesJson.get(name) == null - ? Text.literal("No data").formatted(Formatting.RED) - : getCoinsMessage(threeDayAvgPricesJson.get(name).getAsDouble(), count))); + if (!name.isEmpty() && (threeDayAvgPricesJson.has(name) || oneDayAvgPricesJson.has(name))) { + SkyblockerConfig.Average type = SkyblockerConfig.get().general.itemTooltip.avg; + + // "No data" line because of API not keeping old data, it causes NullPointerException + if (type == SkyblockerConfig.Average.ONE_DAY || type == SkyblockerConfig.Average.BOTH) { + lines.add( + Text.literal(String.format("%-19s", "1 Day Avg. Price:")) + .formatted(Formatting.GOLD) + .append(oneDayAvgPricesJson.get(name) == null + ? Text.literal("No data").formatted(Formatting.RED) + : getCoinsMessage(oneDayAvgPricesJson.get(name).getAsDouble(), count) + ) + ); + } + if (type == SkyblockerConfig.Average.THREE_DAY || type == SkyblockerConfig.Average.BOTH) { + lines.add( + Text.literal(String.format("%-19s", "3 Day Avg. Price:")) + .formatted(Formatting.GOLD) + .append(threeDayAvgPricesJson.get(name) == null + ? Text.literal("No data").formatted(Formatting.RED) + : getCoinsMessage(threeDayAvgPricesJson.get(name).getAsDouble(), count) + ) + ); + } } } } @@ -149,22 +152,25 @@ public class PriceInfoTooltip { if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate && !bazaarOpened) { if (isMuseumJson == null) { nullWarning(); - } - 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(Text.literal(String.format(format, "Museum: (" + itemCategory + ")")) - .formatted(Formatting.LIGHT_PURPLE) - .append(Text.literal(timestamp != null ? timestamp : "").formatted(Formatting.RED))); - } - else if (timestamp != null) { - lines.add(Text.literal(String.format("%-21s", "Obtained: ")) - .formatted(Formatting.LIGHT_PURPLE) - .append(Text.literal(timestamp).formatted(Formatting.RED))); + } + else { + String timestamp = getTimestamp(stack); + + 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(Text.literal(String.format(format, "Museum: (" + itemCategory + ")")) + .formatted(Formatting.LIGHT_PURPLE) + .append(Text.literal(timestamp).formatted(Formatting.RED))); + } else if (!timestamp.isEmpty()) { + lines.add(Text.literal(String.format("%-21s", "Obtained: ")) + .formatted(Formatting.LIGHT_PURPLE) + .append(Text.literal(timestamp).formatted(Formatting.RED))); + } } } } @@ -214,7 +220,7 @@ public class PriceInfoTooltip { } } - return null; + return ""; } public static String getInternalNameFromNBT(ItemStack stack) { -- cgit From 21b64be8d85d37e107ffd628416031e0839c9990 Mon Sep 17 00:00:00 2001 From: Fix3d Date: Sun, 16 Apr 2023 05:39:40 +0300 Subject: add update repository command "/skyblocker updaterepository" --- .../me/xmrvizzy/skyblocker/SkyblockerInitializer.java | 2 ++ .../skyblocker/skyblock/itemlist/ItemRegistry.java | 18 +++++++----------- src/main/resources/assets/skyblocker/lang/en_us.json | 2 ++ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/xmrvizzy/skyblocker/SkyblockerInitializer.java b/src/main/java/me/xmrvizzy/skyblocker/SkyblockerInitializer.java index 3d713727..f17ab1fb 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/SkyblockerInitializer.java +++ b/src/main/java/me/xmrvizzy/skyblocker/SkyblockerInitializer.java @@ -4,6 +4,7 @@ import me.xmrvizzy.skyblocker.chat.ChatMessageListener; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import me.xmrvizzy.skyblocker.discord.DiscordRPCManager; import me.xmrvizzy.skyblocker.skyblock.HotbarSlotLock; +import me.xmrvizzy.skyblocker.skyblock.api.RepositoryUpdate; import me.xmrvizzy.skyblocker.skyblock.api.StatsCommand; import me.xmrvizzy.skyblocker.skyblock.dwarven.DwarvenHud; import me.xmrvizzy.skyblocker.skyblock.item.PriceInfoTooltip; @@ -20,6 +21,7 @@ public class SkyblockerInitializer implements ClientModInitializer { PriceInfoTooltip.init(); WikiLookup.init(); ItemRegistry.init(); + RepositoryUpdate.init(); StatsCommand.init(); DwarvenHud.init(); ChatMessageListener.init(); diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java index ea7184cc..91a59fcb 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java @@ -22,15 +22,15 @@ import java.util.concurrent.CompletableFuture; public class ItemRegistry { private static final Logger LOGGER = LoggerFactory.getLogger(ItemRegistry.class); protected static final String REMOTE_ITEM_REPO = "https://github.com/NotEnoughUpdates/NotEnoughUpdates-REPO"; - protected static final Path LOCAL_ITEM_REPO_DIR = FabricLoader.getInstance().getConfigDir().resolve("skyblocker/item-repo"); + public static final Path LOCAL_ITEM_REPO_DIR = FabricLoader.getInstance().getConfigDir().resolve("skyblocker/item-repo"); - private static final Path ITEM_LIST_DIR = LOCAL_ITEM_REPO_DIR.resolve("items"); + protected static final Path ITEM_LIST_DIR = LOCAL_ITEM_REPO_DIR.resolve("items"); protected static final List items = new ArrayList<>(); protected static final Map itemsMap = new HashMap<>(); protected static final List recipes = new ArrayList<>(); - protected static final MinecraftClient client = MinecraftClient.getInstance(); - static boolean filesImported = false; + public static final MinecraftClient client = MinecraftClient.getInstance(); + public static boolean filesImported = false; public static void init() { CompletableFuture.runAsync(ItemRegistry::updateItemRepo) @@ -46,20 +46,16 @@ public class ItemRegistry { } private static void updateItemRepo() { + Git git; if (!Files.isDirectory(LOCAL_ITEM_REPO_DIR)) { try { - Git.cloneRepository() + git = Git.cloneRepository() .setURI(REMOTE_ITEM_REPO) .setDirectory(LOCAL_ITEM_REPO_DIR.toFile()) .setBranchesToClone(List.of("refs/heads/master")) .setBranch("refs/heads/master") .call(); - } catch (Exception e) { - e.printStackTrace(); - } - } else { - try { - Git.open(LOCAL_ITEM_REPO_DIR.toFile()).pull().call(); + git.close(); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 8e7e4041..c0f540b6 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -96,5 +96,7 @@ "skyblocker.update.hover_text": "Open Modrinth", "text.autoconfig.skyblocker.option.general.enableUpdateNotification": "Update Notification", + "skyblocker.updaterepository.failed": "§b[§6Skyblocker§b] §cUpdating local repository failed. Remove files manually and restart game.", + "skyblocker.api.got_key": "§b[§6Skyblocker§b] §2Automatically set your API key!" } -- cgit From a32e5f58919d7af7a2a86e5a3152146e54f0c552 Mon Sep 17 00:00:00 2001 From: Fix3d Date: Sun, 16 Apr 2023 05:48:36 +0300 Subject: forgot unversioned files :P --- .../skyblocker/skyblock/api/RepositoryUpdate.java | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/main/java/me/xmrvizzy/skyblocker/skyblock/api/RepositoryUpdate.java diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/RepositoryUpdate.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/RepositoryUpdate.java new file mode 100644 index 00000000..db039559 --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/RepositoryUpdate.java @@ -0,0 +1,52 @@ +package me.xmrvizzy.skyblocker.skyblock.api; + +import me.xmrvizzy.skyblocker.skyblock.itemlist.ItemRegistry; +import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; +import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; +import net.minecraft.text.Text; + +import java.io.File; +import java.nio.file.Files; +import java.util.concurrent.CompletableFuture; + +public class RepositoryUpdate { + + //TODO add button to config for this + public static void init(){ + ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register( + ClientCommandManager.literal("skyblocker") + .then(ClientCommandManager.literal("updaterepository") + .executes(context -> { + CompletableFuture.runAsync(() -> { + try { + ItemRegistry.filesImported = false; + File dir = ItemRegistry.LOCAL_ITEM_REPO_DIR.toFile(); + recursiveDelete(dir); + } catch (Exception ex) { + ItemRegistry.client.player.sendMessage( + Text.translatable("skyblocker.updaterepository.failed") + , false + ); + return; + } + + ItemRegistry.init(); + }); + + return 1; + }) + ) + ) + ); + + } + + private static void recursiveDelete(File dir) { + if (dir.isDirectory() && !Files.isSymbolicLink(dir.toPath())) { + for (File child : dir.listFiles()) { + recursiveDelete(child); + } + } + dir.delete(); + } +} -- cgit From 06db7ab46b5d6bd33bbc584172c43e88dce998e1 Mon Sep 17 00:00:00 2001 From: Fix3d Date: Sat, 22 Apr 2023 13:54:53 +0300 Subject: now runes have avg prices --- .../skyblocker/skyblock/item/PriceInfoTooltip.java | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) 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 e0cb97aa..d9263f9a 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java @@ -86,6 +86,7 @@ public class PriceInfoTooltip { } // bazaarOpened & bazaarExist check for lbin, because Skytils keeps some bazaar item data in lbin api + boolean lbinExist = false; if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN && !bazaarOpened && !bazaarExist) { if (lowestPricesJson == null) { nullWarning(); @@ -94,6 +95,7 @@ public class PriceInfoTooltip { lines.add(Text.literal(String.format("%-19s", "Lowest BIN Price:")) .formatted(Formatting.GOLD) .append(getCoinsMessage(lowestPricesJson.get(name).getAsDouble(), count))); + lbinExist = true; } } @@ -115,13 +117,16 @@ public class PriceInfoTooltip { .replace("LEGENDARY", "4") .replace("MYTHIC", "5") .replace("-", ";"); - } else if (name.contains("POTION-") || name.contains("RUNE-") || name.contains("ENCHANTED_BOOK-")) { + } else if (name.contains("RUNE-")) { + name = name.replace("RUNE-", ""); + name = name.substring(0, name.indexOf("-")) + "_RUNE;" + name.substring(name.lastIndexOf("-") + 1); + } else if (name.contains("POTION-") || name.contains("ENCHANTED_BOOK-")) { name = ""; } else { name = name.replace(":", "-"); } - if (!name.isEmpty() && (threeDayAvgPricesJson.has(name) || oneDayAvgPricesJson.has(name))) { + if (!name.isEmpty() && lbinExist) { SkyblockerConfig.Average type = SkyblockerConfig.get().general.itemTooltip.avg; // "No data" line because of API not keeping old data, it causes NullPointerException @@ -244,12 +249,13 @@ public class PriceInfoTooltip { return internalName + "-" + petInfo.get("type").getAsString() + "-" + petInfo.get("tier").getAsString(); } } else if ("POTION".equals(internalName)) { + // New API just contains 'enhanced' tag. String enhanced = ea.contains("enhanced") ? "-ENHANCED" : ""; - String extended = ea.contains("extended") ? "-EXTENDED" : ""; - String splash = ea.contains("splash") ? "-SPLASH" : ""; + //String extended = ea.contains("extended") ? "-EXTENDED" : ""; + //String splash = ea.contains("splash") ? "-SPLASH" : ""; if (ea.contains("potion") && ea.contains("potion_level")) { return internalName + "-" + ea.getString("potion").toUpperCase(Locale.ENGLISH) + "-" + ea.getInt("potion_level") - + enhanced + extended + splash; + + enhanced; //+ extended + splash; } } else if ("RUNE".equals(internalName)) { if (ea.contains("runes")) { @@ -310,7 +316,7 @@ public class PriceInfoTooltip { } } if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN) - futureList.add(CompletableFuture.runAsync(() -> lowestPricesJson = downloadPrices("lowest bin"))); + futureList.add(CompletableFuture.runAsync(() -> lowestPricesJson = downloadPrices("lowest bins"))); if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice) futureList.add(CompletableFuture.runAsync(() -> bazaarPricesJson = downloadPrices("bazaar"))); @@ -337,8 +343,8 @@ public class PriceInfoTooltip { } catch (IOException e) { LOGGER.warn("[Skyblocker] Failed to download " + type + " prices!", e); - if (type.equals("lowest bin")) - lowestPricesJson = downloadPrices("lowest bin backup"); + if (type.equals("lowest bins")) + lowestPricesJson = downloadPrices("lowest bins backup"); return null; } @@ -349,8 +355,8 @@ public class PriceInfoTooltip { apiAddresses.put("1 day avg", "https://moulberry.codes/auction_averages_lbin/1day.json.gz"); apiAddresses.put("3 day avg", "https://moulberry.codes/auction_averages_lbin/3day.json.gz"); apiAddresses.put("bazaar", "https://hysky.de/api/bazaar"); - apiAddresses.put("lowest bin", "https://lb.tricked.pro/lowestbins"); - apiAddresses.put("lowest bin backup", "https://lb2.tricked.pro/lowestbins"); + apiAddresses.put("lowest bins", "https://lb.tricked.pro/lowestbins"); + apiAddresses.put("lowest bins backup", "https://lb2.tricked.pro/lowestbins"); apiAddresses.put("npc", "https://hysky.de/api/npcprice"); apiAddresses.put("museum", "https://hysky.de/api/museum"); } -- cgit From 6e58eddaab6d2830976ee06ae1f3b2801308408c Mon Sep 17 00:00:00 2001 From: Fix3d Date: Sat, 22 Apr 2023 14:21:49 +0300 Subject: fix wikiLink --- .../me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java index 91a59fcb..0a581da8 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java @@ -109,7 +109,12 @@ public class ItemRegistry { try { String fileContent = Files.readString(ITEM_LIST_DIR.resolve(internalName + ".json")); JsonObject fileJson = JsonParser.parseString(fileContent).getAsJsonObject(); - return fileJson.get("info").getAsJsonArray().get(1).getAsString(); + //TODO optional official or unofficial wiki link + try { + return fileJson.get("info").getAsJsonArray().get(1).getAsString(); + } catch (IndexOutOfBoundsException e) { + return fileJson.get("info").getAsJsonArray().get(0).getAsString(); + } } catch (IOException | NullPointerException e) { e.printStackTrace(); client.player.sendMessage(Text.of("Can't locate a wiki article for this item..."), false); -- cgit From a47c68f022809c33f149f90af14d1c20bf271bad Mon Sep 17 00:00:00 2001 From: Fix3d Date: Sun, 14 May 2023 00:23:25 +0300 Subject: revert jgit pull with some modifications --- .../skyblocker/skyblock/api/RepositoryUpdate.java | 6 +++++- .../skyblocker/skyblock/itemlist/ItemListWidget.java | 7 ++++++- .../skyblocker/skyblock/itemlist/ItemRegistry.java | 18 +++++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/RepositoryUpdate.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/RepositoryUpdate.java index db039559..3854dd88 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/RepositoryUpdate.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/RepositoryUpdate.java @@ -11,7 +11,11 @@ import java.util.concurrent.CompletableFuture; public class RepositoryUpdate { - //TODO add button to config for this + /** + * Adds command to update repository manually from ingame. + *

+ * TODO A button could be added to the settings menu that will trigger this command. + */ public static void init(){ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register( ClientCommandManager.literal("skyblocker") diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemListWidget.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemListWidget.java index e99d6dac..d9acc75c 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemListWidget.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemListWidget.java @@ -68,7 +68,12 @@ public class ItemListWidget extends RecipeBookWidget implements Drawable, Select } else { this.searchField.render(matrices, mouseX, mouseY, delta); } - if (ItemRegistry.filesImported && results != null){ + if (ItemRegistry.filesImported){ + if (results == null) { + int x = (this.parentWidth - 147) / 2 - this.leftOffset; + int y = (this.parentHeight - 166) / 2; + this.results = new SearchResultsWidget(this.client, x, y); + } this.updateSearchResult(); this.results.render(matrices, mouseX, mouseY, delta); } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java index 0a581da8..68f587bc 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java @@ -9,6 +9,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.text.Text; import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.PullResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,16 +47,27 @@ public class ItemRegistry { } private static void updateItemRepo() { - Git git; if (!Files.isDirectory(LOCAL_ITEM_REPO_DIR)) { try { - git = Git.cloneRepository() + Git.cloneRepository() .setURI(REMOTE_ITEM_REPO) .setDirectory(LOCAL_ITEM_REPO_DIR.toFile()) .setBranchesToClone(List.of("refs/heads/master")) .setBranch("refs/heads/master") .call(); - git.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + try { + PullResult pull = Git.open(LOCAL_ITEM_REPO_DIR.toFile()).pull().setRebase(true).call(); + if (pull.getRebaseResult() == null) { + LOGGER.info("[Skyblocker Repository Update] No update result"); + } else if (pull.getRebaseResult().getStatus().isSuccessful()) { + LOGGER.info("[Skyblocker Repository Update] Status: " + pull.getRebaseResult().getStatus().name()); + } else if (!pull.getRebaseResult().getStatus().isSuccessful()) { + LOGGER.warn("[Skyblocker Repository Update] Status: " + pull.getRebaseResult().getStatus().name()); + } } catch (Exception e) { e.printStackTrace(); } -- cgit