diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/mining/GoldenGoblinHighlight.kt | 56 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/mining/MiningNotifications.kt | 6 |
2 files changed, 59 insertions, 3 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/GoldenGoblinHighlight.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/GoldenGoblinHighlight.kt new file mode 100644 index 000000000..bd5a5baf4 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/GoldenGoblinHighlight.kt @@ -0,0 +1,56 @@ +package at.hannibal2.skyhanni.features.mining + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.mob.Mob +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.MobEvent +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.SimpleTimeMark +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.seconds + +class GoldenGoblinHighlight { + + private val config get() = SkyHanniMod.feature.mining.highlightYourGoldenGoblin + + private val goblinPattern by RepoPattern.pattern("mining.mob.golden.goblin", "Golden Goblin|Diamond Goblin") + + private fun isEnabled() = LorenzUtils.inMiningIsland() && config + + private val timeOut = 10.0.seconds + + private var lastChatMessage = SimpleTimeMark.farPast() + private var lastGoblinSpawn = SimpleTimeMark.farPast() + private var lastGoblin: Mob? = null + + @SubscribeEvent + fun onChatEvent(event: LorenzChatEvent) { + if (!isEnabled()) return + if (!MiningNotifications.goldenGoblinSpawn.matches(event.message) && + !MiningNotifications.diamondGoblinSpawn.matches(event.message) + ) return + lastChatMessage = SimpleTimeMark.now() + handle() + } + + @SubscribeEvent + fun onMobEvent(event: MobEvent.Spawn.SkyblockMob) { + if (!isEnabled()) return + if (!goblinPattern.matches(event.mob.name)) return + lastGoblin = event.mob + lastGoblinSpawn = SimpleTimeMark.now() + handle() + } + + private fun handle() { + if (lastChatMessage.passedSince() > timeOut || lastGoblinSpawn.passedSince() > timeOut) return + lastChatMessage = SimpleTimeMark.farPast() + lastGoblinSpawn = SimpleTimeMark.farPast() + lastGoblin?.highlight(LorenzColor.GREEN.toColor()) + lastGoblin = null + } + +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/MiningNotifications.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/MiningNotifications.kt index 3115ac48a..acaa23ff5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/MiningNotifications.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/MiningNotifications.kt @@ -19,7 +19,7 @@ import kotlin.math.absoluteValue import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds -class MiningNotifications { +object MiningNotifications { enum class MiningNotificationList(val str: String, val notification: String) { MINESHAFT_SPAWN("§bGlacite Mineshaft", "§bMineshaft"), @@ -42,11 +42,11 @@ class MiningNotifications { "scrapdrop", "§6§lEXCAVATOR! §r§fYou found a §r§9Suspicious Scrap§r§f!" ) - private val goldenGoblinSpawn by patternGroup.pattern( + val goldenGoblinSpawn by patternGroup.pattern( "goblin.goldspawn", "§6A Golden Goblin has spawned!" ) - private val diamondGoblinSpawn by patternGroup.pattern( + val diamondGoblinSpawn by patternGroup.pattern( "goblin.diamondspawn", "§6A §r§bDiamond Goblin §r§6has spawned!" ) |