diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-06-22 14:23:26 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-06-22 14:23:26 +0200 |
commit | 13c636ff4ad49403c078b208dabd0b87972b0440 (patch) | |
tree | 0bc36b94b621a27acba352b58e8f22dd59c5c07f | |
parent | 3e7aa9855489888283b6c53ce14002fe38d04dbe (diff) | |
download | skyhanni-13c636ff4ad49403c078b208dabd0b87972b0440.tar.gz skyhanni-13c636ff4ad49403c078b208dabd0b87972b0440.tar.bz2 skyhanni-13c636ff4ad49403c078b208dabd0b87972b0440.zip |
Added rift timer
-rw-r--r-- | CHANGELOG.md | 6 | ||||
-rw-r--r-- | FEATURES.md | 4 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/Features.java | 4 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java | 37 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/IslandType.kt | 1 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/rift/RiftTimer.kt | 99 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt | 9 |
8 files changed, 162 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 7549bc4f4..9c884a6f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # SkyHanni - Change Log +## Version 0.19 (unreleased) + +### New Features ++ Added **Rift Timer** + + Show the remaining rift time, max time, percentage, and extra time changes. + ## Version 0.18 (2023-06-19) ### New Features diff --git a/FEATURES.md b/FEATURES.md index 917f1c057..6d71d09e0 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -270,6 +270,10 @@ + Show a warning when finding a **visitor with a rare reward** + Show message in chat, over the visitor and prevents refusing +## The Rift ++ **Rift Timer** + + Show the remaining rift time, max time, percentage, and extra time changes. + ## Commands + **/wiki <search term>** - using hypixel-skyblock.fandom.com instead of Hypixel wiki. + **/shmarkplayer <player>** - marking a player with yellow color. diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 73d136618..cf099e987 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -59,6 +59,7 @@ import at.hannibal2.skyhanni.features.mobs.AshfangMinisNametagHider import at.hannibal2.skyhanni.features.mobs.MobHighlight import at.hannibal2.skyhanni.features.nether.ashfang.* import at.hannibal2.skyhanni.features.nether.reputationhelper.CrimsonIsleReputationHelper +import at.hannibal2.skyhanni.features.rift.RiftTimer import at.hannibal2.skyhanni.features.slayer.* import at.hannibal2.skyhanni.features.slayer.blaze.BlazeSlayerClearView import at.hannibal2.skyhanni.features.slayer.blaze.BlazeSlayerDaggerHelper @@ -300,6 +301,7 @@ class SkyHanniMod { loadModule(ShowItemUuid()) loadModule(SlayerRngMeterDisplay()) loadModule(GhostCounter) + loadModule(RiftTimer()) init() diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java index d80195e71..a5a42b48c 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Features.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java @@ -120,6 +120,10 @@ public class Features extends Config { public GhostCounter ghostCounter = new GhostCounter(); @Expose + @Category(name = "The Rift", desc = "Features for The Rift dimension.") + public RiftConfig rift = new RiftConfig(); + + @Expose @Category(name = "Misc", desc = "Settings without a category.") public Misc misc = new Misc(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java new file mode 100644 index 000000000..581413ec0 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java @@ -0,0 +1,37 @@ +package at.hannibal2.skyhanni.config.features; + +import at.hannibal2.skyhanni.config.core.config.Position; +import com.google.gson.annotations.Expose; +import io.github.moulberry.moulconfig.annotations.Accordion; +import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; +import io.github.moulberry.moulconfig.annotations.ConfigOption; + +public class RiftConfig { + + @ConfigOption(name = "Rift Timer", desc = "") + @Accordion + @Expose + public TimerConfig timer = new TimerConfig(); + + public static class TimerConfig { + + @Expose + @ConfigOption(name = "Enabled", desc = "Show the remaining rift time, max time, percentage, and extra time changes.") + @ConfigEditorBoolean + public boolean enabled = true; + + @Expose + @ConfigOption(name = "Max time", desc = "Show max time.") + @ConfigEditorBoolean + public boolean maxTime = true; + + @Expose + @ConfigOption(name = "Percentage", desc = "Show percentage.") + @ConfigEditorBoolean + public boolean percentage = true; + + @Expose + public Position timerPosition = new Position(10, 10, false, true); + + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt b/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt index 8b9c4dc3e..d3357e880 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt @@ -18,6 +18,7 @@ enum class IslandType(val displayName: String, val apiName: String = "null") { GARDEN("Garden"), GARDEN_GUEST("Garden Guest"), SPIDER_DEN("Spider's Den"), + THE_RIFT("The Rift"), NONE(""), UNKNOWN("???"), diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/RiftTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/RiftTimer.kt new file mode 100644 index 000000000..d1fcc758d --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/rift/RiftTimer.kt @@ -0,0 +1,99 @@ +package at.hannibal2.skyhanni.features.rift + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.events.ConfigLoadEvent +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.LorenzActionBarEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +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.TimeUtils +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class RiftTimer { + private val config get() = SkyHanniMod.feature.rift.timer + private var display = listOf<String>() + private var maxTime = 0L + private var latestTime = 0L + private val changes = mutableMapOf<Long, String>() + + @SubscribeEvent + fun onConfigLoad(event: ConfigLoadEvent) { + display = emptyList() + } + + @SubscribeEvent + fun onChatMessage(event: LorenzChatEvent) { + if (!isEnabled()) return + + val message = event.message + " §r§7You have §r§a(?<time>.*)ф §r§7left before the rift collapses!".toPattern().matchMatcher(message) { + val time = group("time") + maxTime = formatTime(time) + } + } + + @SubscribeEvent + fun onActionBar(event: LorenzActionBarEvent) { + if (!isEnabled()) return + + val message = event.message + for (entry in message.split(" ")) { + "§(?<color>[a7])(?<time>.*)ф Left.*".toPattern().matchMatcher(entry) { + val color = group("color") + if (color == "7") { + display = emptyList() + return + } + val time = group("time") + val currentTime = formatTime(time) + update(currentTime) + } + } + } + + private fun formatTime(time: String) = TimeUtils.getMillis(time.replace("m", "m ")) + + private fun update(currentTime: Long) { + if (currentTime == latestTime) return + val diff = (currentTime - latestTime) + 1000 + latestTime = currentTime + addDiff(diff) + + val currentFormat = TimeUtils.formatDuration(currentTime) + val percentage = LorenzUtils.formatPercentage(currentTime.toDouble() / maxTime) + val percentageFormat = if (config.percentage) " §7($percentage)" else "" + val maxTimeFormat = if (config.maxTime) "§7/§b" + TimeUtils.formatDuration(maxTime) else "" + val color = if (currentTime <= 60_000) "§c" else if (currentTime <= 60_000 * 5) "§e" else "§b" + val firstLine = "§eRift Timer: $color$currentFormat$maxTimeFormat$percentageFormat" + + display = buildList { + add(firstLine) + changes.keys.removeIf { System.currentTimeMillis() > it + 4_000 } + for (entry in changes.values) { + add(entry) + } + } + } + + private fun addDiff(diff: Long) { + val diffFormat = if (diff > 0) { + "§a+${TimeUtils.formatDuration(diff)}" + } else if (diff < 0) { + "§c-${TimeUtils.formatDuration(-diff)}" + } else return + + changes[System.currentTimeMillis()] = diffFormat + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { + if (!isEnabled()) return + + config.timerPosition.renderStrings(display, posLabel = "Rift Timer") + } + + fun isEnabled() = LorenzUtils.inIsland(IslandType.THE_RIFT) && config.enabled +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 054b8509c..bc50ea0e6 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -372,4 +372,13 @@ object LorenzUtils { && tileSign.signText[2].unformattedText.removeColor() == "Set your" && tileSign.signText[3].unformattedText.removeColor() == "speed cap!") } + + fun inIsland(island: IslandType) = inSkyBlock && skyBlockIsland == island + + fun <K, N : Number> MutableMap<K, N>.addOrPut(item: K, amount: N) { + val old = this[item] ?: 0 + val d = old.toDouble() + amount.toDouble() + @Suppress("UNCHECKED_CAST") + this[item] = d as N + } }
\ No newline at end of file |