diff options
author | Brady <thatgravyboat@gmail.com> | 2024-06-08 06:48:29 -0230 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-08 11:18:29 +0200 |
commit | f9cafb766115d5342f7d7e1f8b9e3a56504f0273 (patch) | |
tree | cd325dbd48a4f8cde6f7e3c74e49cf0ebef99cad /src/main/java/at | |
parent | f677ce0fa1cab31feccab6eff2e5c35e2524d8a3 (diff) | |
download | skyhanni-f9cafb766115d5342f7d7e1f8b9e3a56504f0273.tar.gz skyhanni-f9cafb766115d5342f7d7e1f8b9e3a56504f0273.tar.bz2 skyhanni-f9cafb766115d5342f7d7e1f8b9e3a56504f0273.zip |
Backend: Packet Events (#2025)
Co-authored-by: Cal <cwolfson58@gmail.com>
Diffstat (limited to 'src/main/java/at')
30 files changed, 151 insertions, 181 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/BlockData.kt b/src/main/java/at/hannibal2/skyhanni/data/BlockData.kt index 3d767b505..0dcc1714e 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/BlockData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/BlockData.kt @@ -1,28 +1,23 @@ package at.hannibal2.skyhanni.data -import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.events.ServerBlockChangeEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import net.minecraft.network.play.server.S22PacketMultiBlockChange import net.minecraft.network.play.server.S23PacketBlockChange -import net.minecraftforge.fml.common.eventhandler.EventPriority -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @SkyHanniModule object BlockData { - @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) - fun onBlockReceivePacket(event: PacketEvent.ReceiveEvent) { - - @Suppress("USELESS_ELVIS") - val packet = event.packet ?: return - - if (packet is S23PacketBlockChange) { - val blockPos = packet.blockPosition ?: return - val blockState = packet.blockState ?: return + @HandleEvent(priority = HandleEvent.LOW, receiveCancelled = true) + fun onBlockReceivePacket(event: PacketReceivedEvent) { + if (event.packet is S23PacketBlockChange) { + val blockPos = event.packet.blockPosition ?: return + val blockState = event.packet.blockState ?: return ServerBlockChangeEvent(blockPos, blockState).postAndCatch() - } else if (packet is S22PacketMultiBlockChange) { - for (block in packet.changedBlocks) { + } else if (event.packet is S22PacketMultiBlockChange) { + for (block in event.packet.changedBlocks) { ServerBlockChangeEvent(block.pos, block.blockState).postAndCatch() } } diff --git a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt index a3991aa7c..fdfaaf06b 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt @@ -1,9 +1,10 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.MessageSendToServerEvent -import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketSentEvent import at.hannibal2.skyhanni.features.chat.ChatFilterGui import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.ChatUtils @@ -76,8 +77,8 @@ object ChatManager { val hoverExtraInfo: List<String> = listOf(), ) - @SubscribeEvent - fun onSendMessageToServerPacket(event: PacketEvent.SendEvent) { + @HandleEvent + fun onSendMessageToServerPacket(event: PacketSentEvent) { val packet = event.packet as? C01PacketChatMessage ?: return val message = packet.message diff --git a/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt b/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt index 318ac465a..c8e90fd27 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt @@ -1,12 +1,13 @@ package at.hannibal2.skyhanni.data +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.events.EntityHealthUpdateEvent import at.hannibal2.skyhanni.events.EntityMaxHealthUpdateEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent -import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.events.SecondPassedEvent import at.hannibal2.skyhanni.events.entity.EntityDisplayNameEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.EntityUtils import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth @@ -57,8 +58,8 @@ object EntityData { maxHealthMap.clear() } - @SubscribeEvent - fun onHealthUpdatePacket(event: PacketEvent.ReceiveEvent) { + @HandleEvent + fun onHealthUpdatePacket(event: PacketReceivedEvent) { val packet = event.packet if (packet !is S1CPacketEntityMetadata) return diff --git a/src/main/java/at/hannibal2/skyhanni/data/ItemClickData.kt b/src/main/java/at/hannibal2/skyhanni/data/ItemClickData.kt index a5f8091e4..e7fa75331 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ItemClickData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ItemClickData.kt @@ -1,9 +1,10 @@ package at.hannibal2.skyhanni.data +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.events.BlockClickEvent import at.hannibal2.skyhanni.events.EntityClickEvent import at.hannibal2.skyhanni.events.ItemClickEvent -import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketSentEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.toLorenzVec @@ -12,15 +13,14 @@ import net.minecraft.network.play.client.C02PacketUseEntity import net.minecraft.network.play.client.C07PacketPlayerDigging import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement import net.minecraft.network.play.client.C0APacketAnimation -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @SkyHanniModule object ItemClickData { - @SubscribeEvent - fun onItemClickSend(event: PacketEvent.SendEvent) { + @HandleEvent + fun onItemClickSend(event: PacketSentEvent) { val packet = event.packet - event.isCanceled = when { + val cancelled = when { packet is C08PacketPlayerBlockPlacement -> { if (packet.placedBlockDirection != 255) { val position = packet.position.toLorenzVec() @@ -58,6 +58,10 @@ object ItemClickData { return } } + + if (cancelled) { + event.cancel() + } } /* @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/data/MinecraftData.kt b/src/main/java/at/hannibal2/skyhanni/data/MinecraftData.kt index bf9980084..02768fc3d 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/MinecraftData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/MinecraftData.kt @@ -1,11 +1,12 @@ package at.hannibal2.skyhanni.data +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.events.ItemInHandChangeEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent -import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.events.PlaySoundEvent import at.hannibal2.skyhanni.events.ReceiveParticleEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.DelayedRun import at.hannibal2.skyhanni.utils.InventoryUtils @@ -23,10 +24,8 @@ import net.minecraftforge.fml.common.gameevent.TickEvent @SkyHanniModule object MinecraftData { - @SubscribeEvent(receiveCanceled = true) - fun onSoundPacket(event: PacketEvent.ReceiveEvent) { - if (!LorenzUtils.inSkyBlock) return - + @HandleEvent(receiveCancelled = true, onlyOnSkyblock = true) + fun onSoundPacket(event: PacketReceivedEvent) { val packet = event.packet if (packet !is S29PacketSoundEffect) return @@ -46,10 +45,8 @@ object MinecraftData { LorenzWorldChangeEvent().postAndCatch() } - @SubscribeEvent(receiveCanceled = true) - fun onParticlePacketReceive(event: PacketEvent.ReceiveEvent) { - if (!LorenzUtils.inSkyBlock) return - + @HandleEvent(receiveCancelled = true, onlyOnSkyblock = true) + fun onParticlePacketReceive(event: PacketReceivedEvent) { val packet = event.packet if (packet !is S2APacketParticles) return diff --git a/src/main/java/at/hannibal2/skyhanni/data/OtherInventoryData.kt b/src/main/java/at/hannibal2/skyhanni/data/OtherInventoryData.kt index 63b5c8c50..02f391019 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/OtherInventoryData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/OtherInventoryData.kt @@ -1,11 +1,12 @@ package at.hannibal2.skyhanni.data +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.InventoryUpdatedEvent import at.hannibal2.skyhanni.events.LorenzTickEvent -import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import net.minecraft.item.ItemStack import net.minecraft.network.play.server.S2DPacketOpenWindow @@ -38,8 +39,8 @@ object OtherInventoryData { } } - @SubscribeEvent - fun onInventoryDataReceiveEvent(event: PacketEvent.ReceiveEvent) { + @HandleEvent + fun onInventoryDataReceiveEvent(event: PacketReceivedEvent) { val packet = event.packet if (packet is S2EPacketCloseWindow) { diff --git a/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt b/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt index 900f87550..6a855a06b 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt @@ -1,13 +1,15 @@ package at.hannibal2.skyhanni.data +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.OwnInventoryItemUpdateEvent -import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.events.entity.ItemAddInInventoryEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketSentEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut import at.hannibal2.skyhanni.utils.DelayedRun @@ -23,7 +25,6 @@ import net.minecraft.client.Minecraft import net.minecraft.network.play.client.C0EPacketClickWindow import net.minecraft.network.play.server.S0DPacketCollectItem import net.minecraft.network.play.server.S2FPacketSetSlot -import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration import kotlin.time.Duration.Companion.milliseconds @@ -39,10 +40,8 @@ object OwnInventoryData { "§aMoved §r§e\\d* (?<name>.*)§r§a from your Sacks to your inventory." ) - @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) - fun onItemPickupReceivePacket(event: PacketEvent.ReceiveEvent) { - if (!LorenzUtils.inSkyBlock) return - + @HandleEvent(priority = HandleEvent.LOW, receiveCancelled = true, onlyOnSkyblock = true) + fun onItemPickupReceivePacket(event: PacketReceivedEvent) { val packet = event.packet if (packet is S2FPacketSetSlot || packet is S0DPacketCollectItem) { dirty = true @@ -59,9 +58,8 @@ object OwnInventoryData { } } - @SubscribeEvent - fun onClickEntity(event: PacketEvent.SendEvent) { - if (!LorenzUtils.inSkyBlock) return + @HandleEvent(onlyOnSkyblock = true) + fun onClickEntity(event: PacketSentEvent) { val packet = event.packet if (packet is C0EPacketClickWindow) { diff --git a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt index 7330317f2..a69210f6d 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt @@ -1,9 +1,10 @@ package at.hannibal2.skyhanni.data +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.events.LorenzTickEvent -import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.events.ScoreboardChangeEvent import at.hannibal2.skyhanni.events.ScoreboardRawChangeEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent import at.hannibal2.skyhanni.utils.RegexUtils.matches import net.minecraft.client.Minecraft import net.minecraft.network.play.server.S3CPacketUpdateScore @@ -71,8 +72,8 @@ class ScoreboardData { var dirty = false - @SubscribeEvent(receiveCanceled = true) - fun onPacketReceive(event: PacketEvent.ReceiveEvent) { + @HandleEvent(receiveCancelled = true) + fun onPacketReceive(event: PacketReceivedEvent) { if (event.packet is S3CPacketUpdateScore) { if (event.packet.objectiveName == "update") { dirty = true diff --git a/src/main/java/at/hannibal2/skyhanni/data/TitleData.kt b/src/main/java/at/hannibal2/skyhanni/data/TitleData.kt index 2a7da7902..f8ad4f652 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/TitleData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/TitleData.kt @@ -1,16 +1,16 @@ package at.hannibal2.skyhanni.data -import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.events.TitleReceivedEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import net.minecraft.network.play.server.S45PacketTitle -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @SkyHanniModule object TitleData { - @SubscribeEvent - fun onReceiveCurrentShield(event: PacketEvent.ReceiveEvent) { + @HandleEvent + fun onReceiveCurrentShield(event: PacketReceivedEvent) { val packet = event.packet if (packet !is S45PacketTitle) return diff --git a/src/main/java/at/hannibal2/skyhanni/data/mob/MobDetection.kt b/src/main/java/at/hannibal2/skyhanni/data/mob/MobDetection.kt index 233389444..a9714aeb4 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/mob/MobDetection.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/mob/MobDetection.kt @@ -11,8 +11,8 @@ import at.hannibal2.skyhanni.events.DebugDataCollectEvent import at.hannibal2.skyhanni.events.EntityHealthUpdateEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.MobEvent -import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.events.minecraft.ClientDisconnectEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.CollectionUtils.drainForEach import at.hannibal2.skyhanni.utils.CollectionUtils.drainTo @@ -312,8 +312,8 @@ object MobDetection { return true } - @SubscribeEvent - fun onEntitySpawnPacket(event: PacketEvent.ReceiveEvent) { + @HandleEvent + fun onEntitySpawnPacket(event: PacketReceivedEvent) { when (val packet = event.packet) { is S0FPacketSpawnMob -> addEntityUpdate(packet.entityID) is S0CPacketSpawnPlayer -> addEntityUpdate(packet.entityID) diff --git a/src/main/java/at/hannibal2/skyhanni/events/PacketEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/PacketEvent.kt deleted file mode 100644 index 961699a40..000000000 --- a/src/main/java/at/hannibal2/skyhanni/events/PacketEvent.kt +++ /dev/null @@ -1,47 +0,0 @@ -package at.hannibal2.skyhanni.events - -import net.minecraft.network.Packet -import net.minecraftforge.fml.common.eventhandler.Cancelable - -@Cancelable -/** - * Note: This event is async and may not be executed on the main minecraft thread. - */ -abstract class PacketEvent : LorenzEvent() { - - abstract val direction: Direction - abstract val packet: Packet<*> - - /** - * Note: This event is async and may not be executed on the main minecraft thread. - */ - data class ReceiveEvent(override val packet: Packet<*>) : PacketEvent() { - - override val direction = Direction.INBOUND - } - - /** - * Note: This event is async and may not be executed on the main minecraft thread. - */ - data class SendEvent(override val packet: Packet<*>) : PacketEvent() { - - override val direction = Direction.OUTBOUND - - fun findOriginatingModCall(skipSkyhanni: Boolean = false): StackTraceElement? { - val nonMinecraftOriginatingStack = Thread.currentThread().stackTrace - // Skip calls before the event is being called - .dropWhile { it.className != "net.minecraft.client.network.NetHandlerPlayClient" } - // Limit the remaining callstack until only the main entrypoint to hide the relauncher - .takeWhile { !it.className.endsWith(".Main") } - // Drop minecraft or skyhanni call frames - .dropWhile { it.className.startsWith("net.minecraft.") || (skipSkyhanni && it.className.startsWith("at.hannibal2.skyhanni.")) } - .firstOrNull() - return nonMinecraftOriginatingStack - } - } - - enum class Direction { - INBOUND, - OUTBOUND, - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/events/minecraft/packet/PacketReceivedEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/minecraft/packet/PacketReceivedEvent.kt new file mode 100644 index 000000000..bbb29acdd --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/minecraft/packet/PacketReceivedEvent.kt @@ -0,0 +1,6 @@ +package at.hannibal2.skyhanni.events.minecraft.packet + +import at.hannibal2.skyhanni.api.event.CancellableSkyHanniEvent +import net.minecraft.network.Packet + +class PacketReceivedEvent(val packet: Packet<*>) : CancellableSkyHanniEvent() diff --git a/src/main/java/at/hannibal2/skyhanni/events/minecraft/packet/PacketSentEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/minecraft/packet/PacketSentEvent.kt new file mode 100644 index 000000000..b01bd94fb --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/minecraft/packet/PacketSentEvent.kt @@ -0,0 +1,22 @@ +package at.hannibal2.skyhanni.events.minecraft.packet + +import at.hannibal2.skyhanni.api.event.CancellableSkyHanniEvent +import net.minecraft.client.network.NetHandlerPlayClient +import net.minecraft.network.Packet + +class PacketSentEvent(val network: NetHandlerPlayClient, val packet: Packet<*>) : CancellableSkyHanniEvent() { + fun findOriginatingModCall(skipSkyhanni: Boolean = false): StackTraceElement? { + val nonMinecraftOriginatingStack = Thread.currentThread().stackTrace + // Skip calls before the event is being called + .dropWhile { it.className != "net.minecraft.client.network.NetHandlerPlayClient" } + // Limit the remaining callstack until only the main entrypoint to hide the relauncher + .takeWhile { !it.className.endsWith(".Main") } + // Drop minecraft or skyhanni call frames + .dropWhile { + it.className.startsWith("net.minecraft.") || + (skipSkyhanni && it.className.startsWith("at.hannibal2.skyhanni.")) + } + .firstOrNull() + return nonMinecraftOriginatingStack + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/mobs/SpawnTimers.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/mobs/ArachneSpawnTimer.kt index 528ae4401..2fee0577e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/mobs/SpawnTimers.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/mobs/ArachneSpawnTimer.kt @@ -1,11 +1,12 @@ package at.hannibal2.skyhanni.features.combat.mobs import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent -import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland @@ -19,13 +20,12 @@ import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import at.hannibal2.skyhanni.utils.toLorenzVec import net.minecraft.network.play.server.S2APacketParticles import net.minecraft.util.EnumParticleTypes -import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds @SkyHanniModule -object SpawnTimers { +object ArachneSpawnTimer { private val config get() = SkyHanniMod.feature.combat.mobs @@ -80,9 +80,8 @@ object SpawnTimers { } } - // All this to detect "quickspawn" vs regular arachne spawn - @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) - fun onPacketReceive(event: PacketEvent.ReceiveEvent) { + @HandleEvent(onlyOnIsland = IslandType.SPIDER_DEN, priority = HandleEvent.LOW, receiveCancelled = true) + fun onPacketReceive(event: PacketReceivedEvent) { if (!saveNextTickParticles) return if (searchTime.passedSince() < 3.seconds) return diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonShadowAssassinNotification.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonShadowAssassinNotification.kt index f3378011e..d96e4559f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonShadowAssassinNotification.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonShadowAssassinNotification.kt @@ -1,21 +1,22 @@ package at.hannibal2.skyhanni.features.dungeon import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.api.event.HandleEvent +import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.TitleManager -import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent import at.hannibal2.skyhanni.mixins.transformers.AccessorWorldBoarderPacket import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.SoundUtils import net.minecraft.network.play.server.S44PacketWorldBorder -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.seconds @SkyHanniModule object DungeonShadowAssassinNotification { private val config get() = SkyHanniMod.feature.dungeon - @SubscribeEvent - fun onWorldBoarderChange(event: PacketEvent.ReceiveEvent) { + @HandleEvent(onlyOnIsland = IslandType.CATACOMBS) + fun onWorldBoarderChange(event: PacketReceivedEvent) { if (!isEnabled()) return if (DungeonAPI.dungeonFloor?.contains("3") == true && DungeonAPI.inBossRoom) return @@ -29,5 +30,5 @@ object DungeonShadowAssassinNotification { } } - private fun isEnabled() = DungeonAPI.inDungeon() && config.shadowAssassinJumpNotifier + private fun isEnabled() = config.shadowAssassinJumpNotifier } diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowParticleFinder.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowParticleFinder.kt index e017bd7dd..80d6ea0e0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowParticleFinder.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowParticleFinder.kt @@ -1,13 +1,15 @@ package at.hannibal2.skyhanni.features.event.diana import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.api.event.HandleEvent +import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.events.BlockClickEvent import at.hannibal2.skyhanni.events.BurrowDetectEvent import at.hannibal2.skyhanni.events.BurrowDugEvent import at.hannibal2.skyhanni.events.DebugDataCollectEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent -import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent import at.hannibal2.skyhanni.features.event.diana.DianaAPI.isDianaSpade import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.BlockUtils.getBlockAt @@ -18,7 +20,6 @@ import at.hannibal2.skyhanni.utils.TimeLimitedSet import at.hannibal2.skyhanni.utils.toLorenzVec import net.minecraft.init.Blocks import net.minecraft.network.play.server.S2APacketParticles -import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds @@ -57,8 +58,8 @@ object GriffinBurrowParticleFinder { } } - @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) - fun onPacketReceive(event: PacketEvent.ReceiveEvent) { + @HandleEvent(onlyOnIsland = IslandType.HUB, priority = HandleEvent.LOW, receiveCancelled = true) + fun onPacketReceive(event: PacketReceivedEvent) { if (!isEnabled()) return if (!config.burrowsSoopyGuess) return val packet = event.packet 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 268eacf0e..d9539fe15 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 @@ -2,13 +2,14 @@ package at.hannibal2.skyhanni.features.event.diana import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.api.event.HandleEvent +import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.events.EntityHealthUpdateEvent import at.hannibal2.skyhanni.events.LorenzChatEvent 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.events.minecraft.packet.PacketReceivedEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.CollectionUtils.editCopy @@ -29,7 +30,6 @@ 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.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.regex.Matcher import kotlin.time.Duration.Companion.seconds @@ -221,8 +221,8 @@ object InquisitorWaypointShare { HypixelCommands.partyChat("x: $x, y: $y, z: $z ") } - @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) - fun onFirstChatEvent(event: PacketEvent.ReceiveEvent) { + @HandleEvent(onlyOnIsland = IslandType.HUB, priority = HandleEvent.LOW, receiveCancelled = true) + fun onFirstChatEvent(event: PacketReceivedEvent) { if (!isEnabled()) return val packet = event.packet if (packet !is S02PacketChat) return diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt index 46d694131..d648acc29 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.PetAPI import at.hannibal2.skyhanni.data.ProfileStorageData @@ -12,8 +13,8 @@ import at.hannibal2.skyhanni.events.GardenToolChangeEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent -import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketSentEvent import at.hannibal2.skyhanni.features.event.hoppity.HoppityCollectionStats import at.hannibal2.skyhanni.features.garden.CropType.Companion.getCropType import at.hannibal2.skyhanni.features.garden.composter.ComposterOverlay @@ -88,9 +89,8 @@ object GardenAPI { "BINGHOE" ) - @SubscribeEvent - fun onSendPacket(event: PacketEvent.SendEvent) { - if (!inGarden()) return + @HandleEvent(onlyOnIsland = IslandType.GARDEN) + fun onSendPacket(event: PacketSentEvent) { if (event.packet !is C09PacketHeldItemChange) return checkItemInHand() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt index a4363a50e..5b9cbf220 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt @@ -3,13 +3,14 @@ package at.hannibal2.skyhanni.features.garden.pests import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.data.ClickType +import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.events.ItemClickEvent import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent -import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.events.ReceiveParticleEvent import at.hannibal2.skyhanni.events.garden.pests.PestUpdateEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled @@ -120,10 +121,10 @@ object PestParticleWaypoint { ++particles } - @SubscribeEvent - fun onFireWorkSpawn(event: PacketEvent.ReceiveEvent) { + @HandleEvent(onlyOnIsland = IslandType.GARDEN) + fun onFireWorkSpawn(event: PacketReceivedEvent) { if (event.packet !is S0EPacketSpawnObject) return - if (!GardenAPI.inGarden() || !config.hideParticles) return + if (!config.hideParticles) return val fireworkId = 76 if (event.packet.type == fireworkId) event.cancel() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/HighlightVisitorsOutsideOfGarden.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/HighlightVisitorsOutsideOfGarden.kt index 729f9d847..54adcebad 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/HighlightVisitorsOutsideOfGarden.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/HighlightVisitorsOutsideOfGarden.kt @@ -1,11 +1,12 @@ package at.hannibal2.skyhanni.features.garden.visitor +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.config.features.garden.visitor.VisitorConfig.VisitorBlockBehaviour import at.hannibal2.skyhanni.data.jsonobjects.repo.GardenJson import at.hannibal2.skyhanni.data.jsonobjects.repo.GardenVisitor -import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.events.SecondPassedEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketSentEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule @@ -89,8 +90,8 @@ object HighlightVisitorsOutsideOfGarden { private fun isVisitorNearby(location: LorenzVec) = EntityUtils.getEntitiesNearby<EntityLivingBase>(location, 2.0).any { isVisitor(it) } - @SubscribeEvent - fun onClickEntity(event: PacketEvent.SendEvent) { + @HandleEvent(onlyOnSkyblock = true) + fun onClickEntity(event: PacketSentEvent) { if (!shouldBlock) return val world = Minecraft.getMinecraft().theWorld ?: return val player = Minecraft.getMinecraft().thePlayer ?: return diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt index 577c014b4..31f8db263 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt @@ -8,12 +8,12 @@ import at.hannibal2.skyhanni.events.GuiKeyPressEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent -import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.events.ProfileJoinEvent import at.hannibal2.skyhanni.events.TabListUpdateEvent import at.hannibal2.skyhanni.events.garden.visitor.VisitorOpenEvent import at.hannibal2.skyhanni.events.garden.visitor.VisitorRenderEvent import at.hannibal2.skyhanni.events.item.ItemHoverEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketSentEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI.ACCEPT_SLOT import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI.INFO_SLOT @@ -55,8 +55,8 @@ object VisitorListener { } // TODO make event - @SubscribeEvent - fun onSendEvent(event: PacketEvent.SendEvent) { + @HandleEvent(onlyOnIsland = IslandType.GARDEN) + fun onSendEvent(event: PacketSentEvent) { val packet = event.packet if (packet !is C02PacketUseEntity) return diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/FixGhostEntities.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/FixGhostEntities.kt index 2fab8893a..0e891f444 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/FixGhostEntities.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/FixGhostEntities.kt @@ -1,9 +1,10 @@ package at.hannibal2.skyhanni.features.misc import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.events.CheckRenderEntityEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent -import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.MobUtils.isDefaultValue @@ -31,8 +32,8 @@ object FixGhostEntities { recentlySpawnedEntities = ArrayDeque() } - @SubscribeEvent - fun onReceiveCurrentShield(event: PacketEvent.ReceiveEvent) { + @HandleEvent(onlyOnSkyblock = true) + fun onReceiveCurrentShield(event: PacketReceivedEvent) { if (!isEnabled()) return val packet = event.packet @@ -69,5 +70,5 @@ object FixGhostEntities { } } - fun isEnabled() = LorenzUtils.inSkyBlock && config.fixGhostEntities + fun isEnabled() = config.fixGhostEntities } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt index 206215760..7f0775889 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt @@ -1,15 +1,16 @@ package at.hannibal2.skyhanni.features.misc import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.data.ProfileStorageData import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent -import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.events.ProfileJoinEvent import at.hannibal2.skyhanni.events.SecondPassedEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent import at.hannibal2.skyhanni.features.dungeon.DungeonAPI import at.hannibal2.skyhanni.features.rift.RiftAPI import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule @@ -28,7 +29,6 @@ import at.hannibal2.skyhanni.utils.TimeUtils.timerColor import at.hannibal2.skyhanni.utils.Timer import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.network.play.server.S47PacketPlayerListHeaderFooter -import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.hours import kotlin.time.Duration.Companion.minutes @@ -220,8 +220,9 @@ object NonGodPotEffectDisplay { } } - @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) - fun onPacketReceive(event: PacketEvent.ReceiveEvent) { + // TODO use TablistFooterUpdateEvent instead + @HandleEvent(onlyOnSkyblock = true, priority = HandleEvent.LOW, receiveCancelled = true) + fun onPacketReceive(event: PacketReceivedEvent) { val packet = event.packet if (!checkFooter) return if (packet is S47PacketPlayerListHeaderFooter) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/TpsCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/TpsCounter.kt index 1c37e92ff..0c6521e9c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/TpsCounter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/TpsCounter.kt @@ -1,16 +1,16 @@ package at.hannibal2.skyhanni.features.misc import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.config.enums.OutsideSbFeature import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent -import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.round import at.hannibal2.skyhanni.utils.RenderUtils.renderString -import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.concurrent.fixedRateTimer @@ -79,8 +79,8 @@ object TpsCounter { display = "" } - @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) - fun onPacketReceive(event: PacketEvent.ReceiveEvent) { + @HandleEvent(priority = HandleEvent.LOW, receiveCancelled = true) + fun onPacketReceive(event: PacketReceivedEvent) { if (!config.tpsDisplay) return hasPacketReceived = true } diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/NetHandlerPlayClientHook.kt b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/NetHandlerPlayClientHook.kt deleted file mode 100644 index b18d80613..000000000 --- a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/NetHandlerPlayClientHook.kt +++ /dev/null @@ -1,9 +0,0 @@ -package at.hannibal2.skyhanni.mixins.hooks - -import at.hannibal2.skyhanni.events.PacketEvent -import net.minecraft.network.Packet -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo - -fun onSendPacket(packet: Packet<*>, ci: CallbackInfo) { - if (PacketEvent.SendEvent(packet).postAndCatch()) ci.cancel() -}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/NetworkManagerHook.kt b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/NetworkManagerHook.kt deleted file mode 100644 index 71f6aaba9..000000000 --- a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/NetworkManagerHook.kt +++ /dev/null @@ -1,9 +0,0 @@ -package at.hannibal2.skyhanni.mixins.hooks - -import at.hannibal2.skyhanni.events.PacketEvent -import net.minecraft.network.Packet -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo - -fun onReceivePacket(packet: Packet<*>, ci: CallbackInfo) { - if (PacketEvent.ReceiveEvent(packet).postAndCatch()) ci.cancel() -} diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNetHandlerPlayClient.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNetHandlerPlayClient.java index 879e41061..b8bb676db 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNetHandlerPlayClient.java +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNetHandlerPlayClient.java @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.mixins.transformers; import at.hannibal2.skyhanni.events.EntityEquipmentChangeEvent; -import at.hannibal2.skyhanni.mixins.hooks.NetHandlerPlayClientHookKt; +import at.hannibal2.skyhanni.events.minecraft.packet.PacketSentEvent; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.entity.Entity; import net.minecraft.network.Packet; @@ -18,7 +18,10 @@ public abstract class MixinNetHandlerPlayClient implements INetHandlerPlayClient @Inject(method = "addToSendQueue", at = @At("HEAD"), cancellable = true) private void onSendPacket(Packet<?> packet, CallbackInfo ci) { - NetHandlerPlayClientHookKt.onSendPacket(packet, ci); + NetHandlerPlayClient handler = (NetHandlerPlayClient) (Object) this; + if (new PacketSentEvent(handler, packet).post()) { + ci.cancel(); + } } @Inject(method = "handleEntityEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setCurrentItemOrArmor(ILnet/minecraft/item/ItemStack;)V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD) diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNetworkManager.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNetworkManager.java index 11d7ed309..a00348021 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNetworkManager.java +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNetworkManager.java @@ -1,6 +1,6 @@ package at.hannibal2.skyhanni.mixins.transformers; -import at.hannibal2.skyhanni.mixins.hooks.NetworkManagerHookKt; +import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import net.minecraft.network.NetworkManager; @@ -15,8 +15,8 @@ public abstract class MixinNetworkManager extends SimpleChannelInboundHandler<Pa @Inject(method = "channelRead0*", at = @At("HEAD"), cancellable = true) private void onReceivePacket(ChannelHandlerContext context, Packet<?> packet, CallbackInfo ci) { - if (packet != null) { - NetworkManagerHookKt.onReceivePacket(packet, ci); + if (packet != null && new PacketReceivedEvent(packet).post()) { + ci.cancel(); } } } diff --git a/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt b/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt index 1e2829d49..033f71999 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt @@ -1,6 +1,8 @@ package at.hannibal2.skyhanni.test -import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.api.event.HandleEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketSentEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.EntityUtils @@ -32,8 +34,6 @@ import net.minecraft.network.play.server.S1DPacketEntityEffect import net.minecraft.network.play.server.S20PacketEntityProperties import net.minecraft.network.play.server.S28PacketEffect import net.minecraft.network.play.server.S2APacketParticles -import net.minecraftforge.fml.common.eventhandler.EventPriority -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @SkyHanniModule object PacketTest { @@ -70,8 +70,8 @@ object PacketTest { ChatUtils.chat("Packet test: $enabled") } - @SubscribeEvent - fun onSendPacket(event: PacketEvent.SendEvent) { + @HandleEvent + fun onSendPacket(event: PacketSentEvent) { if (!enabled) return val packet = event.packet @@ -91,8 +91,8 @@ object PacketTest { println("Send: $packetName") } - @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) - fun onPacketReceive(event: PacketEvent.ReceiveEvent) { + @HandleEvent(priority = HandleEvent.LOW, receiveCancelled = true) + fun onPacketReceive(event: PacketReceivedEvent) { if (!enabled) return val packet = event.packet packet.print() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt b/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt index 475a53fb5..083772935 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt @@ -1,11 +1,12 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.data.model.TabWidget import at.hannibal2.skyhanni.events.LorenzTickEvent -import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.events.TabListUpdateEvent import at.hannibal2.skyhanni.events.TablistFooterUpdateEvent +import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent import at.hannibal2.skyhanni.mixins.hooks.tabListGuard import at.hannibal2.skyhanni.mixins.transformers.AccessorGuiPlayerTabOverlay import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule @@ -117,8 +118,8 @@ object TabListData { var dirty = false - @SubscribeEvent(receiveCanceled = true) - fun onPacketReceive(event: PacketEvent.ReceiveEvent) { + @HandleEvent(receiveCancelled = true) + fun onPacketReceive(event: PacketReceivedEvent) { if (event.packet is S38PacketPlayerListItem) { dirty = true } |