aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/xmrvizzy/skyblocker/skyblock
diff options
context:
space:
mode:
authorFix3d <serhanduzce@gmail.com>2023-03-24 19:15:34 +0300
committerFix3d <serhanduzce@gmail.com>2023-03-24 19:15:34 +0300
commit47e9ec4135540eb03e2363ddfc6ca7535e77377e (patch)
tree47080d3b9328bc1d85bdfc7a09b75cd7936f88c8 /src/main/java/me/xmrvizzy/skyblocker/skyblock
parent4a3b5a00c174d9c7abe2cfaed84ac09bf464650a (diff)
downloadSkyblocker-47e9ec4135540eb03e2363ddfc6ca7535e77377e.tar.gz
Skyblocker-47e9ec4135540eb03e2363ddfc6ca7535e77377e.tar.bz2
Skyblocker-47e9ec4135540eb03e2363ddfc6ca7535e77377e.zip
more readability for PriceInfoTooltip
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock')
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java157
1 files 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")));
}
}