Skip to content

Commit

Permalink
Hoppity and Chocolate being less annoying (#2196)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <[email protected]>
  • Loading branch information
hannibal002 and hannibal002 committed Jul 7, 2024
1 parent 6b3e2d7 commit 6c1c000
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TimeUtils.format
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.regex.Matcher
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds

@SkyHanniModule
Expand Down Expand Up @@ -218,7 +219,7 @@ object HoppityEggsManager {
private fun warn() {
if (!config.warnUnclaimedEggs) return
if (ReminderUtils.isBusy() && !config.warnWhileBusy) return
if (lastWarnTime.passedSince() < 30.seconds) return
if (lastWarnTime.passedSince() < 1.minutes) return

lastWarnTime = now()
val amount = HoppityEggType.entries.size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.highlight
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SkyBlockTime
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds
import kotlin.time.Duration.Companion.minutes

@SkyHanniModule
object HoppityNpc {
Expand Down Expand Up @@ -51,7 +51,7 @@ object HoppityNpc {
if (ReminderUtils.isBusy()) return
if (hoppityYearOpened == SkyBlockTime.now().year) return
if (!ChocolateFactoryAPI.isHoppityEvent()) return
if (lastReminderSent.passedSince() <= 30.seconds) return
if (lastReminderSent.passedSince() <= 2.minutes) return

ChatUtils.clickableChat(
"New rabbits are available at §aHoppity's Shop§e! §c(Click to disable this reminder)",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.features.inventory.chocolatefactory

import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggsCompactChat
import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggsManager
Expand All @@ -10,11 +11,9 @@ import at.hannibal2.skyhanni.utils.HypixelCommands
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.formatLong
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.TimeUtils.format
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds

@SkyHanniModule
object ChocolateFactoryBarnManager {
Expand All @@ -28,11 +27,11 @@ object ChocolateFactoryBarnManager {
*/
private val rabbitCrashedPattern by ChocolateFactoryAPI.patternGroup.pattern(
"rabbit.crushed",
"§c§lBARN FULL! §f\\D+ §7got §ccrushed§7! §6\\+(?<amount>[\\d,]+) Chocolate"
"§c§lBARN FULL! §f\\D+ §7got §ccrushed§7! §6\\+(?<amount>[\\d,]+) Chocolate",
)

var barnFull = false
private var lastBarnFullWarning = SimpleTimeMark.farPast()
private var sentBarnFullWarning = false

@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
Expand All @@ -41,7 +40,7 @@ object ChocolateFactoryBarnManager {
HoppityEggsManager.newRabbitFound.matchMatcher(event.message) {
val profileStorage = profileStorage ?: return
profileStorage.currentRabbits += 1
trySendBarnFullMessage()
trySendBarnFullMessage(inventory = false)
HoppityEggsManager.shareWaypointPrompt()
}

Expand All @@ -64,7 +63,12 @@ object ChocolateFactoryBarnManager {
}
}

fun trySendBarnFullMessage() {
@SubscribeEvent
fun onInventoryClose(event: InventoryCloseEvent) {
sentBarnFullWarning = false
}

fun trySendBarnFullMessage(inventory: Boolean) {
if (!ChocolateFactoryAPI.isEnabled()) return

if (config.barnCapacityThreshold <= 0) {
Expand All @@ -79,7 +83,9 @@ object ChocolateFactoryBarnManager {
barnFull = remainingSpace <= config.barnCapacityThreshold
if (!barnFull) return

if (lastBarnFullWarning.passedSince() < 30.seconds) return
if (inventory && sentBarnFullWarning) return

sentBarnFullWarning = true

if (profileStorage.maxRabbits == -1) {
ChatUtils.clickableChat(
Expand All @@ -99,7 +105,6 @@ object ChocolateFactoryBarnManager {
"§eClick to run /cf!",
)
SoundUtils.playBeepSound()
lastBarnFullWarning = SimpleTimeMark.now()
}

fun barnStatus(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ object ChocolateFactoryDataLoader {
item.getLore().matchFirst(barnAmountPattern) {
profileStorage.currentRabbits = group("rabbits").formatInt()
profileStorage.maxRabbits = group("max").formatInt()
ChocolateFactoryBarnManager.trySendBarnFullMessage()
ChocolateFactoryBarnManager.trySendBarnFullMessage(inventory = true)
}
}

Expand Down

0 comments on commit 6c1c000

Please sign in to comment.