aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-05-18 19:51:12 +0200
committerGitHub <noreply@github.com>2024-05-18 19:51:12 +0200
commit6ee6072c64959811a389bafc23142663b06b7dce (patch)
treeadd871c71ff0f35826d9998f783ba48c310298d3 /src/main/java/at/hannibal2/skyhanni
parentf0aa9df4c216a0c9dedbd6bf186d17e3aa1717ed (diff)
downloadskyhanni-6ee6072c64959811a389bafc23142663b06b7dce.tar.gz
skyhanni-6ee6072c64959811a389bafc23142663b06b7dce.tar.bz2
skyhanni-6ee6072c64959811a389bafc23142663b06b7dce.zip
Fix: Reworked slayer warning (#1814)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt14
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerQuestWarning.kt165
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerType.kt4
4 files changed, 90 insertions, 99 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
index 2995a38e2..4c021929b 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
@@ -6,7 +6,8 @@ import at.hannibal2.skyhanni.events.ScoreboardChangeEvent
import at.hannibal2.skyhanni.events.ScoreboardRawChangeEvent
import at.hannibal2.skyhanni.utils.StringUtils.matches
import net.minecraft.client.Minecraft
-import net.minecraft.network.play.server.S3BPacketScoreboardObjective
+import net.minecraft.network.play.server.S3CPacketUpdateScore
+import net.minecraft.network.play.server.S3EPacketTeams
import net.minecraft.scoreboard.Score
import net.minecraft.scoreboard.ScorePlayerTeam
import net.minecraftforge.fml.common.eventhandler.EventPriority
@@ -72,8 +73,15 @@ class ScoreboardData {
@SubscribeEvent(receiveCanceled = true)
fun onPacketReceive(event: PacketEvent.ReceiveEvent) {
- if (event.packet is S3BPacketScoreboardObjective) {
- dirty = true
+ if (event.packet is S3CPacketUpdateScore) {
+ if (event.packet.objectiveName == "update") {
+ dirty = true
+ }
+ }
+ if (event.packet is S3EPacketTeams) {
+ if (event.packet.name.startsWith("team_")) {
+ dirty = true
+ }
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt
index 5f92da7ae..ec62adda0 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt
@@ -98,10 +98,8 @@ object SlayerAPI {
private fun grabActiveSlayer(): SlayerType? {
for (line in ScoreboardData.sidebarLinesFormatted) {
- for (type in SlayerType.entries) {
- if (line.contains(type.displayName)) {
- return type
- }
+ SlayerType.getByName(line)?.let {
+ return it
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerQuestWarning.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerQuestWarning.kt
index a90d0eb9f..95ba80060 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerQuestWarning.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerQuestWarning.kt
@@ -1,130 +1,91 @@
package at.hannibal2.skyhanni.features.slayer
import at.hannibal2.skyhanni.SkyHanniMod
-import at.hannibal2.skyhanni.data.ScoreboardData
+import at.hannibal2.skyhanni.data.ClickType
import at.hannibal2.skyhanni.data.SlayerAPI
import at.hannibal2.skyhanni.events.EntityHealthUpdateEvent
-import at.hannibal2.skyhanni.events.LorenzChatEvent
-import at.hannibal2.skyhanni.events.LorenzTickEvent
-import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
+import at.hannibal2.skyhanni.events.ItemClickEvent
+import at.hannibal2.skyhanni.events.ScoreboardChangeEvent
+import at.hannibal2.skyhanni.features.event.diana.DianaAPI
+import at.hannibal2.skyhanni.features.rift.RiftAPI
import at.hannibal2.skyhanni.utils.ChatUtils
+import at.hannibal2.skyhanni.utils.CollectionUtils.nextAfter
+import at.hannibal2.skyhanni.utils.DelayedRun
+import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull
import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
+import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.getLorenzVec
-import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.entity.EntityLivingBase
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
class SlayerQuestWarning {
private val config get() = SkyHanniMod.feature.slayer
- private val talkToMaddoxPattern by RepoPattern.pattern(
- "slayer.questwarning.talkto",
- " {3}§r§5§l» §r§7Talk to Maddox to claim your .+ Slayer XP!"
- )
+ private var lastWeaponUse = SimpleTimeMark.farPast()
+ private val voidItem = "ASPECT_OF_THE_VOID".asInternalName()
+ private val endItem = "ASPECT_OF_THE_END".asInternalName()
- private var needSlayerQuest = false
- private var lastWarning = 0L
- private var currentReason = ""
- private var dirtySidebar = false
- private var hasAutoSlayer = false
+ private val outsideRiftData = SlayerData()
+ private val insideRiftData = SlayerData()
- // TODO add check if player has clicked on an item, before mobs around you gets damage
+ class SlayerData {
+ var currentSlayerState: String? = null
+ var lastSlayerType: SlayerType? = null
+ }
@SubscribeEvent
- fun onChat(event: LorenzChatEvent) {
- if (!(LorenzUtils.inSkyBlock)) return
+ fun onScoreboardChange(event: ScoreboardChangeEvent) {
+ val slayerType = event.newList.nextAfter("Slayer Quest")
+ val slayerProgress = event.newList.nextAfter("Slayer Quest", skip = 2) ?: "no slayer"
+ val new = slayerProgress.removeColor()
+ val slayerData = getSlayerData()
- val message = event.message
+ if (slayerData.currentSlayerState == new) return
- // died
- if (message == " §r§c§lSLAYER QUEST FAILED!") {
- needNewQuest("The old slayer quest has failed!")
- }
- if (message == " §r§5§lSLAYER QUEST STARTED!") {
- needSlayerQuest = false
- hasAutoSlayer = true
- dirtySidebar = true
+ slayerData.currentSlayerState?.let {
+ change(it, new)
}
-
- // no auto slayer
- talkToMaddoxPattern.matchMatcher(message) {
- needNewQuest("You have no Auto-Slayer active!")
+ slayerData.currentSlayerState = new
+ slayerType?.let {
+ slayerData.lastSlayerType = SlayerType.getByName(it)
}
- if (message == " §r§a§lSLAYER QUEST COMPLETE!") {
- needSlayerQuest = false
- }
-
- if (message == "§aYour Slayer Quest has been cancelled!") {
- needSlayerQuest = false
- }
-
- // TODO auto slayer disabled bc of no more money in bank or purse
}
- private fun needNewQuest(reason: String) {
- currentReason = reason
- needSlayerQuest = true
- }
-
- @SubscribeEvent
- fun onTick(event: LorenzTickEvent) {
- if (!(LorenzUtils.inSkyBlock)) return
+ private fun getSlayerData() = if (RiftAPI.inRift()) outsideRiftData else insideRiftData
- if (dirtySidebar && event.repeatSeconds(3)) {
- checkSidebar()
- }
- }
-
- private fun checkSidebar() {
- var loaded = false
-
- var slayerQuest = false
- var bossSlain = false
- var slayBoss = false
- var nextIsType = false
- for (line in ScoreboardData.sidebarLinesFormatted) {
- if (nextIsType) {
- nextIsType = false
- }
- if (line == "Slayer Quest") {
- slayerQuest = true
- nextIsType = true
+ private fun change(old: String, new: String) {
+ if (new.contains("Combat")) {
+ if (!old.contains("Combat")) {
+ needSlayerQuest = false
}
- if (line == "§aBoss slain!") {
- bossSlain = true
- }
- if (line == "§eSlay the boss!") {
- slayBoss = true
- }
- if (line == "§ewww.hypixel.net" || line == "§ewww.alpha.hypixel.net") {
- loaded = true
+ }
+ if (new == "no slayer") {
+ if (old == "Slay the boss!") {
+ needNewQuest("The old slayer quest has failed!")
}
}
-
- if (loaded) {
- dirtySidebar = false
- if (slayerQuest && !needSlayerQuest) {
- if (bossSlain) {
- if (!hasAutoSlayer) {
- needNewQuest("You have no Auto-Slayer active!")
- hasAutoSlayer = false
- }
- } else if (slayBoss) {
- needNewQuest("You probably switched the server during an active boss and now hypixel doesn't know what to do.")
+ if (new == "Boss slain!") {
+ DelayedRun.runDelayed(2.seconds) {
+ if (getSlayerData().currentSlayerState == "Boss slain!") {
+ needNewQuest("You have no Auto-Slayer active!")
}
}
}
}
- @SubscribeEvent
- fun onWorldChange(event: LorenzWorldChangeEvent) {
- if (!needSlayerQuest) {
- dirtySidebar = true
- }
+ private var needSlayerQuest = false
+ private var lastWarning = 0L
+ private var currentReason = ""
+
+ private fun needNewQuest(reason: String) {
+ currentReason = reason
+ needSlayerQuest = true
}
private fun tryWarn() {
@@ -136,6 +97,10 @@ class SlayerQuestWarning {
if (!config.questWarning) return
if (lastWarning + 10_000 > System.currentTimeMillis()) return
+ if (DianaAPI.isDoingDiana()) return
+ // prevent warnings when mobs are hit by other players
+ if (lastWeaponUse.passedSince() > 500.milliseconds) return
+
lastWarning = System.currentTimeMillis()
ChatUtils.chat(chatMessage)
@@ -170,7 +135,23 @@ class SlayerQuestWarning {
)
}
}
+ return (getSlayerData().lastSlayerType == slayerType) && slayerType.clazz.isInstance(entity)
+ }
- return slayerType.clazz.isInstance(entity)
+ @SubscribeEvent
+ fun onItemClick(event: ItemClickEvent) {
+ val internalName = event.itemInHand?.getInternalNameOrNull()
+
+ if (event.clickType == ClickType.RIGHT_CLICK) {
+ if (internalName == voidItem || internalName == endItem) {
+ // ignore harmless teleportation
+ return
+ }
+ if (internalName == null) {
+ // ignore harmless right click
+ return
+ }
+ }
+ lastWeaponUse = SimpleTimeMark.now()
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerType.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerType.kt
index c7a1f2fde..0fc237b0d 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerType.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerType.kt
@@ -14,4 +14,8 @@ enum class SlayerType(val displayName: String, val rngName: String, val clazz: C
INFERNO("Inferno Demonlord", "inferno", EntityBlaze::class.java),
VAMPIRE("Riftstalker Bloodfiend", "vampire", EntityZombie::class.java)
;
+
+ companion object {
+ fun getByName(name: String): SlayerType? = entries.firstOrNull {name.contains(it.displayName)}
+ }
}