diff options
| author | martimavocado <39881008+martimavocado@users.noreply.github.com> | 2024-04-13 07:55:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-13 08:55:48 +0200 |
| commit | e3f1794b61cc4ad7a48b15ed1abb0b28eeaa71eb (patch) | |
| tree | 755943bc28d95d29c3e1ca5f2df659ab45c7d761 /src/main/java/at/hannibal2/skyhanni/features/mining | |
| parent | 0d41a281c8d87128a0004fed96dada8b1b5e950a (diff) | |
| download | skyhanni-e3f1794b61cc4ad7a48b15ed1abb0b28eeaa71eb.tar.gz skyhanni-e3f1794b61cc4ad7a48b15ed1abb0b28eeaa71eb.tar.bz2 skyhanni-e3f1794b61cc4ad7a48b15ed1abb0b28eeaa71eb.zip | |
Feature: Mining Notifications (#1429)
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/mining')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/mining/MiningNotifications.kt | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/MiningNotifications.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/MiningNotifications.kt new file mode 100644 index 000000000..3115ac48a --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/MiningNotifications.kt @@ -0,0 +1,116 @@ +package at.hannibal2.skyhanni.features.mining + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.events.ConfigLoadEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent +import at.hannibal2.skyhanni.events.ScoreboardChangeEvent +import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardPattern +import at.hannibal2.skyhanni.utils.ConditionalUtils +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.SoundUtils +import at.hannibal2.skyhanni.utils.StringUtils.matchFirst +import at.hannibal2.skyhanni.utils.StringUtils.matches +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.math.absoluteValue +import kotlin.time.Duration.Companion.milliseconds +import kotlin.time.Duration.Companion.seconds + +class MiningNotifications { + + 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(): String { + return 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!" + ) + private val goldenGoblinSpawn by patternGroup.pattern( + "goblin.goldspawn", + "§6A Golden Goblin has spawned!" + ) + private val diamondGoblinSpawn by patternGroup.pattern( + "goblin.diamondspawn", + "§6A §r§bDiamond Goblin §r§6has spawned!" + ) + private val coldReset by patternGroup.pattern( + "cold.reset", + "§cThe warmth of the campfire reduced your §r§b❄ Cold §r§cto 0!" + ) + + private val config get() = SkyHanniMod.feature.mining.notifications + + private var cold = 0 + private var hasSentCold = false + private var coldResetTimer = SimpleTimeMark.farPast() + + @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) + coldReset.matches(message) -> { + cold = 0 + hasSentCold = false + coldResetTimer = SimpleTimeMark.now().plus(1.seconds) + } + } + } + + @SubscribeEvent + fun onScoreboardChange(event: ScoreboardChangeEvent) { + if (!LorenzUtils.inAnyIsland(IslandType.DWARVEN_MINES, IslandType.MINESHAFT)) return + if (!config.enabled) return + val newCold = event.newList.matchFirst(ScoreboardPattern.coldPattern) { + group("cold").toInt().absoluteValue + } ?: 0 + if (cold == newCold) return + cold = newCold + if (coldResetTimer.isInFuture()) return + if (cold >= config.coldThreshold.get() && !hasSentCold) { + hasSentCold = true + sendNotification(MiningNotificationList.COLD) + } + } + + @SubscribeEvent + fun onWorldChange(event: LorenzWorldChangeEvent) { + cold = 0 + hasSentCold = false + } + + @SubscribeEvent + fun onConfigLoad(event: ConfigLoadEvent) { + ConditionalUtils.onToggle(config.coldThreshold) { + if (cold != 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() + } +} |
