aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2
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
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')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Garden.java7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt42
3 files changed, 41 insertions, 11 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java
index 0fa527216..4854f054f 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java
@@ -58,6 +58,13 @@ public class Garden {
public boolean visitorTimerSixthVisitorEnabled = true;
@Expose
+ @ConfigOption(name = "Sixth Visitor Warning", desc = "Notifies when it is believed that the sixth visitor has arrived. " +
+ "May be inaccurate with coop members farming simultaneously.")
+ @ConfigEditorBoolean
+ @ConfigAccordionId(id = 2)
+ public boolean visitorTimerSixthVisitorWarning = true;
+
+ @Expose
public Position visitorTimerPos = new Position(-373, -203, false, true);
@Expose
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java
index 0115b956b..a310ab367 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java
@@ -70,6 +70,9 @@ public class Hidden {
public long visitorInterval = 15 * 60_000L;
@Expose
+ public long nextSixthVisitorArrival = 0;
+
+ @Expose
public Map<Long, List<CropType>> gardenJacobFarmingContestTimes = new HashMap<>();
@Expose
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
+}