aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2023-04-30 21:41:12 +1000
committerGitHub <noreply@github.com>2023-04-30 13:41:12 +0200
commite3654b50f30224f1815d4d8f289ec8d00a1f04e9 (patch)
tree1eed970d418d27d39dc826a42988223aef37ba66 /src/main/java/at/hannibal2/skyhanni/features
parent5a04a6166b1d9f94a23ba13105c0faf2c117243f (diff)
downloadskyhanni-e3654b50f30224f1815d4d8f289ec8d00a1f04e9.tar.gz
skyhanni-e3654b50f30224f1815d4d8f289ec8d00a1f04e9.tar.bz2
skyhanni-e3654b50f30224f1815d4d8f289ec8d00a1f04e9.zip
Sixth visitor changes (#76)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt42
1 files changed, 31 insertions, 11 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt
index 4250ddfb3..afdd55e87 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt
@@ -1,19 +1,23 @@
package at.hannibal2.skyhanni.features.garden.visitor
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.TitleUtils
import at.hannibal2.skyhanni.events.CropClickEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
-import at.hannibal2.skyhanni.events.TabListUpdateEvent
import at.hannibal2.skyhanni.events.VisitorArrivalEvent
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
+import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.TabListData
import at.hannibal2.skyhanni.utils.TimeUtils
import net.minecraftforge.event.world.WorldEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.concurrent.fixedRateTimer
import kotlin.math.roundToLong
class GardenVisitorTimer {
+ private val config get() = SkyHanniMod.feature.garden
private val patternNextVisitor = " Next Visitor: §r§b(?<time>.*)".toPattern()
private val patternVisitors = "§b§lVisitors: §r§f\\((?<amount>\\d)\\)".toPattern()
private var render = ""
@@ -21,6 +25,7 @@ class GardenVisitorTimer {
private var lastVisitors: Int = -1
private var sixthVisitorArrivalTime: Long = 0
private var visitorJustArrived: Boolean = false
+ private var sixthVisitorReady: Boolean = false
private var visitorInterval
get() = SkyHanniMod.feature.hidden.visitorInterval
set(value) {
@@ -32,14 +37,19 @@ class GardenVisitorTimer {
visitorJustArrived = true
}
- @SubscribeEvent
- fun onTabListUpdate(event: TabListUpdateEvent) {
+ init {
+ fixedRateTimer(name = "skyhanni-update-visitor-display", period = 1000L) {
+ updateVisitorDisplay()
+ }
+ }
+
+ private fun updateVisitorDisplay() {
if (!isEnabled()) return
var visitorsAmount = 0
var millis = visitorInterval
var queueFull = false
- for (line in event.tabList) {
+ for (line in TabListData.getTabList()) {
val matcher = patternNextVisitor.matcher(line)
if (matcher.matches()) {
val rawTime = matcher.group("time")
@@ -65,13 +75,20 @@ class GardenVisitorTimer {
}
if (queueFull) {
- if (sixthVisitorArrivalTime != 0L && visitorJustArrived) {
+ if (visitorJustArrived && visitorsAmount - lastVisitors == 1) {
updateSixthVisitorArrivalTime()
visitorJustArrived = false
+ sixthVisitorReady = false
}
millis = sixthVisitorArrivalTime - System.currentTimeMillis()
- if (isSixthVisitorEnabled() && sixthVisitorArrivalTime != 0L && millis < 0) {
+ SkyHanniMod.feature.hidden.nextSixthVisitorArrival = System.currentTimeMillis() + millis + (5 - visitorsAmount) * visitorInterval
+ if (isSixthVisitorEnabled() && millis < 0) {
visitorsAmount++
+ if (!sixthVisitorReady) {
+ TitleUtils.sendTitle("§a6th Visitor Ready", 5_000)
+ sixthVisitorReady = true
+ if (isSixthVisitorWarningEnabled()) SoundUtils.playBeepSound()
+ }
}
}
@@ -99,13 +116,15 @@ class GardenVisitorTimer {
fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) {
if (!isEnabled()) return
- SkyHanniMod.feature.garden.visitorTimerPos.renderString(render, posLabel = "Garden Visitor Timer")
+ config.visitorTimerPos.renderString(render, posLabel = "Garden Visitor Timer")
}
@SubscribeEvent
fun onWorldLoad(event: WorldEvent.Load) {
lastVisitors = -1
- sixthVisitorArrivalTime = 0
+ sixthVisitorArrivalTime = SkyHanniMod.feature.hidden.nextSixthVisitorArrival
+ sixthVisitorReady = false
+ lastMillis = sixthVisitorArrivalTime - System.currentTimeMillis()
}
@SubscribeEvent
@@ -118,6 +137,7 @@ class GardenVisitorTimer {
sixthVisitorArrivalTime = System.currentTimeMillis() + visitorInterval
}
- private fun isSixthVisitorEnabled() = SkyHanniMod.feature.garden.visitorTimerSixthVisitorEnabled
- private fun isEnabled() = GardenAPI.inGarden() && SkyHanniMod.feature.garden.visitorTimerEnabled
-} \ No newline at end of file
+ private fun isSixthVisitorEnabled() = config.visitorTimerSixthVisitorEnabled
+ private fun isSixthVisitorWarningEnabled() = config.visitorTimerSixthVisitorWarning
+ private fun isEnabled() = GardenAPI.inGarden() && config.visitorTimerEnabled
+}