aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-05-08 11:41:20 +0200
committerGitHub <noreply@github.com>2024-05-08 11:41:20 +0200
commitec9d6cfc817dfa9fbbc2d0e3fdf58e096a7ab44b (patch)
treece06107f4719c8e0e45869e628a6070b3a2a89a8 /src
parent300542d272ae78b06c5ed56b1d59df7f5e3e72e4 (diff)
downloadskyhanni-ec9d6cfc817dfa9fbbc2d0e3fdf58e096a7ab44b.tar.gz
skyhanni-ec9d6cfc817dfa9fbbc2d0e3fdf58e096a7ab44b.tar.bz2
skyhanni-ec9d6cfc817dfa9fbbc2d0e3fdf58e096a7ab44b.zip
Fix rare chat crash (#1707)
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt
index bb2de0010..7d6d1a7ac 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PlayerAllChatEvent.kt
@@ -1,7 +1,10 @@
package at.hannibal2.skyhanni.data.hypixel.chat.event
import at.hannibal2.skyhanni.utils.ComponentSpan
+import net.minecraft.util.ChatComponentText
import net.minecraft.util.IChatComponent
+import net.minecraftforge.fml.common.eventhandler.ListenerList
+import org.jetbrains.annotations.ApiStatus
class PlayerAllChatEvent(
val levelComponent: ComponentSpan?,
@@ -16,4 +19,39 @@ class PlayerAllChatEvent(
val levelColor = levelComponent?.sampleStyleAtStart()?.color
val level by lazy { levelComponent?.getText()?.toInt() }
val isAGuest by lazy { privateIslandGuest != null }
+
+ companion object {
+ private val listenerList = ListenerList(AbstractChatEvent(
+ ComponentSpan.empty(),
+ ComponentSpan.empty(),
+ ChatComponentText(""),
+ "").listenerList)
+ }
+
+ /**
+ * This method is here to prevent FML from trying to add its own constructor. FML adds a public no args
+ * constructor to every Event class, which is used to determine the listener list using inheritance. This is done
+ * using class transformations, more specifically ASM. Sadly this class contains expressions which cause the class
+ * writer used by ASM to perform type unifications. Due to the way ASM is loaded these type unifications do not
+ * have access to some of the classes used in this class, causing a ClassNotFoundException. In order to prevent
+ * these unifications from happening we need to prevent FML from trying to generate this constructor, which we do
+ * by having our own setup function.
+ */
+ override fun setup() {
+ super.setup()
+ }
+
+ /**
+ * This method is required if [setup] is present.
+ */
+ @ApiStatus.Internal
+ constructor() : this(null, null, null, "",
+ ComponentSpan.empty(), ComponentSpan.empty(), ChatComponentText(""))
+
+ /**
+ * This method is required if [setup] is present.
+ */
+ override fun getListenerList(): ListenerList {
+ return PlayerAllChatEvent.listenerList
+ }
}