aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/rift
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2024-04-07 21:36:08 +1000
committerGitHub <noreply@github.com>2024-04-07 13:36:08 +0200
commitfcd404d862b4b051474898076fcc06b406d1ea91 (patch)
tree7659d22a41d1529a8d4ebaa62958bc0934596431 /src/main/java/at/hannibal2/skyhanni/features/rift
parent03c416202ccdec17cc46f6d07aae111fa977771a (diff)
downloadskyhanni-fcd404d862b4b051474898076fcc06b406d1ea91.tar.gz
skyhanni-fcd404d862b4b051474898076fcc06b406d1ea91.tar.bz2
skyhanni-fcd404d862b4b051474898076fcc06b406d1ea91.zip
Backend: Remove a lot of deprecated code (#1371)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/rift')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/area/stillgorechateau/RiftBloodEffigies.kt58
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/EnigmaSoulWaypoints.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt61
3 files changed, 58 insertions, 66 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/area/stillgorechateau/RiftBloodEffigies.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/area/stillgorechateau/RiftBloodEffigies.kt
index de0c57850..261229e09 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/rift/area/stillgorechateau/RiftBloodEffigies.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/area/stillgorechateau/RiftBloodEffigies.kt
@@ -4,10 +4,10 @@ import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.data.jsonobjects.repo.RiftEffigiesJson
import at.hannibal2.skyhanni.events.DebugDataCollectEvent
import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
-import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.events.ScoreboardRawChangeEvent
+import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.features.rift.RiftAPI
import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled
import at.hannibal2.skyhanni.utils.ChatUtils
@@ -18,26 +18,22 @@ import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.TimeUtils
+import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.getLorenzVec
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.entity.item.EntityArmorStand
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.minutes
class RiftBloodEffigies {
private val config get() = RiftAPI.config.area.stillgoreChateau.bloodEffigies
private var locations: List<LorenzVec> = emptyList()
- private var effigiesTimes = mapOf(
- 0 to -1L,
- 1 to -1L,
- 2 to -1L,
- 3 to -1L,
- 4 to -1L,
- 5 to -1L,
- )
+ private var effigiesTimes = cleanMap()
companion object {
private val group = RepoPattern.group("rift.area.stillgore.effegies")
@@ -53,16 +49,11 @@ class RiftBloodEffigies {
@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
- effigiesTimes = mapOf(
- 0 to -1L,
- 1 to -1L,
- 2 to -1L,
- 3 to -1L,
- 4 to -1L,
- 5 to -1L,
- )
+ effigiesTimes = cleanMap()
}
+ private fun cleanMap() = (0..5).associateWith { SimpleTimeMark.farPast() }
+
@SubscribeEvent
fun onDebugDataCollect(event: DebugDataCollectEvent) {
event.title("Rift Blood Effigies")
@@ -73,8 +64,7 @@ class RiftBloodEffigies {
}
event.addData {
for ((number, duration) in effigiesTimes) {
- val diff = duration - System.currentTimeMillis()
- val time = TimeUtils.formatDuration(diff - 999)
+ val time = duration.timeUntil().format()
add("$number: $time ($duration)")
}
}
@@ -101,17 +91,17 @@ class RiftBloodEffigies {
val split = hearts.split("§").drop(1)
for ((index, s) in split.withIndex()) {
val time = effigiesTimes[index]!!
- val diff = time - System.currentTimeMillis()
- if (diff < 0L) {
+
+ if (time.isInPast()) {
if (s == "7") {
- if (time != 0L) {
+ if (time.isFarPast()) {
ChatUtils.chat("Effigy #${index + 1} respawned!")
- effigiesTimes = effigiesTimes.editCopy { this[index] = 0L }
+ effigiesTimes = effigiesTimes.editCopy { this[index] = SimpleTimeMark.farPast() }
}
} else {
- if (time != -1L) {
+ if (time.isFarPast()) {
ChatUtils.chat("Effigy #${index + 1} is broken!")
- val endTime = System.currentTimeMillis() + 1_000 * 60 * 20
+ val endTime = SimpleTimeMark.now() + 20.minutes
effigiesTimes = effigiesTimes.editCopy { this[index] = endTime }
}
}
@@ -120,8 +110,7 @@ class RiftBloodEffigies {
}
@SubscribeEvent
- fun onTick(event: LorenzTickEvent) {
- if (!event.repeatSeconds(1)) return
+ fun onSecondPassed(event: SecondPassedEvent) {
if (!isEnabled()) return
for (entity in EntityUtils.getEntitiesNearby<EntityArmorStand>(LocationUtils.playerLocation(), 6.0)) {
@@ -130,8 +119,8 @@ class RiftBloodEffigies {
val index = locations.indexOf(nearest)
val string = group("time")
- val time = TimeUtils.getMillis(string)
- effigiesTimes = effigiesTimes.editCopy { this[index] = System.currentTimeMillis() + time }
+ val time = TimeUtils.getDuration(string)
+ effigiesTimes = effigiesTimes.editCopy { this[index] = SimpleTimeMark.now() + time }
}
}
}
@@ -144,23 +133,22 @@ class RiftBloodEffigies {
val name = "Effigy #${index + 1}"
val duration = effigiesTimes[index]!!
- if (duration == -1L) {
+ if (duration.isFarPast()) {
if (config.unknownTime) {
event.drawWaypointFilled(location, LorenzColor.GRAY.toColor(), seeThroughBlocks = true)
event.drawDynamicText(location, "§7Unknown Time ($name)", 1.5)
continue
}
} else {
- val diff = duration - System.currentTimeMillis()
- if (duration <= 0L) {
+ if (duration.isFarPast()) {
event.drawWaypointFilled(location, LorenzColor.RED.toColor(), seeThroughBlocks = true)
event.drawDynamicText(location, "§cBreak $name!", 1.5)
continue
}
- if (config.respawningSoon && diff < 60_000 * config.respwningSoonTime) {
- val time = TimeUtils.formatDuration(diff - 999)
+ if (config.respawningSoon && duration.passedSince() < config.respwningSoonTime.minutes) {
event.drawWaypointFilled(location, LorenzColor.YELLOW.toColor(), seeThroughBlocks = true)
+ val time = duration.timeUntil()
event.drawDynamicText(location, "§e$name is respawning §b$time", 1.5)
continue
}
@@ -172,7 +160,7 @@ class RiftBloodEffigies {
}
}
- fun isEnabled() = RiftAPI.inRift() && RiftAPI.inStillgoreChateau() && config.enabled
+ fun isEnabled() = RiftAPI.inRift() && config.enabled && RiftAPI.inStillgoreChateau()
@SubscribeEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/EnigmaSoulWaypoints.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/EnigmaSoulWaypoints.kt
index 34a19a01c..7b337a2e5 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/EnigmaSoulWaypoints.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/EnigmaSoulWaypoints.kt
@@ -15,7 +15,8 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzVec
-import at.hannibal2.skyhanni.utils.NEUItems
+import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
+import at.hannibal2.skyhanni.utils.NEUItems.getItemStack
import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
@@ -37,7 +38,7 @@ object EnigmaSoulWaypoints {
private var adding = true
private val item by lazy {
- val neuItem = NEUItems.getItemStack("SKYBLOCK_ENIGMA_SOUL")
+ val neuItem = "SKYBLOCK_ENIGMA_SOUL".asInternalName().getItemStack()
Utils.createItemStack(
neuItem.item,
"§5Toggle Missing",
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt
index c995fa405..8282bf1e6 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt
@@ -8,10 +8,14 @@ import at.hannibal2.skyhanni.features.rift.RiftAPI
import at.hannibal2.skyhanni.utils.ConditionalUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
-import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.StringUtils.matchFirst
import at.hannibal2.skyhanni.utils.TimeUtils
+import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration
+import kotlin.time.Duration.Companion.minutes
+import kotlin.time.Duration.Companion.seconds
class RiftTimer {
@@ -23,54 +27,53 @@ class RiftTimer {
)
private var display = emptyList<String>()
- private var maxTime = 0L
- private var currentTime = 0L
- private var latestTime = 0L
+ private var maxTime = 0.seconds
+ private var currentTime = 0.seconds
+ private var latestTime = 0.seconds
private val changes = mutableMapOf<Long, String>()
@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
display = emptyList()
- maxTime = 0
- latestTime = 0
- currentTime = 0
+ maxTime = 0.seconds
+ latestTime = 0.seconds
+ currentTime = 0.seconds
}
//todo use ActionBarValueUpdateEvent
@SubscribeEvent
fun onActionBarUpdate(event: ActionBarUpdateEvent) {
if (!isEnabled()) return
- for (entry in event.actionBar.split(" ")) {
- timePattern.matchMatcher(entry) {
- val color = group("color")
- val newTime = getTime(group("time"))
- if (color == "7") {
- if (newTime > maxTime) {
- maxTime = newTime
- }
+
+ event.actionBar.split(" ").matchFirst(timePattern) {
+ val color = group("color")
+ val newTime = TimeUtils.getDuration(group("time").replace("m", "m "))
+
+ if (color == "7") {
+ if (newTime > maxTime) {
+ maxTime = newTime
}
- currentTime = newTime
- update()
}
+ currentTime = newTime
+ update()
}
}
- private fun getTime(time: String) = TimeUtils.getMillis(time.replace("m", "m "))
-
private fun update() {
if (currentTime != latestTime) {
- val diff = (currentTime - latestTime) + 1000
+ val diff = (currentTime - latestTime) + 1.seconds
latestTime = currentTime
if (latestTime != maxTime) {
addDiff(diff)
}
}
- val currentFormat = TimeUtils.formatDuration(currentTime)
- val percentage = LorenzUtils.formatPercentage(currentTime.toDouble() / maxTime)
+ val currentFormat = currentTime.format()
+ val percentage =
+ LorenzUtils.formatPercentage(currentTime.inWholeMilliseconds.toDouble() / maxTime.inWholeMilliseconds)
val percentageFormat = if (config.percentage.get()) " §7($percentage)" else ""
- val maxTimeFormat = if (config.maxTime.get()) "§7/§b" + TimeUtils.formatDuration(maxTime) else ""
- val color = if (currentTime <= 60_000) "§c" else if (currentTime <= 60_000 * 5) "§e" else "§b"
+ val maxTimeFormat = if (config.maxTime.get()) "§7/§b" + maxTime.format() else ""
+ val color = if (currentTime <= 1.minutes) "§c" else if (currentTime <= 5.minutes) "§e" else "§b"
val firstLine = "§eRift Timer: $color$currentFormat$maxTimeFormat$percentageFormat"
display = buildList {
@@ -82,11 +85,11 @@ class RiftTimer {
}
}
- private fun addDiff(diff: Long) {
- val diffFormat = if (diff > 0) {
- "§a+${TimeUtils.formatDuration(diff)}"
- } else if (diff < 0) {
- "§c-${TimeUtils.formatDuration(-diff)}"
+ private fun addDiff(diff: Duration) {
+ val diffFormat = if (diff > 0.seconds) {
+ "§a+${diff.format()}"
+ } else if (diff < 0.seconds) {
+ "§c-${(-diff).format()}"
} else return
changes[System.currentTimeMillis()] = diffFormat