aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
authorErymanthus[#5074] | (u/)RayDeeUx <51521765+RayDeeUx@users.noreply.github.com>2023-12-29 08:36:30 -0500
committerGitHub <noreply@github.com>2023-12-29 14:36:30 +0100
commite576ed7aab14da5e4bf1a68eee3abdcb6c9a66a8 (patch)
tree836d34dabd7b7b295fb255104de11a6e033963ca /src/main/kotlin
parent72f31f374f22736356d639775e48a2567babb288 (diff)
downloadNotEnoughUpdates-e576ed7aab14da5e4bf1a68eee3abdcb6c9a66a8.tar.gz
NotEnoughUpdates-e576ed7aab14da5e4bf1a68eee3abdcb6c9a66a8.tar.bz2
NotEnoughUpdates-e576ed7aab14da5e4bf1a68eee3abdcb6c9a66a8.zip
Fixes: Countdown Calculator (#985)
* smaller change: add NEU prefix to /warp dessert
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/CountdownCalculator.kt29
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/WarpDessert.kt2
2 files changed, 18 insertions, 13 deletions
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/CountdownCalculator.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/CountdownCalculator.kt
index 068e735b..4431d3bd 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/CountdownCalculator.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/CountdownCalculator.kt
@@ -32,9 +32,9 @@ import java.time.format.DateTimeFormatter
— Erymanthus / RayDeeUx (code base, math, timestamp wrangling, adaptation into overall NEU codebase)
— nea89 (enum, regex wrangling, ItemTooltipEvent integration, cleanup)
- Intended to detect countdowns within item tooltips, converting the time remaining into
- units of seconds, and then adding that result to the user's current system time
- in Unix epoch form converted into a human-readable timestamp, timezones included.
+ Intended to detect countdowns within item tooltips and then adding that result
+ to the user's current system time in Unix epoch form converted into a
+ human-readable timestamp relative to the system timezone.
Formerly a feature from SkyBlockCatia, then later attempted to be ported into Skytils.
Now has a comfy home in the NotEnoughUpdates codebase.
@@ -62,6 +62,7 @@ class CountdownCalculator {
TIMELEFT("Time left:", "Ends at"),
EVENTTIMELEFT("Event lasts for", "Ends at", isRelative = true),
SHENSUCKS("Auction ends in:", "Auction ends at"),
+ TAMINGSIXTYWASAMISTAKE("Ends:", "Finishes at"), // There would be a more specific message here seeing as this is for pet XP, but knowing Hypixel it's probably safer to leave it like this in case they use the "Ends:" prefix elsewhere besides the pet training menus.
CALENDARDETAILS(" (§e", "Starts at"); // Calendar details
}
@@ -79,15 +80,15 @@ class CountdownCalculator {
val tooltipLine = event.toolTip[i]
val countdownKind = CountdownTypes.values().find { it.match in tooltipLine } ?: continue
val match = regex.findAll(tooltipLine).maxByOrNull { it.value.length } ?: continue
-
- val years = match.groups["years"]?.value?.toInt() ?: 0
- val days = match.groups["days"]?.value?.toInt() ?: 0
- val hours = match.groups["hours"]?.value?.toInt() ?: 0
- val minutes = match.groups["minutes"]?.value?.toInt() ?: 0
- val seconds = match.groups["seconds"]?.value?.toInt() ?: 0
+ if (countdownKind == CountdownTypes.CALENDARDETAILS && !event.itemStack.displayName.startsWith("§aDay ")) return
+ val years = match.groups["years"]?.value?.toLong() ?: 0L
+ val days = match.groups["days"]?.value?.toLong() ?: 0L
+ val hours = match.groups["hours"]?.value?.toLong() ?: 0L
+ val minutes = match.groups["minutes"]?.value?.toLong() ?: 0L
+ val seconds = match.groups["seconds"]?.value?.toLong() ?: 0L
val totalSeconds = (years * 31_536_000L) + (days * 86_400L) + (hours * 3_600L) + (minutes * 60L) + seconds
if (totalSeconds == 0L) continue
- if (years != 0) formatterAsString = "${formatterAsString} yyyy"
+ if (years != 0L) formatterAsString = "${formatterAsString} yyyy"
val useFormatter = DateTimeFormatter.ofPattern(formatterAsString)!!
val countdownTarget = if (countdownKind.isRelative) {
if (lastTimer == null) {
@@ -96,8 +97,8 @@ class CountdownCalculator {
"§r§cThe above countdown is relative, but I can't find another countdown. [NEU]"
)
continue
- } else lastTimer.plusSeconds(totalSeconds)
- } else ZonedDateTime.now().plusSeconds(totalSeconds)
+ } else lastTimer.addTime(years, days, hours, minutes, seconds)
+ } else ZonedDateTime.now().addTime(years, days, hours, minutes, seconds)
val countdownTargetFormatted = useFormatter.format(countdownTarget)
event.toolTip.add(
++i,
@@ -108,4 +109,8 @@ class CountdownCalculator {
}
}
+ private fun ZonedDateTime.addTime(years: Long, days: Long, hours: Long, minutes: Long, seconds: Long): ZonedDateTime {
+ return this.plusYears(years).plusDays(days).plusHours(hours).plusMinutes(minutes).plusSeconds(seconds)
+ }
}
+
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/WarpDessert.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/WarpDessert.kt
index f6f272b9..a41ff3e3 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/WarpDessert.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/WarpDessert.kt
@@ -29,7 +29,7 @@ object WarpDessert {
val message = packet.message.lowercase()
if (message == "/warp dessert") {
Minecraft.getMinecraft().thePlayer.sendChatMessage("/warp desert")
- Utils.addChatMessage("§eDid someone say §d§lDessert§e? Sand is yummy!")
+ Utils.addChatMessage("§e[NEU] Did someone say §d§lDessert§e? Sand is yummy!")
return true
}
return false