feat: add creation timestamp in lore
This commit is contained in:
@@ -16,12 +16,14 @@ import moe.nea.firmament.util.SBData
|
||||
import moe.nea.firmament.util.aqua
|
||||
import moe.nea.firmament.util.grey
|
||||
import moe.nea.firmament.util.mc.displayNameAccordingToNbt
|
||||
import moe.nea.firmament.util.timestamp
|
||||
import moe.nea.firmament.util.tr
|
||||
import moe.nea.firmament.util.unformattedString
|
||||
|
||||
object TimerInLore {
|
||||
object TConfig : ManagedConfig("lore-timers", Category.INVENTORY) {
|
||||
val showTimers by toggle("show") { true }
|
||||
val showCreationTimestamp by toggle("show-creation") { true }
|
||||
val timerFormat by choice("format") { TimerFormat.SOCIALIST }
|
||||
}
|
||||
|
||||
@@ -90,6 +92,14 @@ object TimerInLore {
|
||||
val regex =
|
||||
"(?i)(?:(?<years>[0-9]+) ?(y|years?) )?(?:(?<days>[0-9]+) ?(d|days?))? ?(?:(?<hours>[0-9]+) ?(h|hours?))? ?(?:(?<minutes>[0-9]+) ?(m|minutes?))? ?(?:(?<seconds>[0-9]+) ?(s|seconds?))?\\b".toRegex()
|
||||
|
||||
@Subscribe
|
||||
fun creationInLore(event: ItemTooltipEvent) {
|
||||
if (!TConfig.showCreationTimestamp) return
|
||||
val timestamp = event.stack.timestamp ?: return
|
||||
val formattedTimestamp = TConfig.timerFormat.formatter.format(ZonedDateTime.ofInstant(timestamp, ZoneId.systemDefault()))
|
||||
event.lines.add(tr("firmament.lore.creationtimestamp", "Created at: $formattedTimestamp").grey())
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
fun modifyLore(event: ItemTooltipEvent) {
|
||||
if (!TConfig.showTimers) return
|
||||
@@ -111,9 +121,13 @@ object TimerInLore {
|
||||
var baseLine = ZonedDateTime.now(SBData.hypixelTimeZone)
|
||||
if (countdownType.isRelative) {
|
||||
if (lastTimer == null) {
|
||||
event.lines.add(i + 1,
|
||||
tr("firmament.loretimer.missingrelative",
|
||||
"Found a relative countdown with no baseline (Firmament)").grey())
|
||||
event.lines.add(
|
||||
i + 1,
|
||||
tr(
|
||||
"firmament.loretimer.missingrelative",
|
||||
"Found a relative countdown with no baseline (Firmament)"
|
||||
).grey()
|
||||
)
|
||||
continue
|
||||
}
|
||||
baseLine = lastTimer
|
||||
@@ -123,10 +137,11 @@ object TimerInLore {
|
||||
lastTimer = timer
|
||||
val localTimer = timer.withZoneSameInstant(ZoneId.systemDefault())
|
||||
// TODO: install approximate time stabilization algorithm
|
||||
event.lines.add(i + 1,
|
||||
Text.literal("${countdownType.label}: ")
|
||||
.grey()
|
||||
.append(Text.literal(TConfig.timerFormat.formatter.format(localTimer)).aqua())
|
||||
event.lines.add(
|
||||
i + 1,
|
||||
Text.literal("${countdownType.label}: ")
|
||||
.grey()
|
||||
.append(Text.literal(TConfig.timerFormat.formatter.format(localTimer)).aqua())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,11 @@ import com.mojang.serialization.Codec
|
||||
import io.github.moulberry.repo.data.NEUIngredient
|
||||
import io.github.moulberry.repo.data.NEUItem
|
||||
import io.github.moulberry.repo.data.Rarity
|
||||
import java.time.Instant
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatterBuilder
|
||||
import java.time.format.SignStyle
|
||||
import java.time.temporal.ChronoField
|
||||
import java.util.Optional
|
||||
import java.util.UUID
|
||||
import kotlinx.serialization.Serializable
|
||||
@@ -38,13 +43,14 @@ import moe.nea.firmament.util.json.DashlessUUIDSerializer
|
||||
@Serializable
|
||||
value class SkyblockId(val neuItem: String) : Comparable<SkyblockId> {
|
||||
val identifier
|
||||
get() = Identifier.of("skyblockitem",
|
||||
neuItem.lowercase().replace(";", "__")
|
||||
.replace(":", "___")
|
||||
.replace(illlegalPathRegex) {
|
||||
it.value.toCharArray()
|
||||
.joinToString("") { "__" + it.code.toString(16).padStart(4, '0') }
|
||||
})
|
||||
get() = Identifier.of(
|
||||
"skyblockitem",
|
||||
neuItem.lowercase().replace(";", "__")
|
||||
.replace(":", "___")
|
||||
.replace(illlegalPathRegex) {
|
||||
it.value.toCharArray()
|
||||
.joinToString("") { "__" + it.code.toString(16).padStart(4, '0') }
|
||||
})
|
||||
|
||||
override fun toString(): String {
|
||||
return neuItem
|
||||
@@ -137,6 +143,30 @@ fun ItemStack.modifyExtraAttributes(block: (NbtCompound) -> Unit) {
|
||||
val ItemStack.skyblockUUIDString: String?
|
||||
get() = extraAttributes.getString("uuid").getOrNull()?.takeIf { it.isNotBlank() }
|
||||
|
||||
private val timestampFormat = //"10/11/21 3:39 PM"
|
||||
DateTimeFormatterBuilder().apply {
|
||||
appendValue(ChronoField.MONTH_OF_YEAR, 2)
|
||||
appendLiteral("/")
|
||||
appendValue(ChronoField.DAY_OF_MONTH, 2)
|
||||
appendLiteral("/")
|
||||
appendValueReduced(ChronoField.YEAR, 2, 2, 1950)
|
||||
appendLiteral(" ")
|
||||
appendValue(ChronoField.HOUR_OF_AMPM, 1, 2, SignStyle.NEVER)
|
||||
appendLiteral(":")
|
||||
appendValue(ChronoField.MINUTE_OF_HOUR, 2)
|
||||
appendLiteral(" ")
|
||||
appendText(ChronoField.AMPM_OF_DAY)
|
||||
}.toFormatter()
|
||||
val ItemStack.timestamp
|
||||
get() =
|
||||
extraAttributes.getLong("timestamp").getOrNull()?.let { Instant.ofEpochMilli(it) }
|
||||
?: extraAttributes.getString("timestamp").getOrNull()?.let {
|
||||
ErrorUtil.catch("Could not parse timestamp $it") {
|
||||
LocalDateTime.from(timestampFormat.parse(it)).atZone(SBData.hypixelTimeZone)
|
||||
.toInstant()
|
||||
}.orNull()
|
||||
}
|
||||
|
||||
val ItemStack.skyblockUUID: UUID?
|
||||
get() = skyblockUUIDString?.let { UUID.fromString(it) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user