blob: 785c2c358dcc90945deb166f66737c43904c87fc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package at.hannibal2.skyhanni.features.event.winter
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.data.ScoreboardData
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.features.fame.ReminderUtils
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.HypixelCommands
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SkyBlockTime
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds
@SkyHanniModule
object NewYearCakeReminder {
private val config get() = SkyHanniMod.feature.event.winter
private val sidebarDetectionPattern by RepoPattern.pattern(
"event.winter.newyearcake.reminder.sidebar",
"§dNew Year Event!§f (?<time>.*)",
)
private var lastReminderSend = SimpleTimeMark.farPast()
@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
if (event.message == "§aYou claimed a §r§cNew Year Cake§r§a!") {
markCakeClaimed()
}
}
@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
// cake already claimed
if (event.inventoryName == "Baker") {
markCakeClaimed()
}
}
private fun markCakeClaimed() {
val playerSpecific = ProfileStorageData.playerSpecific ?: return
playerSpecific.winter.cakeCollectedYear = SkyBlockTime.now().year
}
private fun isClaimed(): Boolean {
val playerSpecific = ProfileStorageData.playerSpecific ?: return false
return playerSpecific.winter.cakeCollectedYear == SkyBlockTime.now().year
}
@SubscribeEvent
fun onSecondPassed(event: SecondPassedEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!config.newYearCakeReminder) return
if (!isCakeTime()) return
if (ReminderUtils.isBusy()) return
if (isClaimed()) return
if (lastReminderSend.passedSince() < 30.seconds) return
lastReminderSend = SimpleTimeMark.now()
ChatUtils.clickToActionOrDisable(
"Reminding you to grab the free New Year Cake. Click here to open the baker menu!",
config::newYearCakeReminder,
actionName = "open the baker menu",
action = { HypixelCommands.openBaker() },
)
}
private fun isCakeTime() = ScoreboardData.sidebarLinesFormatted.any { sidebarDetectionPattern.matches(it) }
}
|