aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/xmrvizzy/skyblocker/skyblock
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock')
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java2
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java41
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonBlaze.java13
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Reparty.java8
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/ThreeWeirdos.java8
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java6
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/terminal/ColorTerminal.java6
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/Fetchur.java2
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/Puzzler.java4
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java126
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java53
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemStackBuilder.java11
12 files changed, 156 insertions, 124 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java
index 53a48a04..2638b0a6 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java
@@ -47,7 +47,7 @@ public class BackpackPreview extends DrawableHelper {
}
private static File getSaveDir() {
- String uuid = MinecraftClient.getInstance().player.getUuidAsString();
+ String uuid = MinecraftClient.getInstance().getSession().getUuid();
File dir = FabricLoader.getInstance().getConfigDir().resolve("skyblocker/backpack-preview/" + uuid).toFile();
dir.mkdirs();
return dir;
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java
index 84eebed3..5d3cf9c4 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FancyStatusBars.java
@@ -16,7 +16,8 @@ import java.util.regex.Pattern;
public class FancyStatusBars extends DrawableHelper {
private static final MinecraftClient client = MinecraftClient.getInstance();
private static final Identifier BARS = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/bars.png");
- private static final Pattern ACTION_BAR_STATUS = Pattern.compile("^§[6c]([0-9]+)/([0-9]+)❤(?:\\+§c[0-9]+\\S)? {3,}(?:§a([0-9]+)§a❈ Defense|(\\S+(?: \\S+)*)) {3,}(?:§b([0-9]+)/([0-9]+)✎ (?:Mana|§3([0-9]+)ʬ)?|(\\S+(?: \\S+)*))(.*)$");
+ private static final Pattern ACTION_BAR_MANA = Pattern.compile("§b-\\d+ Mana \\(.*\\) +");
+ private static final Pattern ACTION_BAR_STATUS = Pattern.compile("^§[6c](\\d+)/(\\d+)❤(\\+§c\\d+.)? +(?:§a(\\d+)§a❈ Defense|([^✎]*?))?(?: +§b(\\d+)/(\\d+)✎ +(?:Mana|§3(\\d+)ʬ))?(?: +(§[27].*))?$");
private final Resource[] resources = new Resource[]{
// Health
@@ -30,29 +31,47 @@ public class FancyStatusBars extends DrawableHelper {
};
public boolean update(String actionBar) {
- if (!SkyblockerConfig.get().general.bars.enableBars)
+ if (!SkyblockerConfig.get().general.bars.enableBars) {
+ if (SkyblockerConfig.get().messages.hideMana) {
+ Matcher mana = ACTION_BAR_MANA.matcher(actionBar);
+ if (mana.find()) {
+ assert client.player != null;
+ client.player.sendMessage(Text.of(actionBar.replace(mana.group(), "")), true);
+ return true;
+ }
+ }
return false;
+ }
+
Matcher matcher = ACTION_BAR_STATUS.matcher(actionBar);
if (!matcher.matches())
return false;
resources[0].setMax(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)));
- if (matcher.group(3) != null) {
- int def = Integer.parseInt(matcher.group(3));
+ if (matcher.group(4) != null) {
+ int def = Integer.parseInt(matcher.group(4));
resources[2].setFillLevel(def, (double) def / ((double) def + 100D));
}
- if (matcher.group(5) != null) {
- int m = Integer.parseInt(matcher.group(5));
- if (matcher.group(7) != null)
- m += Integer.parseInt(matcher.group(7));
- resources[1].setMax(m, Integer.parseInt(matcher.group(6)));
+ if (matcher.group(6) != null) {
+ int m = Integer.parseInt(matcher.group(6));
+ if (matcher.group(8) != null)
+ m += Integer.parseInt(matcher.group(8));
+ resources[1].setMax(m, Integer.parseInt(matcher.group(7)));
}
assert client.player != null;
resources[3].setFillLevel(client.player.experienceLevel, client.player.experienceProgress);
StringBuilder sb = new StringBuilder();
- appendIfNotNull(sb, matcher.group(4));
- appendIfNotNull(sb, matcher.group(8));
+ if (matcher.group(3) != null) {
+ sb.append("§c").append(matcher.group(3));
+ }
+ if (SkyblockerConfig.get().messages.hideMana) {
+ Matcher mana = ACTION_BAR_MANA.matcher(actionBar);
+ if (!mana.find())
+ appendIfNotNull(sb, matcher.group(5));
+ } else {
+ appendIfNotNull(sb, matcher.group(5));
+ }
appendIfNotNull(sb, matcher.group(9));
if (!sb.isEmpty()) {
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonBlaze.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonBlaze.java
index d4f7fec5..4554372b 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonBlaze.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonBlaze.java
@@ -7,24 +7,27 @@ import me.xmrvizzy.skyblocker.utils.RenderUtils;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.Box;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class DungeonBlaze {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DungeonBlaze.class.getName());
static Entity highestBlaze = null;
static Entity lowestBlaze = null;
static boolean renderHooked = false;
public static void update() {
- if (!Utils.isInDungeons) return;
- MinecraftClient client = MinecraftClient.getInstance();
+ ClientWorld world = MinecraftClient.getInstance().world;
+ if (world == null || !Utils.isInDungeons) return;
if(!renderHooked){
WorldRenderEvents.END.register(DungeonBlaze::blazeRenderer);
renderHooked = true;
}
- assert client.world != null;
- Iterable<Entity> entities = client.world.getEntities();
+ Iterable<Entity> entities = world.getEntities();
int highestHealth = 0;
int lowestHealth = 99999999;
@@ -70,7 +73,7 @@ public class DungeonBlaze {
}
}
}catch(Exception e) {
- System.out.println("BlazeRenderer: " + e);
+ LOGGER.warn("[Skyblocker BlazeRenderer] " + e);
}
}
} \ No newline at end of file
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Reparty.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Reparty.java
index f5fd1151..c3da7c18 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Reparty.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Reparty.java
@@ -27,9 +27,8 @@ public class Reparty extends ChatPatternListener {
repartying = false;
ClientCommandManager.DISPATCHER.register(
ClientCommandManager.literal("rp").executes(context -> {
- if (!Utils.isOnSkyblock || repartying)
+ if (!Utils.isOnSkyblock || repartying || client.player == null)
return 0;
- assert client.player != null;
repartying = true;
client.player.sendChatMessage("/p list");
return 0;
@@ -63,7 +62,10 @@ public class Reparty extends ChatPatternListener {
private void reparty() {
ClientPlayerEntity playerEntity = client.player;
- assert playerEntity != null;
+ if (playerEntity == null) {
+ repartying = false;
+ return;
+ }
sendCommand(playerEntity, "/p disband", 1);
StringBuilder sb = new StringBuilder();
int invites = (players.length - 1) / 5 + 1;
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/ThreeWeirdos.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/ThreeWeirdos.java
index 8f1f3711..da964f07 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/ThreeWeirdos.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/ThreeWeirdos.java
@@ -23,17 +23,13 @@ public class ThreeWeirdos extends ChatPatternListener {
@Override
public boolean onMatch(Text message, Matcher matcher) {
MinecraftClient client = MinecraftClient.getInstance();
- assert client.world != null;
- assert client.player != null;
+ if (client.player == null || client.world == null) return false;
client.world.getEntitiesByClass(
ArmorStandEntity.class,
client.player.getBoundingBox().expand(3),
entity -> {
Text customName = entity.getCustomName();
- if (customName != null && customName.getString().equals(matcher.group(1))) {
- return true;
- }
- return false;
+ return customName != null && customName.getString().equals(matcher.group(1));
}
).forEach(
entity -> entity.setCustomName(Text.of(Formatting.GREEN + matcher.group(1)))
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java
index 51ff1c6a..673797d4 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java
@@ -31,9 +31,9 @@ public class Trivia extends ChatPatternListener {
if (riddle != null) {
if (!solutions.contains(riddle)) {
ClientPlayerEntity player = MinecraftClient.getInstance().player;
- assert player != null;
- MinecraftClient.getInstance().player.sendMessage(new LiteralText(" " + Formatting.GOLD + matcher.group(2) + Formatting.RED + " " + riddle), false);
- return true;
+ if (player != null)
+ MinecraftClient.getInstance().player.sendMessage(new LiteralText(" " + Formatting.GOLD + matcher.group(2) + Formatting.RED + " " + riddle), false);
+ return player != null;
}
} else
updateSolutions(matcher.group(0));
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/terminal/ColorTerminal.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/terminal/ColorTerminal.java
index 4d40ea83..57c40654 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/terminal/ColorTerminal.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/terminal/ColorTerminal.java
@@ -9,14 +9,14 @@ import net.minecraft.item.Items;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.*;
public class ColorTerminal extends ContainerSolver {
- private static final Logger LOGGER = LogManager.getLogger(ColorTerminal.class.getName());
+ private static final Logger LOGGER = LoggerFactory.getLogger(ColorTerminal.class.getName());
private static final Map<String, DyeColor> colorFromName;
private DyeColor targetColor;
private static final Map<Item, DyeColor> itemColor;
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/Fetchur.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/Fetchur.java
index ce1dde11..ccd47c5a 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/Fetchur.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/Fetchur.java
@@ -26,7 +26,7 @@ public class Fetchur extends ChatPatternListener {
@Override
public boolean onMatch(Text message, Matcher matcher) {
MinecraftClient client = MinecraftClient.getInstance();
- assert client.player != null;
+ if (client.player == null) return false;
String riddle = matcher.group(1);
String answer = answers.getOrDefault(riddle, riddle);
client.player.sendMessage(Text.of("§e[NPC] Fetchur§f: " + answer), false);
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/Puzzler.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/Puzzler.java
index f61e007e..06395898 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/Puzzler.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/Puzzler.java
@@ -32,8 +32,8 @@ public class Puzzler extends ChatPatternListener {
else if (c == '▶') x--;
}
ClientWorld world = MinecraftClient.getInstance().world;
- assert world != null;
- world.setBlockStateWithoutNeighborUpdates(new BlockPos(x, 195, z), Blocks.CRIMSON_PLANKS.getDefaultState());
+ if (world != null)
+ world.setBlockStateWithoutNeighborUpdates(new BlockPos(x, 195, z), Blocks.CRIMSON_PLANKS.getDefaultState());
return false;
}
} \ No newline at end of file
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 1d70c5e0..3a5980f0 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java
@@ -4,6 +4,7 @@ import com.google.gson.Gson;
import com.google.gson.JsonObject;
import me.xmrvizzy.skyblocker.SkyblockerMod;
import me.xmrvizzy.skyblocker.config.SkyblockerConfig;
+import me.xmrvizzy.skyblocker.utils.Utils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.item.ItemStack;
@@ -13,7 +14,8 @@ import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import org.apache.commons.lang3.StringUtils;
-import org.apache.logging.log4j.LogManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
@@ -27,6 +29,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.zip.GZIPInputStream;
public class PriceInfoTooltip {
+ private static final Logger LOGGER = LoggerFactory.getLogger(PriceInfoTooltip.class.getName());
private static final SkyblockerMod skyblocker = SkyblockerMod.getInstance();
private static final MinecraftClient client = MinecraftClient.getInstance();
private static JsonObject npcPricesJson;
@@ -39,17 +42,16 @@ public class PriceInfoTooltip {
private final static Gson gson = new Gson();
public static void onInjectTooltip(ItemStack stack, TooltipContext context, List<Text> lines) {
- int count = stack.getCount();
+ if (!Utils.isOnSkyblock || client.player == null) return;
+
String name = getInternalNameFromNBT(stack);
- String timestamp = getTimestamp(stack);
- List<String> listString = lines.stream()
- .map(Text::getString).toList();
+ if (name == null) return;
- if (client.player == null) {
- throw new RuntimeException("[Skyblocker] client.player cannot be null!");
- }
+ 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 && !listString.contains("NPC Price")) {
+ if (SkyblockerConfig.get().general.itemTooltip.enableNPCPrice) {
if (npcPricesJson == null) {
if (!nullMsgSend) {
client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false);
@@ -62,7 +64,31 @@ public class PriceInfoTooltip {
}
}
- if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN && !listString.contains("Lowest BIN Price")) {
+ boolean bazaarExist = false;
+ if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice && !bazaarOpened) {
+ if (bazaarPricesJson == null) {
+ if (!nullMsgSend) {
+ client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false);
+ nullMsgSend = true;
+ }
+ } else if (bazaarPricesJson.has(name)) {
+ JsonObject getItem = bazaarPricesJson.getAsJsonObject(name);
+ lines.add(new LiteralText(String.format("%-18s", "Bazaar buy Price:"))
+ .formatted(Formatting.GOLD)
+ .append(getItem.get("buyPrice").isJsonNull()
+ ? new LiteralText("No data").formatted(Formatting.RED)
+ : getCoinsMessage(getItem.get("buyPrice").getAsDouble(), count)));
+ lines.add(new LiteralText(String.format("%-19s", "Bazaar sell Price:"))
+ .formatted(Formatting.GOLD)
+ .append(getItem.get("sellPrice").isJsonNull()
+ ? new LiteralText("No data").formatted(Formatting.RED)
+ : getCoinsMessage(getItem.get("sellPrice").getAsDouble(), count)));
+ bazaarExist = true;
+ }
+ }
+
+ // 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(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false);
@@ -75,7 +101,7 @@ public class PriceInfoTooltip {
}
}
- if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN && !listString.contains("Avg. BIN Price")) {
+ if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN) {
if (threeDayAvgPricesJson == null || oneDayAvgPricesJson == null) {
if (!nullMsgSend) {
client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false);
@@ -109,49 +135,23 @@ public class PriceInfoTooltip {
// "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)) {
- if (oneDayAvgPricesJson.get(name) != null) {
- lines.add(new LiteralText(String.format("%-19s", "1 Day Avg. Price:"))
- .formatted(Formatting.GOLD)
- .append(getCoinsMessage(oneDayAvgPricesJson.get(name).getAsDouble(), count)));
- } else {
- lines.add(new LiteralText(String.format("%-19s", "1 Day Avg. Price:"))
- .formatted(Formatting.GOLD)
- .append(new LiteralText("No data").formatted(Formatting.RED)));
- }
+ lines.add(new LiteralText(String.format("%-19s", "1 Day Avg. Price:"))
+ .formatted(Formatting.GOLD)
+ .append(oneDayAvgPricesJson.get(name) == null
+ ? new LiteralText("No data").formatted(Formatting.RED)
+ : getCoinsMessage(oneDayAvgPricesJson.get(name).getAsDouble(), count)));
}
if (!name.isEmpty() && (type == SkyblockerConfig.Average.THREE_DAY || type == SkyblockerConfig.Average.BOTH)) {
- if (threeDayAvgPricesJson.get(name) != null) {
- lines.add(new LiteralText(String.format("%-19s", "3 Day Avg. Price:"))
- .formatted(Formatting.GOLD)
- .append(getCoinsMessage(threeDayAvgPricesJson.get(name).getAsDouble(), count)));
- } else {
- lines.add(new LiteralText(String.format("%-19s", "3 Day Avg. Price:"))
- .formatted(Formatting.GOLD)
- .append(new LiteralText("No data").formatted(Formatting.RED)));
- }
- }
- }
- }
-
- if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice
- && (!listString.contains("Bazaar buy Price") || !listString.contains("Bazaar sell Price"))) {
- if (bazaarPricesJson == null) {
- if (!nullMsgSend) {
- client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false);
- nullMsgSend = true;
+ lines.add(new LiteralText(String.format("%-19s", "3 Day Avg. Price:"))
+ .formatted(Formatting.GOLD)
+ .append(threeDayAvgPricesJson.get(name) == null
+ ? new LiteralText("No data").formatted(Formatting.RED)
+ : getCoinsMessage(threeDayAvgPricesJson.get(name).getAsDouble(), count)));
}
- } else if (bazaarPricesJson.has(name)) {
- JsonObject getItem = bazaarPricesJson.getAsJsonObject(name);
- lines.add(new LiteralText(String.format("%-18s", "Bazaar buy Price:"))
- .formatted(Formatting.GOLD)
- .append(getCoinsMessage(getItem.get("buyPrice").getAsDouble(), count)));
- lines.add(new LiteralText(String.format("%-19s", "Bazaar sell Price:"))
- .formatted(Formatting.GOLD)
- .append(getCoinsMessage(getItem.get("sellPrice").getAsDouble(), count)));
}
}
- if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate && !listString.contains("Museum")) {
+ if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate && !bazaarOpened) {
if (isMuseumJson == null) {
if (!nullMsgSend) {
client.player.sendMessage(new TranslatableText("skyblocker.itemTooltip.nullMessage"), false);
@@ -164,15 +164,14 @@ public class PriceInfoTooltip {
case "Armor" -> "%-19s";
default -> "%-20s";
};
-
lines.add(new LiteralText(String.format(format, "Museum: (" + itemCategory + ")"))
.formatted(Formatting.LIGHT_PURPLE)
.append(new LiteralText(timestamp != null ? timestamp : "").formatted(Formatting.RED)));
+ } else if (timestamp != null) {
+ lines.add(new LiteralText(String.format("%-21s", "Obtained: "))
+ .formatted(Formatting.LIGHT_PURPLE)
+ .append(new LiteralText(timestamp).formatted(Formatting.RED)));
}
- } else if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate && !listString.contains("Obtained") && timestamp != null) {
- lines.add(new LiteralText(String.format("%-22s", "Obtained: "))
- .formatted(Formatting.LIGHT_PURPLE)
- .append(new LiteralText(timestamp).formatted(Formatting.RED)));
}
}
@@ -252,9 +251,16 @@ public class PriceInfoTooltip {
}
}
- public static int minute = 0;
+ // If these options is true beforehand, the client will get first data of these options while loading.
+ // After then, it will only fetch the data if it is on Skyblock.
+ public static int minute = -1;
public static void init() {
skyblocker.scheduler.scheduleCyclic(() -> {
+ if (!Utils.isOnSkyblock && 0 < minute++) {
+ nullMsgSend = false;
+ return;
+ }
+
List<CompletableFuture<Void>> futureList = new ArrayList<>();
if ((SkyblockerConfig.get().general.itemTooltip.enableAvgBIN) && (oneDayAvgPricesJson == null || threeDayAvgPricesJson == null || minute % 5 == 0)) {
SkyblockerConfig.Average type = SkyblockerConfig.get().general.itemTooltip.avg;
@@ -301,7 +307,7 @@ public class PriceInfoTooltip {
}
}
} catch (IOException e) {
- LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download average BIN prices!", e);
+ LOGGER.warn("[Skyblocker] Failed to download average BIN prices!", e);
}
switch (type) {
case ONE_DAY -> oneDayAvgPricesJson = result;
@@ -316,7 +322,7 @@ public class PriceInfoTooltip {
InputStreamReader reader = new InputStreamReader(apiAddr.openStream());
result = new Gson().fromJson(reader, JsonObject.class);
} catch (IOException e) {
- LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download bazaar prices!", e);
+ LOGGER.warn("[Skyblocker] Failed to download bazaar prices!", e);
}
bazaarPricesJson = result;
}
@@ -324,11 +330,11 @@ public class PriceInfoTooltip {
private static void downloadLowestPrices() {
JsonObject result = null;
try {
- URL apiAddr = new URL("https://sbe-stole-skytils.design/api/auctions/lowestbins");
+ URL apiAddr = new URL("https://skytils.gg/api/auctions/lowestbins");
InputStreamReader reader = new InputStreamReader(apiAddr.openStream());
result = new Gson().fromJson(reader, JsonObject.class);
} catch (IOException e) {
- LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download lowest BIN prices!", e);
+ LOGGER.warn("[Skyblocker] Failed to download lowest BIN prices!", e);
}
lowestPricesJson = result;
}
@@ -340,7 +346,7 @@ public class PriceInfoTooltip {
InputStreamReader reader = new InputStreamReader(apiAddr.openStream());
result = new Gson().fromJson(reader, JsonObject.class);
} catch (IOException e) {
- LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download NPC prices!", e);
+ LOGGER.warn("[Skyblocker] Failed to download NPC prices!", e);
}
npcPricesJson = result;
}
@@ -352,7 +358,7 @@ public class PriceInfoTooltip {
InputStreamReader reader = new InputStreamReader(apiAddr.openStream());
result = new Gson().fromJson(reader, JsonObject.class);
} catch (IOException e) {
- LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download museum items!", e);
+ LOGGER.warn("[Skyblocker] Failed to download museum items!", e);
}
isMuseumJson = result;
}
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 c664bb9e..17e9aebc 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java
@@ -2,22 +2,24 @@ package me.xmrvizzy.skyblocker.skyblock.itemlist;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
+
+import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import org.eclipse.jgit.api.Git;
-import org.eclipse.jgit.api.errors.GitAPIException;
+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.Paths;
+import java.nio.file.Path;
import java.util.*;
public class ItemRegistry {
- protected static final String REMOTE_ITEM_REPO_DIR = "https://github.com/KonaeAkira/NotEnoughUpdates-REPO.git";
- protected static final String LOCAL_ITEM_REPO_DIR = "./config/skyblocker/items-repo/";
+ protected static final String REMOTE_ITEM_REPO = "https://github.com/KonaeAkira/NotEnoughUpdates-REPO.git";
+ protected static final Path LOCAL_ITEM_REPO_DIR = FabricLoader.getInstance().getConfigDir().resolve("skyblocker/item-repo");
- private static final String ITEM_LIST_DIR = LOCAL_ITEM_REPO_DIR + "items/";
+ private static final Path ITEM_LIST_DIR = LOCAL_ITEM_REPO_DIR.resolve("items");
protected static List<ItemStack> items = new ArrayList<>();
protected static Map<String, ItemStack> itemsMap = new HashMap<>();
@@ -31,21 +33,21 @@ public class ItemRegistry {
}
private static void updateItemRepo() {
- if (!Files.isDirectory(Paths.get(LOCAL_ITEM_REPO_DIR))) {
+ if (!Files.isDirectory(LOCAL_ITEM_REPO_DIR)) {
try {
Git.cloneRepository()
- .setURI(REMOTE_ITEM_REPO_DIR)
- .setDirectory(new File(LOCAL_ITEM_REPO_DIR))
+ .setURI(REMOTE_ITEM_REPO)
+ .setDirectory(LOCAL_ITEM_REPO_DIR.toFile())
.setBranchesToClone(List.of("refs/heads/master"))
.setBranch("refs/heads/master")
.call();
- } catch (GitAPIException e) {
+ } catch (Exception e) {
e.printStackTrace();
}
} else {
try {
- Git.open(new File(LOCAL_ITEM_REPO_DIR)).pull().call();
- } catch (GitAPIException | IOException e) {
+ Git.open(LOCAL_ITEM_REPO_DIR.toFile()).pull().call();
+ } catch (Exception e) {
e.printStackTrace();
}
}
@@ -54,16 +56,15 @@ public class ItemRegistry {
private static void importItemFiles() {
List<JsonObject> jsonObjs = new ArrayList<>();
- File dir = new File(ITEM_LIST_DIR);
+ File dir = ITEM_LIST_DIR.toFile();
File[] files = dir.listFiles();
assert files != null;
for (File file : files) {
- String path = ITEM_LIST_DIR + "/" + file.getName();
+ Path path = ITEM_LIST_DIR.resolve(file.getName());
try {
- String fileContent = Files.readString(Paths.get(path));
+ String fileContent = Files.readString(path);
jsonObjs.add(JsonParser.parseString(fileContent).getAsJsonObject());
- } catch (IOException e) {
- System.err.println("Couldn't import " + path);
+ } catch (Exception e) {
e.printStackTrace();
}
}
@@ -110,6 +111,7 @@ public class ItemRegistry {
}
class Recipe {
+ private static final Logger LOGGER = LoggerFactory.getLogger(Recipe.class);
String text = "";
List<ItemStack> grid = new ArrayList<>(9);
ItemStack result;
@@ -131,12 +133,17 @@ class Recipe {
}
private static ItemStack getItemStack(String internalName) {
- if (internalName.length() > 0) {
- int count = Integer.parseInt(internalName.split(":")[1]);
- internalName = internalName.split(":")[0];
- ItemStack itemStack = ItemRegistry.itemsMap.get(internalName).copy();
- itemStack.setCount(count);
- return itemStack;
+ try {
+ if (internalName.length() > 0) {
+ int count = Integer.parseInt(internalName.split(":")[1]);
+ internalName = internalName.split(":")[0];
+ ItemStack itemStack = ItemRegistry.itemsMap.get(internalName).copy();
+ itemStack.setCount(count);
+ return itemStack;
+ }
+ }
+ catch(Exception e) {
+ LOGGER.error("[Skyblocker-Recipe] "+internalName,e);
}
return Items.AIR.getDefaultStack();
}
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemStackBuilder.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemStackBuilder.java
index 6781f99c..f21c7ccb 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemStackBuilder.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemStackBuilder.java
@@ -9,21 +9,20 @@ import net.minecraft.nbt.*;
import net.minecraft.text.Text;
import net.minecraft.util.Pair;
-import java.io.IOException;
import java.nio.file.Files;
-import java.nio.file.Paths;
+import java.nio.file.Path;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ItemStackBuilder {
- private final static String PETNUMS_PATH = ItemRegistry.LOCAL_ITEM_REPO_DIR + "constants/petnums.json";
+ private final static Path PETNUMS_PATH = ItemRegistry.LOCAL_ITEM_REPO_DIR.resolve("constants/petnums.json");
private static JsonObject petNums;
public static void init() {
try {
- petNums = JsonParser.parseString(Files.readString(Paths.get(PETNUMS_PATH))).getAsJsonObject();
- } catch (IOException e) {
+ petNums = JsonParser.parseString(Files.readString(PETNUMS_PATH)).getAsJsonObject();
+ } catch (Exception e) {
e.printStackTrace();
}
}
@@ -130,7 +129,7 @@ public class ItemStackBuilder {
for (int i = 0; i < otherNumsMin.size(); ++i) {
String left = "\\{" + i + "\\}";
String right = otherNumsMin.get(i).getAsString() + " ➡ " + otherNumsMax.get(i).getAsString();
- list.add(new Pair(left, right));
+ list.add(new Pair<>(left, right));
}
return list;