diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java | 92 | 
1 files 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) { | 
