diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-05-31 01:13:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-31 01:13:54 +0200 |
commit | 23ce43b83c5707f07952327a2fcc21fe01e8db46 (patch) | |
tree | bf7911fd85c270d7d29e58ee9d85d54449843bc1 /src/main/java/at/hannibal2/skyhanni | |
parent | 3b8c54f0928beffeb64db6879e47b145b28854e0 (diff) | |
download | skyhanni-23ce43b83c5707f07952327a2fcc21fe01e8db46.tar.gz skyhanni-23ce43b83c5707f07952327a2fcc21fe01e8db46.tar.bz2 skyhanni-23ce43b83c5707f07952327a2fcc21fe01e8db46.zip |
Fix: inquisitor detection (#1949)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
5 files changed, 68 insertions, 77 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index d068150fa..311c65807 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -135,6 +135,7 @@ import at.hannibal2.skyhanni.features.dungeon.TerracottaPhase import at.hannibal2.skyhanni.features.event.UniqueGiftingOpportunitiesFeatures import at.hannibal2.skyhanni.features.event.diana.AllBurrowsList import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper +import at.hannibal2.skyhanni.features.event.diana.DianaAPI import at.hannibal2.skyhanni.features.event.diana.DianaFixChat import at.hannibal2.skyhanni.features.event.diana.DianaProfitTracker import at.hannibal2.skyhanni.features.event.diana.GriffinBurrowHelper @@ -614,6 +615,7 @@ class SkyHanniMod { loadModule(FossilExcavatorAPI) loadModule(ChocolateFactoryAPI) loadModule(RenderableTooltips) + loadModule(DianaAPI) // features loadModule(BazaarOrderHelper()) diff --git a/src/main/java/at/hannibal2/skyhanni/events/diana/InquisitorFoundEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/diana/InquisitorFoundEvent.kt new file mode 100644 index 000000000..9978c6f3c --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/diana/InquisitorFoundEvent.kt @@ -0,0 +1,6 @@ +package at.hannibal2.skyhanni.events.diana + +import at.hannibal2.skyhanni.events.LorenzEvent +import net.minecraft.client.entity.EntityOtherPlayerMP + +class InquisitorFoundEvent(val inquisitorEntity: EntityOtherPlayerMP) : LorenzEvent() diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaAPI.kt index 747c0d02a..f49376e37 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaAPI.kt @@ -3,11 +3,16 @@ package at.hannibal2.skyhanni.features.event.diana import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.Perk import at.hannibal2.skyhanni.data.PetAPI +import at.hannibal2.skyhanni.events.diana.InquisitorFoundEvent import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import net.minecraft.client.entity.EntityOtherPlayerMP import net.minecraft.item.ItemStack +import net.minecraftforge.event.entity.EntityJoinWorldEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object DianaAPI { @@ -25,4 +30,14 @@ object DianaAPI { val ItemStack.isDianaSpade get() = getInternalName() == spade private fun hasSpadeInInventory() = InventoryUtils.getItemsInOwnInventory().any { it.isDianaSpade } + + @SubscribeEvent + fun onJoinWorld(event: EntityJoinWorldEvent) { + if (!LorenzUtils.inSkyBlock) return + + val entity = event.entity + if (entity is EntityOtherPlayerMP && entity.name == "Minos Inquisitor") { + InquisitorFoundEvent(entity).postAndCatch() + } + } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/HighlightInquisitors.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/HighlightInquisitors.kt index dd48e28c5..41d69d63e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/HighlightInquisitors.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/HighlightInquisitors.kt @@ -1,11 +1,9 @@ package at.hannibal2.skyhanni.features.event.diana import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.diana.InquisitorFoundEvent import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper import at.hannibal2.skyhanni.utils.ColorUtils.toChromaColorInt -import at.hannibal2.skyhanni.utils.LorenzUtils -import net.minecraft.entity.player.EntityPlayer -import net.minecraftforge.event.entity.EntityJoinWorldEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class HighlightInquisitors { @@ -13,15 +11,12 @@ class HighlightInquisitors { private val config get() = SkyHanniMod.feature.event.diana @SubscribeEvent - fun onJoinWorld(event: EntityJoinWorldEvent) { - if (!LorenzUtils.inSkyBlock) return + fun onInquisitorFound(event: InquisitorFoundEvent) { if (!config.highlightInquisitors) return - val entity = event.entity + val inquisitor = event.inquisitorEntity - if (entity is EntityPlayer && entity.name == "Minos Inquisitor") { - val color = config.color.toChromaColorInt() - RenderLivingEntityHelper.setEntityColorWithNoHurtTime(entity, color) { config.highlightInquisitors } - } + val color = config.color.toChromaColorInt() + RenderLivingEntityHelper.setEntityColorWithNoHurtTime(inquisitor, color) { config.highlightInquisitors } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt index c884bd818..205fc41f2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt @@ -7,29 +7,29 @@ import at.hannibal2.skyhanni.events.LorenzKeyPressEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.events.SecondPassedEvent +import at.hannibal2.skyhanni.events.diana.InquisitorFoundEvent import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.CollectionUtils.editCopy import at.hannibal2.skyhanni.utils.EntityUtils import at.hannibal2.skyhanni.utils.HypixelCommands import at.hannibal2.skyhanni.utils.KeyboardManager -import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.RegexUtils.hasGroup import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher +import at.hannibal2.skyhanni.utils.RegexUtils.matches import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SoundUtils import at.hannibal2.skyhanni.utils.StringUtils.cleanPlayerName +import at.hannibal2.skyhanni.utils.StringUtils.stripHypixelMessage import at.hannibal2.skyhanni.utils.getLorenzVec import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.client.Minecraft import net.minecraft.client.entity.EntityOtherPlayerMP import net.minecraft.network.play.server.S02PacketChat -import net.minecraftforge.event.entity.EntityJoinWorldEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.regex.Matcher -import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds object InquisitorWaypointShare { @@ -59,16 +59,18 @@ object InquisitorWaypointShare { "(?<party>§9Party §8> )?(?<playerName>.*)§f: §rInquisitor dead!" ) - private var inquisitorTime = SimpleTimeMark.farPast() - private var testTime = SimpleTimeMark.farPast() - private var lastInquisitorMessage = "" + /** + * REGEX-TEST: §c§lUh oh! §r§eYou dug out a §r§2Minos Inquisitor§r§e! + */ + private val inquisitorFoundChatPattern by patternGroup.pattern( + "inquisitor.dug", + ".* §r§eYou dug out a §r§2Minos Inquisitor§r§e!" + ) + private var inquisitor = -1 private var lastInquisitor = -1 private var lastShareTime = SimpleTimeMark.farPast() private var inquisitorsNearby = emptyList<EntityOtherPlayerMP>() - private val soonRange = (-500).milliseconds..1.5.seconds - - private val logger = LorenzLogger("diana/waypoints") var waypoints = mapOf<String, SharedInquisitor>() @@ -103,68 +105,44 @@ object InquisitorWaypointShare { inquisitorsNearby = emptyList() } + val inquisitorTime = mutableListOf<SimpleTimeMark>() + @SubscribeEvent - fun onChat(event: LorenzChatEvent) { - if (!isEnabled()) return - val message = event.message - // TODO repo pattern - if (message.contains("§eYou dug out")) { - testTime = SimpleTimeMark.now() - lastInquisitorMessage = message + fun onInquisitorFound(event: InquisitorFoundEvent) { + val inquisitor = event.inquisitorEntity + inquisitorsNearby = inquisitorsNearby.editCopy { add(inquisitor) } + GriffinBurrowHelper.update() - val passedSince = inquisitorTime.passedSince() + lastInquisitor = inquisitor.entityId + checkInquisFound() + } - if (passedSince < 10.seconds) { - logger.log(" ") - logger.log("reverse!") - logger.log("diff: $passedSince") - } - if (passedSince in soonRange) return - foundInquisitor(lastInquisitor) - } + // We do not know if the chat message or the entity spawn happens first. + // We only want to run foundInquisitor when both happens in under 1.5 seconds + private fun checkInquisFound() { + inquisitorTime.add(SimpleTimeMark.now()) - // TODO: Change the check to only one line once we have a confirmed inquis message line - if (message.contains("§r§eYou dug out ") && message.contains("Inquis")) { - inquisitorTime = SimpleTimeMark.now() - logger.log("found Inquisitor") + val lastTwo = inquisitorTime.takeLast(2) + if (lastTwo.size != 2) return + + if (lastTwo.all { it.passedSince() < 1.5.seconds }) { + inquisitorTime.clear() + foundInquisitor(lastInquisitor) } } @SubscribeEvent - fun onJoinWorld(event: EntityJoinWorldEvent) { + fun onChat(event: LorenzChatEvent) { if (!isEnabled()) return - val entity = event.entity - if (entity !is EntityOtherPlayerMP) return - val name = entity.name - if (test) { - if (name != "Minos Inquisitor" && name != "Minotaur " && name != "Minos Champion") return - } else { - if (name != "Minos Inquisitor") return - } - logger.log("FOUND: $name") - - inquisitorsNearby = inquisitorsNearby.editCopy { add(entity) } - GriffinBurrowHelper.update() + val message = event.message - val passedSince = inquisitorTime.passedSince() - inquisitorTime = SimpleTimeMark.now() - lastInquisitor = entity.entityId - - logger.log("diff: $passedSince") - if (passedSince in soonRange) { - val testDiff = testTime.passedSince() - if (testDiff in soonRange) { - logger.log("testDiff: $passedSince") - return - } else { - logger.log("wrong Inquisitor message!") - } + if (inquisitorFoundChatPattern.matches(message)) { + checkInquisFound() } - foundInquisitor(entity.entityId) } private fun foundInquisitor(inquisId: Int) { - logger.log("lastInquisitorMessage: '$lastInquisitorMessage'") + lastShareTime = SimpleTimeMark.farPast() inquisitor = inquisId if (config.instantShare) { @@ -205,20 +183,17 @@ object InquisitorWaypointShare { private fun sendDeath() { if (!isEnabled()) return - if (lastShareTime.passedSince() > 5.seconds) return - lastShareTime = SimpleTimeMark.now() + if (lastShareTime.passedSince() < 5.seconds) return - if (inquisitor == -1) { - logger.log("Inquisitor is already null!") - return - } + // already dead + if (inquisitor == -1) return inquisitor = -1 HypixelCommands.partyChat("Inquisitor dead!") } fun sendInquisitor() { if (!isEnabled()) return - if (lastShareTime.passedSince() > 5.seconds) return + if (lastShareTime.passedSince() < 5.seconds) return lastShareTime = SimpleTimeMark.now() if (inquisitor == -1) { @@ -250,7 +225,7 @@ object InquisitorWaypointShare { if (packet !is S02PacketChat) return val messageComponent = packet.chatComponent - val message = LorenzUtils.stripVanillaMessage(messageComponent.formattedText) + val message = messageComponent.formattedText.stripHypixelMessage() if (packet.type.toInt() != 0) return partyInquisitorCheckerPattern.matchMatcher(message) { @@ -268,10 +243,8 @@ object InquisitorWaypointShare { if (block()) return val rawName = group("playerName") val name = rawName.cleanPlayerName() - val displayName = rawName.cleanPlayerName(displayName = true) waypoints = waypoints.editCopy { remove(name) } GriffinBurrowHelper.update() - logger.log("Inquisitor died from '$displayName'") } } |