diff options
Diffstat (limited to 'src/main')
3 files changed, 60 insertions, 46 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java index 3e25a8f1..a1bafc20 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java @@ -408,7 +408,7 @@ public class Room implements Tickable, Renderable { } int matchingRoomsSize = possibleRooms.stream().map(Triple::getRight).mapToInt(Collection::size).sum(); - if (matchingRoomsSize == 0) { + if (matchingRoomsSize == 0) synchronized (this) { // If no rooms match, reset the fields and scan again after 50 ticks. matchState = MatchState.FAILED; DungeonManager.LOGGER.warn("[Skyblocker Dungeon Secrets] No dungeon room matched after checking {} block(s) including double checking {} block(s)", checkedBlocks.size(), doubleCheckBlocks); @@ -524,10 +524,12 @@ public class Room implements Tickable, Renderable { renderable.render(context); } - if (SkyblockerConfigManager.get().locations.dungeons.secretWaypoints.enableSecretWaypoints && isMatched()) { - for (SecretWaypoint secretWaypoint : secretWaypoints.values()) { - if (secretWaypoint.shouldRender()) { - secretWaypoint.render(context); + synchronized (this) { + if (SkyblockerConfigManager.get().locations.dungeons.secretWaypoints.enableSecretWaypoints && isMatched()) { + for (SecretWaypoint secretWaypoint : secretWaypoints.values()) { + if (secretWaypoint.shouldRender()) { + secretWaypoint.render(context); + } } } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java index 3452cdec..e4e18f8b 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java @@ -14,14 +14,13 @@ import net.minecraft.client.item.TooltipContext; import net.minecraft.item.DyeableItem; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtElement; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.CompletableFuture; @@ -148,7 +147,7 @@ public class ItemTooltip { } if (TooltipInfoType.OBTAINED.isTooltipEnabled()) { - String timestamp = getTimestamp(stack); + String timestamp = ItemUtils.getTimestamp(stack); if (!timestamp.isEmpty()) { lines.add(Text.literal(String.format("%-21s", "Obtained: ")) @@ -221,43 +220,11 @@ public class ItemTooltip { } } - /** - * this method converts the "timestamp" variable into the same date format as Hypixel represents it in the museum. - * Currently, there are two types of timestamps the legacy which is built like this - * "dd/MM/yy hh:mm" ("25/04/20 16:38") and the current which is built like this - * "MM/dd/yy hh:mm aa" ("12/24/20 11:08 PM"). Since Hypixel transforms the two formats into one format without - * taking into account of their formats, we do the same. The final result looks like this - * "MMMM dd, yyyy" (December 24, 2020). - * Since the legacy format has a 25 as "month" SimpleDateFormat converts the 25 into 2 years and 1 month and makes - * "25/04/20 16:38" -> "January 04, 2022" instead of "April 25, 2020". - * This causes the museum rank to be much worse than it should be. - * - * @param stack the item under the pointer - * @return if the item have a "Timestamp" it will be shown formated on the tooltip - */ - public static String getTimestamp(ItemStack stack) { - NbtCompound ea = ItemUtils.getExtraAttributes(stack); - - if (ea != null && ea.contains("timestamp", 8)) { - SimpleDateFormat nbtFormat = new SimpleDateFormat("MM/dd/yy"); - - try { - 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 ""; - } - // TODO What in the world is this? public static String getInternalNameFromNBT(ItemStack stack, boolean internalIDOnly) { NbtCompound ea = ItemUtils.getExtraAttributes(stack); - if (ea == null || !ea.contains(ItemUtils.ID, 8)) { + if (ea == null || !ea.contains(ItemUtils.ID, NbtElement.STRING_TYPE)) { return null; } String internalName = ea.getString(ItemUtils.ID); diff --git a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java index eed91ed8..880ebe76 100644 --- a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java +++ b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java @@ -15,20 +15,27 @@ import net.minecraft.text.Texts; import net.minecraft.util.Formatting; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.Instant; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.*; import java.util.function.Predicate; import java.util.regex.Pattern; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; public class ItemUtils { + private static final Logger LOGGER = LoggerFactory.getLogger(ItemUtils.class); public static final String EXTRA_ATTRIBUTES = "ExtraAttributes"; public static final String ID = "id"; public static final String UUID = "uuid"; + private static final DateTimeFormatter OBTAINED_DATE_FORMATTER = DateTimeFormatter.ofPattern("MMMM d, yyyy").withZone(ZoneId.systemDefault()).localizedBy(Locale.ENGLISH); + private static final SimpleDateFormat OLD_OBTAINED_DATE_FORMAT = new SimpleDateFormat("MM/dd/yy"); public static final Pattern NOT_DURABILITY = Pattern.compile("[^0-9 /]"); public static final Predicate<String> FUEL_PREDICATE = line -> line.contains("Fuel: "); @@ -102,6 +109,44 @@ public class ItemUtils { return extraAttributes != null ? extraAttributes.getString(UUID) : ""; } + /** + * This method converts the "timestamp" variable into the same date format as Hypixel represents it in the museum. + * Currently, there are two types of string timestamps the legacy which is built like this + * "dd/MM/yy hh:mm" ("25/04/20 16:38") and the current which is built like this + * "MM/dd/yy hh:mm aa" ("12/24/20 11:08 PM"). Since Hypixel transforms the two formats into one format without + * taking into account of their formats, we do the same. The final result looks like this + * "MMMM dd, yyyy" (December 24, 2020). + * Since the legacy format has a 25 as "month" SimpleDateFormat converts the 25 into 2 years and 1 month and makes + * "25/04/20 16:38" -> "January 04, 2022" instead of "April 25, 2020". + * This causes the museum rank to be much worse than it should be. + * <p> + * This also handles the long timestamp format introduced in January 2024 where the timestamp is in epoch milliseconds. + * + * @param stack the item under the pointer + * @return if the item have a "Timestamp" it will be shown formated on the tooltip + */ + public static String getTimestamp(ItemStack stack) { + NbtCompound ea = getExtraAttributes(stack); + + if (ea != null && ea.contains("timestamp", NbtElement.LONG_TYPE)) { + Instant date = Instant.ofEpochMilli(ea.getLong("timestamp")); + + return OBTAINED_DATE_FORMATTER.format(date); + } + + if (ea != null && ea.contains("timestamp", NbtElement.STRING_TYPE)) { + try { + Instant date = OLD_OBTAINED_DATE_FORMAT.parse(ea.getString("timestamp")).toInstant(); + + return OBTAINED_DATE_FORMATTER.format(date); + } catch (ParseException e) { + LOGGER.warn("[Skyblocker Item Utils] Encountered an unknown exception while parsing time stamp of item {} with extra attributes {}", stack, ea, e); + } + } + + return ""; + } + public static boolean hasCustomDurability(@NotNull ItemStack stack) { NbtCompound extraAttributes = getExtraAttributes(stack); return extraAttributes != null && (extraAttributes.contains("drill_fuel") || extraAttributes.getString(ID).equals("PICKONIMBUS")); |