aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java187
1 files changed, 99 insertions, 88 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java b/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java
index 1804831b..a773abdc 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/ItemPriceInformation.java
@@ -1,18 +1,46 @@
+/*
+ * Copyright (C) 2022 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
package io.github.moulberry.notenoughupdates;
import com.google.gson.Gson;
+import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.auction.APIManager;
import io.github.moulberry.notenoughupdates.core.config.KeybindHelper;
import io.github.moulberry.notenoughupdates.util.Constants;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.item.ItemStack;
-import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import org.lwjgl.input.Keyboard;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.HashSet;
import java.util.List;
@@ -23,6 +51,7 @@ public class ItemPriceInformation {
private static File file;
private static HashSet<String> auctionableItems = null;
private static Gson gson;
+ private static final NumberFormat format = new DecimalFormat("#,##0.#", new DecimalFormatSymbols(Locale.US));
public static boolean addToTooltip(List<String> tooltip, String internalname, ItemStack stack) {
return addToTooltip(tooltip, internalname, stack, true);
@@ -75,27 +104,24 @@ public class ItemPriceInformation {
}
JsonObject auctionInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAuctionInfo(internalname);
JsonObject bazaarInfo = NotEnoughUpdates.INSTANCE.manager.auctionManager.getBazaarInfo(internalname);
- float lowestBinAvg = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAvgBin(internalname);
+ double lowestBinAvg = NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAvgBin(internalname);
- int lowestBin = NotEnoughUpdates.INSTANCE.manager.auctionManager.getLowestBin(internalname);
+ double lowestBin = NotEnoughUpdates.INSTANCE.manager.auctionManager.getLowestBin(internalname);
APIManager.CraftInfo craftCost = NotEnoughUpdates.INSTANCE.manager.auctionManager.getCraftCost(internalname);
+ boolean bazaarItem = bazaarInfo != null;
- boolean auctionItem = lowestBin > 0 || lowestBinAvg > 0;
+ boolean auctionItem = !bazaarItem;
boolean auctionInfoErrored = auctionInfo == null;
if (auctionItem) {
long currentTime = System.currentTimeMillis();
long lastUpdate = NotEnoughUpdates.INSTANCE.manager.auctionManager.getLastLowestBinUpdateTime();
//check if info is older than 10 minutes
- if (currentTime - lastUpdate > 600 * 1000) {
+ if (currentTime - lastUpdate > 600 * 1000 && NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) {
tooltip.add(EnumChatFormatting.RED + "[NEU] Price info is outdated.");
tooltip.add(EnumChatFormatting.RED + "It will be updated again as soon as possible.");
}
}
- boolean bazaarItem = bazaarInfo != null;
-
- NumberFormat format = NumberFormat.getInstance(Locale.US);
- boolean shortNumber = NotEnoughUpdates.INSTANCE.config.tooltipTweaks.shortNumberFormatPrices;
if (bazaarItem) {
List<Integer> lines = NotEnoughUpdates.INSTANCE.config.tooltipTweaks.priceInfoBaz;
@@ -120,11 +146,8 @@ public class ItemPriceInformation {
tooltip.add(EnumChatFormatting.DARK_GRAY + "[SHIFT show x" + shiftStackMultiplier + "]");
added = true;
}
- int bazaarBuyPrice = (int) bazaarInfo.get("avg_buy").getAsFloat() * stackMultiplier;
- tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Bazaar Buy: " +
- EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + (shortNumber && bazaarBuyPrice > 1000
- ? Utils.shortNumberFormat(bazaarBuyPrice, 0)
- : format.format(bazaarBuyPrice)) + " coins");
+ double bazaarBuyPrice = bazaarInfo.get("avg_buy").getAsFloat() * stackMultiplier;
+ tooltip.add(formatPrice("Bazaar Buy: ", bazaarBuyPrice));
}
break;
case 1:
@@ -135,11 +158,8 @@ public class ItemPriceInformation {
tooltip.add(EnumChatFormatting.DARK_GRAY + "[SHIFT show x" + shiftStackMultiplier + "]");
added = true;
}
- int bazaarSellPrice = (int) bazaarInfo.get("avg_sell").getAsFloat() * stackMultiplier;
- tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Bazaar Sell: " +
- EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + (shortNumber && bazaarSellPrice > 1000
- ? Utils.shortNumberFormat(bazaarSellPrice, 0)
- : format.format(bazaarSellPrice)) + " coins");
+ double bazaarSellPrice = bazaarInfo.get("avg_sell").getAsDouble() * stackMultiplier;
+ tooltip.add(formatPrice("Bazaar Sell: ", bazaarSellPrice));
}
break;
case 2:
@@ -150,12 +170,8 @@ public class ItemPriceInformation {
tooltip.add(EnumChatFormatting.DARK_GRAY + "[SHIFT show x" + shiftStackMultiplier + "]");
added = true;
}
- int bazaarInstantBuyPrice = (int) bazaarInfo.get("curr_buy").getAsFloat() * stackMultiplier;
- tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Bazaar Insta-Buy: " +
- EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + (shortNumber && bazaarInstantBuyPrice > 1000
- ? Utils.shortNumberFormat(bazaarInstantBuyPrice, 0)
- : format.format(bazaarInstantBuyPrice)) +
- " coins");
+ double bazaarInstantBuyPrice = bazaarInfo.get("curr_buy").getAsFloat() * stackMultiplier;
+ tooltip.add(formatPrice("Bazaar Insta-Buy: ", bazaarInstantBuyPrice));
}
break;
case 3:
@@ -166,32 +182,22 @@ public class ItemPriceInformation {
tooltip.add(EnumChatFormatting.DARK_GRAY + "[SHIFT show x" + shiftStackMultiplier + "]");
added = true;
}
- int bazaarInstantSellPrice = (int) bazaarInfo.get("curr_sell").getAsFloat() * stackMultiplier;
- tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Bazaar Insta-Sell: " +
- EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + (shortNumber && bazaarInstantSellPrice > 1000
- ? Utils.shortNumberFormat(
- bazaarInstantSellPrice,
- 0
- )
- : format.format(bazaarInstantSellPrice)) +
- " coins");
+ double bazaarInstantSellPrice = bazaarInfo.get("curr_sell").getAsFloat() * stackMultiplier;
+ tooltip.add(formatPrice("Bazaar Insta-Sell: ", bazaarInstantSellPrice));
}
break;
case 4:
if (craftCost != null && craftCost.fromRecipe) {
- if ((int) craftCost.craftCost == 0) {
+ if (craftCost.craftCost == 0) {
continue;
}
if (!added) {
tooltip.add("");
added = true;
}
- float cost = craftCost.craftCost;
+ double cost = craftCost.craftCost;
if (shiftPressed) cost = cost * shiftStackMultiplier;
-
- tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Raw Craft Cost: " +
- EnumChatFormatting.GOLD + EnumChatFormatting.BOLD +
- (shortNumber && cost > 1000 ? Utils.shortNumberFormat(cost, 0) : format.format((int) cost)) + " coins");
+ tooltip.add(formatPrice("Raw Craft Cost: ", cost));
}
break;
}
@@ -211,8 +217,7 @@ public class ItemPriceInformation {
tooltip.add("");
added = true;
}
- tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Lowest BIN: " +
- EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + format.format(lowestBin) + " coins");
+ tooltip.add(formatPrice("Lowest BIN: ", lowestBin));
}
break;
case 1:
@@ -223,21 +228,11 @@ public class ItemPriceInformation {
}
if (auctionInfo.has("clean_price")) {
- tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "AH Price (Clean): " +
- EnumChatFormatting.GOLD + EnumChatFormatting.BOLD +
- (shortNumber && auctionInfo.get("clean_price").getAsFloat() > 1000 ? Utils.shortNumberFormat(
- auctionInfo.get("clean_price").getAsFloat(),
- 0
- ) : format.format((int) auctionInfo.get("clean_price").getAsFloat())
- + " coins"));
+ double cleanPrice = auctionInfo.get("clean_price").getAsDouble();
+ tooltip.add(formatPrice("AH Price (Clean): ", cleanPrice));
} else {
- int auctionPrice =
- (int) (auctionInfo.get("price").getAsFloat() / auctionInfo.get("count").getAsFloat());
- tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "AH Price: " +
- EnumChatFormatting.GOLD + EnumChatFormatting.BOLD +
- (shortNumber && auctionPrice > 1000
- ? Utils.shortNumberFormat(auctionPrice, 0)
- : format.format(auctionPrice)) + " coins");
+ double auctionPrice = auctionInfo.get("price").getAsDouble() / auctionInfo.get("count").getAsFloat();
+ tooltip.add(formatPrice("AH Price: ", auctionPrice));
}
}
@@ -267,18 +262,14 @@ public class ItemPriceInformation {
break;
case 3:
if (craftCost != null && craftCost.fromRecipe) {
- if ((int) craftCost.craftCost == 0) {
+ if (craftCost.craftCost == 0) {
continue;
}
if (!added) {
tooltip.add("");
added = true;
}
- tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Raw Craft Cost: " +
- EnumChatFormatting.GOLD + EnumChatFormatting.BOLD +
- (shortNumber && craftCost.craftCost > 1000
- ? Utils.shortNumberFormat(craftCost.craftCost, 0)
- : format.format((int) craftCost.craftCost)) + " coins");
+ tooltip.add(formatPrice("Raw Craft Cost: ", craftCost.craftCost));
}
break;
case 4:
@@ -287,11 +278,7 @@ public class ItemPriceInformation {
tooltip.add("");
added = true;
}
- tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "AVG Lowest BIN: " +
- EnumChatFormatting.GOLD + EnumChatFormatting.BOLD +
- (shortNumber && lowestBinAvg > 1000
- ? Utils.shortNumberFormat(lowestBinAvg, 0)
- : format.format(lowestBinAvg)) + " coins");
+ tooltip.add(formatPrice("AVG Lowest BIN: ", lowestBinAvg));
}
break;
case 5:
@@ -302,41 +289,56 @@ public class ItemPriceInformation {
}
JsonObject itemCosts = essenceCosts.get(internalname).getAsJsonObject();
String essenceType = itemCosts.get("type").getAsString();
+ boolean requiresItems = false;
+ JsonObject itemsObject = null;
+ if (itemCosts.has("items")) {
+ requiresItems = true;
+ itemsObject = itemCosts.get("items").getAsJsonObject();
+ }
- int dungeonItemLevel = -1;
- if (stack != null && stack.hasTagCompound() &&
- stack.getTagCompound().hasKey("ExtraAttributes", 10)) {
- NBTTagCompound ea = stack.getTagCompound().getCompoundTag("ExtraAttributes");
+ int dungeonItemLevel = Utils.getNumberOfStars(stack);
- if (ea.hasKey("dungeon_item_level", 99)) {
- dungeonItemLevel = ea.getInteger("dungeon_item_level");
- }
- }
if (dungeonItemLevel == -1) {
int dungeonizeCost = 0;
if (itemCosts.has("dungeonize")) {
dungeonizeCost = itemCosts.get("dungeonize").getAsInt();
}
- tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Dungeonize Cost: " +
- EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + dungeonizeCost + " " + essenceType);
- } else if (dungeonItemLevel >= 0 && dungeonItemLevel <= 4) {
- String costType = (dungeonItemLevel + 1) + "";
- int upgradeCost = itemCosts.get(costType).getAsInt();
- StringBuilder star = new StringBuilder();
- for (int i = 0; i <= dungeonItemLevel; i++) {
- star.append('\u272A');
+ if (dungeonizeCost > 0) {
+ tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Dungeonize Cost: " +
+ EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + dungeonizeCost + " " + essenceType);
+ }
+ } else if (dungeonItemLevel >= 0) {
+ String nextStarLevelString = (dungeonItemLevel + 1) + "";
+ int nextStarLevelInt = Integer.parseInt(nextStarLevelString);
+
+ if (itemCosts.has(nextStarLevelString)) {
+ int upgradeCost = itemCosts.get(nextStarLevelString).getAsInt();
+ String starString = Utils.getStarsString(nextStarLevelInt);
+ tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Upgrade to " +
+ starString + EnumChatFormatting.YELLOW + EnumChatFormatting.BOLD + ": " +
+ EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + upgradeCost + " " + essenceType);
+ if (requiresItems && itemsObject.has(nextStarLevelString)) {
+ boolean shouldShow = Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) ||
+ NotEnoughUpdates.INSTANCE.config.tooltipTweaks.alwaysShowRequiredItems;
+
+ if (shouldShow) {
+ tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Required Items:");
+ for (JsonElement item : itemsObject.get(nextStarLevelString).getAsJsonArray()) {
+ tooltip.add(" - " + item.getAsString());
+ }
+ } else {
+ tooltip.add(EnumChatFormatting.DARK_GRAY + "[CTRL to show required items]");
+ }
+ }
}
- tooltip.add(EnumChatFormatting.YELLOW.toString() + EnumChatFormatting.BOLD + "Upgrade to " +
- EnumChatFormatting.GOLD + star + EnumChatFormatting.YELLOW + EnumChatFormatting.BOLD + ": " +
- EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + upgradeCost + " " + essenceType);
}
break;
}
}
return added;
- } else if (auctionInfoErrored) {
+ } else if (auctionInfoErrored && NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) {
String message = EnumChatFormatting.RED.toString() + EnumChatFormatting.BOLD + "[NEU] API is down";
if (auctionableItems != null && !auctionableItems.isEmpty()) {
if (auctionableItems.contains(internalname)) {
@@ -351,4 +353,13 @@ public class ItemPriceInformation {
return false;
}
+
+ private static String formatPrice(String label, double price) {
+ boolean shortNumber = NotEnoughUpdates.INSTANCE.config.tooltipTweaks.shortNumberFormatPrices;
+ String number = (shortNumber && price > 1000
+ ? Utils.shortNumberFormat(price, 0)
+ : price > 5 ? format.format((int) price) : format.format(price));
+ return "§e§l" + label + "§6§l" + number + " coins";
+ }
+
}