Skip to content

Commit 38b7e91

Browse files
committed
fix: better fishing timer warning incorrectly
1 parent a7724e6 commit 38b7e91

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/main/kotlin/com/github/itsempa/nautilus/features/gui/BetterFishingTimer.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.github.itsempa.nautilus.events.NautilusDebugEvent
1515
import com.github.itsempa.nautilus.events.SeaCreatureEvent
1616
import com.github.itsempa.nautilus.utils.NautilusNullableUtils.orFarPast
1717
import me.owdding.ktmodules.Module
18+
import kotlin.reflect.KMutableProperty0
1819
import kotlin.time.Duration
1920
import kotlin.time.Duration.Companion.seconds
2021

@@ -84,6 +85,8 @@ object BetterFishingTimer {
8485
config.position.renderString(display, posLabel = "Better Fishing Timer")
8586
}
8687

88+
private fun KMutableProperty0<Int>.decrease() = set((get() - 1).coerceAtLeast(0))
89+
8790
private fun SeaCreatureData.handleSpawn() {
8891
if (isOwn) ++ownMobs else ++otherMobs
8992
val oldest = oldestSeaCreature
@@ -95,13 +98,17 @@ object BetterFishingTimer {
9598
}
9699

97100
private fun SeaCreatureData.handleDeSpawn() {
98-
if (isOwn) --ownMobs else --otherMobs
101+
val property = if (isOwn) ::ownMobs else ::otherMobs
102+
property.decrease()
99103
if (this == oldestSeaCreature) calculateOldest()
100104
update()
101105
}
102106

103107
private fun update() {
104-
if (totalMobs == 0 && display != null) return reset()
108+
if (totalMobs == 0) {
109+
if (display != null) reset()
110+
return
111+
}
105112
if (!isEnabled()) return
106113
val timeSince = oldestTime.passedSince()
107114

@@ -132,7 +139,7 @@ object BetterFishingTimer {
132139
lastWarning.passedSince() < warningDelay -> AlertReason.NO_ALERT
133140
timeAlert && timeSince >= timeAlertSeconds.seconds -> AlertReason.TIME
134141
warnPersonalCap && currentCap.hasPersonalCap && ownMobs >= currentCap.personalCap -> AlertReason.PERSONAL_CAP
135-
warnGlobalCap && ownMobs >= GLOBAL_CAP -> AlertReason.GLOBAL_CAP
142+
warnGlobalCap && totalMobs >= GLOBAL_CAP -> AlertReason.GLOBAL_CAP
136143
else -> AlertReason.NO_ALERT
137144
}
138145
}

0 commit comments

Comments
 (0)