aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFix3dll <serhanduzce@gmail.com>2022-02-23 18:23:15 +0300
committerFix3dll <serhanduzce@gmail.com>2022-02-23 18:23:15 +0300
commit57fd50d7d657e1ed0c7ef95545bfc4e7e4302607 (patch)
tree47e940967f1a6ebadfca22ba9857a932c6043633 /src
parentaa4789fab32d7402a03d5f5d78cb577fa4012267 (diff)
downloadSkyblocker-57fd50d7d657e1ed0c7ef95545bfc4e7e4302607.tar.gz
Skyblocker-57fd50d7d657e1ed0c7ef95545bfc4e7e4302607.tar.bz2
Skyblocker-57fd50d7d657e1ed0c7ef95545bfc4e7e4302607.zip
new avg type
Diffstat (limited to 'src')
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java10
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java73
-rw-r--r--src/main/resources/assets/skyblocker/lang/en_us.json2
3 files changed, 74 insertions, 11 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java
index 12aeb001..f94a422d 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java
@@ -72,9 +72,18 @@ public class SkyblockerConfig implements ConfigData {
public boolean enableQuicknav = true;
}
+ public enum Average {
+ ONE_DAY,
+ THREE_DAY,
+ BOTH
+ }
+
public static class ItemTooltip {
public boolean enableNPCPrice = true;
public boolean enableAvgBIN = true;
+ @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
+ @ConfigEntry.Gui.Tooltip()
+ public Average avg = Average.THREE_DAY;
public boolean enableLowestBIN = true;
public boolean enableBazaarPrice = true;
public boolean enableMuseumDate = true;
@@ -122,6 +131,7 @@ public class SkyblockerConfig implements ConfigData {
public boolean hideTeleportPad = false;
public boolean hideCombo = false;
}
+
public enum Info {
PURSE,
BITS,
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 a9593f96..df3ef3b3 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java
@@ -25,11 +25,14 @@ import java.util.Locale;
import java.util.concurrent.CompletableFuture;
import java.util.zip.GZIPInputStream;
+import static me.xmrvizzy.skyblocker.config.SkyblockerConfig.Average.BOTH;
+
public class PriceInfoTooltip {
private static final SkyblockerMod skyblocker = SkyblockerMod.getInstance();
private static JsonObject npcPricesJson;
private static JsonObject bazaarPricesJson;
- private static JsonObject avgPricesJson;
+ private static JsonObject oneDayAvgPricesJson;
+ private static JsonObject threeDayAvgPricesJson;
private static JsonObject lowestPricesJson;
private static JsonObject isMuseumJson;
private static boolean nullMsgSend = false;
@@ -51,7 +54,7 @@ public class PriceInfoTooltip {
}
}
- if ((!listString.contains("Avg. BIN Price") && avgPricesJson.has(name))
+ if ((!listString.contains("Avg. BIN Price") && (threeDayAvgPricesJson.has(name) || oneDayAvgPricesJson.has(name)))
|| (!listString.contains("Lowest BIN Price") && lowestPricesJson.has(name))) {
if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN && lowestPricesJson.has(name)) {
@@ -81,10 +84,24 @@ public class PriceInfoTooltip {
name = name.replace(":", "-");
}
- if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN && !name.isEmpty() && avgPricesJson.has(name)) {
- lines.add(new LiteralText(String.format("%-21s", "Avg. BIN Price:"))
- .formatted(Formatting.GOLD)
- .append(getCoinsMessage(avgPricesJson.get(name).getAsDouble(), count)));
+ if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN && !name.isEmpty()
+ && (threeDayAvgPricesJson.has(name) || oneDayAvgPricesJson.has(name))) {
+ switch (SkyblockerConfig.get().general.itemTooltip.avg) {
+ case ONE_DAY -> lines.add(new LiteralText(String.format("%-19s", "1 Day Avg. Price:"))
+ .formatted(Formatting.GOLD)
+ .append(getCoinsMessage(oneDayAvgPricesJson.get(name).getAsDouble(), count)));
+ case THREE_DAY -> lines.add(new LiteralText(String.format("%-19s", "3 Day Avg. Price:"))
+ .formatted(Formatting.GOLD)
+ .append(getCoinsMessage(threeDayAvgPricesJson.get(name).getAsDouble(), count)));
+ case BOTH -> {
+ lines.add(new LiteralText(String.format("%-19s", "1 Day Avg. Price:"))
+ .formatted(Formatting.GOLD)
+ .append(getCoinsMessage(oneDayAvgPricesJson.get(name).getAsDouble(), count)));
+ lines.add(new LiteralText(String.format("%-19s", "3 Day Avg. Price:"))
+ .formatted(Formatting.GOLD)
+ .append(getCoinsMessage(threeDayAvgPricesJson.get(name).getAsDouble(), count)));
+ }
+ }
}
} else if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice
&& !listString.contains("Bazaar buy Price") || !listString.contains("Bazaar sell Price")) {
@@ -119,7 +136,8 @@ public class PriceInfoTooltip {
.append(new LiteralText(timestamp).formatted(Formatting.RED)));
}
} catch (NullPointerException ex) {
- if ((npcPricesJson == null || bazaarPricesJson == null || avgPricesJson == null || lowestPricesJson == null || isMuseumJson == null)
+ if ((npcPricesJson == null || bazaarPricesJson == null || oneDayAvgPricesJson == null
+ || threeDayAvgPricesJson == null || lowestPricesJson == null || isMuseumJson == null)
&& !nullMsgSend) {
MinecraftClient.getInstance().player.sendMessage(new TranslatableText("skyblocker.itemTooltip.NullMessage"), false);
nullMsgSend = true;
@@ -214,8 +232,22 @@ public class PriceInfoTooltip {
public static void init() {
skyblocker.scheduler.scheduleCyclic(() -> {
{
- if ((SkyblockerConfig.get().general.itemTooltip.enableAvgBIN || minute == 0) && (avgPricesJson == null || minute % 5 == 0)) {
- CompletableFuture.runAsync(PriceInfoTooltip::downloadAvgPrices);
+ if ((SkyblockerConfig.get().general.itemTooltip.enableAvgBIN || minute == 0)
+ && (oneDayAvgPricesJson == null || threeDayAvgPricesJson == null || minute % 5 == 0)) {
+ SkyblockerConfig.Average avg;
+ if (oneDayAvgPricesJson == null || threeDayAvgPricesJson == null || minute == 0) {
+ avg = BOTH;
+ } else {
+ avg = SkyblockerConfig.get().general.itemTooltip.avg;
+ }
+ switch (avg) {
+ case ONE_DAY -> CompletableFuture.runAsync(PriceInfoTooltip::download1DayAvgPrices);
+ case THREE_DAY -> CompletableFuture.runAsync(PriceInfoTooltip::download3DayAvgPrices);
+ case BOTH -> {
+ CompletableFuture.runAsync(PriceInfoTooltip::download1DayAvgPrices);
+ CompletableFuture.runAsync(PriceInfoTooltip::download3DayAvgPrices);
+ }
+ }
}
if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN || minute == 0) {
CompletableFuture.runAsync(PriceInfoTooltip::downloadLowestPrices);
@@ -234,8 +266,27 @@ public class PriceInfoTooltip {
}, 1200);
}
- private static void downloadAvgPrices() {
+ private static void download1DayAvgPrices() {
+ JsonObject result = null;
+ String avgDay = null;
+ try {
+ URL apiAddr = new URL("https://moulberry.codes/auction_averages_lbin/1day.json.gz");
+ try (InputStream src = apiAddr.openStream()) {
+ try (GZIPInputStream gzipOutput = new GZIPInputStream(src)) {
+ try (InputStreamReader reader = new InputStreamReader(gzipOutput)) {
+ result = new Gson().fromJson(reader, JsonObject.class);
+ }
+ }
+ }
+ } catch (IOException e) {
+ LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download average BIN prices!", e);
+ }
+ oneDayAvgPricesJson = result;
+ }
+
+ private static void download3DayAvgPrices() {
JsonObject result = null;
+ String avgDay = null;
try {
URL apiAddr = new URL("https://moulberry.codes/auction_averages_lbin/3day.json.gz");
try (InputStream src = apiAddr.openStream()) {
@@ -248,7 +299,7 @@ public class PriceInfoTooltip {
} catch (IOException e) {
LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download average BIN prices!", e);
}
- avgPricesJson = result;
+ threeDayAvgPricesJson = result;
}
private static void downloadBazaarPrices() {
diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json
index fa2f6b5c..17357c49 100644
--- a/src/main/resources/assets/skyblocker/lang/en_us.json
+++ b/src/main/resources/assets/skyblocker/lang/en_us.json
@@ -13,6 +13,8 @@
"text.autoconfig.skyblocker.option.general.itemTooltip": "Item Tooltip",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableNPCPrice": "Enable NPC Price",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableAvgBIN": "Enable Avg. BIN Price",
+ "text.autoconfig.skyblocker.option.general.itemTooltip.avg": "Average Type",
+ "text.autoconfig.skyblocker.option.general.itemTooltip.avg.@Tooltip": "You can choose how many days of average price to be",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableLowestBIN": "Enable Lowest BIN Price",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableBazaarPrice": "Enable Bazaar buy/sell Price",
"text.autoconfig.skyblocker.option.general.itemTooltip.enableMuseumDate": "Enable Museum & Date",