aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/events
diff options
context:
space:
mode:
authorBrady <thatgravyboat@gmail.com>2024-06-08 06:48:29 -0230
committerGitHub <noreply@github.com>2024-06-08 11:18:29 +0200
commitf9cafb766115d5342f7d7e1f8b9e3a56504f0273 (patch)
treecd325dbd48a4f8cde6f7e3c74e49cf0ebef99cad /src/main/java/at/hannibal2/skyhanni/events
parentf677ce0fa1cab31feccab6eff2e5c35e2524d8a3 (diff)
downloadskyhanni-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/hannibal2/skyhanni/events')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/PacketEvent.kt47
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/minecraft/packet/PacketReceivedEvent.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/minecraft/packet/PacketSentEvent.kt22
3 files changed, 28 insertions, 47 deletions
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
+ }
+}