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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
package at.hannibal2.skyhanni.features.mining
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.GetFromSackAPI
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.data.MiningAPI.getCold
import at.hannibal2.skyhanni.data.MiningAPI.inColdIsland
import at.hannibal2.skyhanni.data.MiningAPI.lastColdReset
import at.hannibal2.skyhanni.events.ColdUpdateEvent
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.utils.ConditionalUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.LorenzUtils.runDelayed
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.PrimitiveItemStack.Companion.makePrimitiveStack
import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
object MiningNotifications {
private val ASCENSION_ROPE = "ASCENSION_ROPE".asInternalName().makePrimitiveStack(1)
enum class MiningNotificationList(val str: String, val notification: String) {
MINESHAFT_SPAWN("§bGlacite Mineshaft", "§bMineshaft"),
SCRAP("§9Suspicious Scrap", "§9Suspicious Scrap"),
GOLDEN_GOBLIN("§6Golden Goblin", "§6Golden Goblin"),
DIAMOND_GOBLIN("§bDiamond Goblin", "§bDiamond Goblin"),
COLD("§bCold", "§bCold");
override fun toString() = str
}
private val patternGroup = RepoPattern.group("mining.notifications")
private val mineshaftSpawn by patternGroup.pattern(
"mineshaft.spawn",
"§5§lWOW! §r§aYou found a §r§bGlacite Mineshaft §r§aportal!"
)
private val scrapDrop by patternGroup.pattern(
"scrapdrop",
"§6§lEXCAVATOR! §r§fYou found a §r§9Suspicious Scrap§r§f!"
)
val goldenGoblinSpawn by patternGroup.pattern(
"goblin.goldspawn",
"§6A Golden Goblin has spawned!"
)
val diamondGoblinSpawn by patternGroup.pattern(
"goblin.diamondspawn",
"§6A §r§bDiamond Goblin §r§6has spawned!"
)
private val frostbitePattern by patternGroup.pattern(
"cold.frostbite",
"§9§lBRRR! §r§bYou're freezing! All you can think about is getting out of here to a warm campfire\\.\\.\\."
)
private val config get() = SkyHanniMod.feature.mining.notifications
private var hasSentCold = false
@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
if (!LorenzUtils.inMiningIsland()) return
if (!config.enabled) return
val message = event.message
when {
mineshaftSpawn.matches(message) -> sendNotification(MiningNotificationList.MINESHAFT_SPAWN)
scrapDrop.matches(message) -> sendNotification(MiningNotificationList.SCRAP)
goldenGoblinSpawn.matches(message) -> sendNotification(MiningNotificationList.GOLDEN_GOBLIN)
diamondGoblinSpawn.matches(message) -> sendNotification(MiningNotificationList.DIAMOND_GOBLIN)
frostbitePattern.matches(message) -> {
if (IslandType.MINESHAFT.isInIsland() && config.getAscensionRope) {
runDelayed(0.5.seconds) {
GetFromSackAPI.getFromChatMessageSackItems(ASCENSION_ROPE)
}
}
}
}
}
@SubscribeEvent
fun onColdUpdate(event: ColdUpdateEvent) {
if (!inColdIsland()) return
if (!config.enabled) return
if (lastColdReset.passedSince() < 1.seconds) return
if (event.cold >= config.coldThreshold.get() && !hasSentCold) {
hasSentCold = true
sendNotification(MiningNotificationList.COLD)
}
}
@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
hasSentCold = false
}
@SubscribeEvent
fun onConfigLoad(event: ConfigLoadEvent) {
ConditionalUtils.onToggle(config.coldThreshold) {
if (getCold() != config.coldThreshold.get()) hasSentCold = false
}
}
private fun sendNotification(type: MiningNotificationList) {
if (!config.notifications.contains(type)) return
LorenzUtils.sendTitle(type.notification, 1500.milliseconds)
if (config.playSound) SoundUtils.playPlingSound()
}
}
|