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 | |
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')
4 files changed, 169 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 622c0d5f8..170dfb524 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -266,6 +266,7 @@ import at.hannibal2.skyhanni.features.itemabilities.abilitycooldown.ItemAbilityC import at.hannibal2.skyhanni.features.mining.DeepCavernsParkour import at.hannibal2.skyhanni.features.mining.HighlightMiningCommissionMobs import at.hannibal2.skyhanni.features.mining.KingTalismanHelper +import at.hannibal2.skyhanni.features.mining.MiningNotifications import at.hannibal2.skyhanni.features.mining.crystalhollows.CrystalHollowsNamesInCore import at.hannibal2.skyhanni.features.mining.crystalhollows.CrystalHollowsWalls import at.hannibal2.skyhanni.features.mining.eventtracker.MiningEventDisplay @@ -818,6 +819,7 @@ class SkyHanniMod { loadModule(HighlightPlaceableNpcs()) loadModule(PresentWaypoints()) loadModule(MiningEventTracker()) + loadModule(MiningNotifications()) loadModule(JyrreTimer()) loadModule(TotemOfCorruption()) loadModule(NewYearCakeReminder()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningConfig.java index 5beafceb0..92300f690 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningConfig.java @@ -37,6 +37,11 @@ public class MiningConfig { @ConfigOption(name = "Fossil Excavator", desc = "") @Accordion public FossilExcavatorConfig fossilExcavator = new FossilExcavatorConfig(); + + @Expose + @ConfigOption(name = "Notifications", desc = "") + @Accordion + public MiningNotificationsConfig notifications = new MiningNotificationsConfig(); @Expose @ConfigOption(name = "Highlight Commission Mobs", desc = "Highlight Mobs that are part of active commissions.") diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningNotificationsConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningNotificationsConfig.java new file mode 100644 index 000000000..59a74b879 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningNotificationsConfig.java @@ -0,0 +1,46 @@ +package at.hannibal2.skyhanni.config.features.mining; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import at.hannibal2.skyhanni.features.mining.MiningNotifications.MiningNotificationList; +import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; +import io.github.notenoughupdates.moulconfig.observer.Property; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class MiningNotificationsConfig { + @Expose + @ConfigOption(name = "Enabled", desc = "Toggles the Mining Notifications.") + @ConfigEditorBoolean + @FeatureToggle + public boolean enabled = false; + + @Expose + @ConfigOption( + name = "Notification List", + desc = "Drag text to change which events send a title." + ) + @ConfigEditorDraggableList + public List<MiningNotificationList> notifications = new ArrayList<>(Arrays.asList( + MiningNotificationList.MINESHAFT_SPAWN, + MiningNotificationList.SCRAP, + MiningNotificationList.COLD, + MiningNotificationList.GOLDEN_GOBLIN, + MiningNotificationList.DIAMOND_GOBLIN + )); + + @Expose + @ConfigOption(name = "Play Sound", desc = "Plays a ding when a notification is triggered.") + @ConfigEditorBoolean + public boolean playSound = true; + + @Expose + @ConfigOption(name = "Cold Threshold", desc = "Change when the Cold notification gets triggered.") + @ConfigEditorSlider(minValue = 1, maxValue = 100, minStep = 1) + public Property<Integer> coldThreshold = Property.of(50); +} 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() + } +} |