aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/test/hotswap
diff options
context:
space:
mode:
authorThunderblade73 <85900443+Thunderblade73@users.noreply.github.com>2024-02-10 00:24:52 +0100
committerGitHub <noreply@github.com>2024-02-10 00:24:52 +0100
commit4559e5ff05e19817a21ae49f1c0d8a97d273f6a1 (patch)
treee72dac91d07fc84bea80548c89e13276caa68b81 /src/main/java/at/hannibal2/skyhanni/test/hotswap
parentd3a7cc4ab970b457b7950489da781539e45e0dce (diff)
downloadskyhanni-4559e5ff05e19817a21ae49f1c0d8a97d273f6a1.tar.gz
skyhanni-4559e5ff05e19817a21ae49f1c0d8a97d273f6a1.tar.bz2
skyhanni-4559e5ff05e19817a21ae49f1c0d8a97d273f6a1.zip
Splitting many utils functions from LorenzUtils up into other classes: ChatUtils, CollectionUtils, ConditionalUtils. And code cleanup #978
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/test/hotswap')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupport.kt1
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupportHandle.kt1
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupportImpl.kt15
3 files changed, 10 insertions, 7 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupport.kt b/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupport.kt
index 87acab62d..447a6f5aa 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupport.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupport.kt
@@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.test.hotswap
import java.util.function.Supplier
object HotswapSupport {
+
private val isForgeSidePresent =
runCatching { Class.forName("moe.nea.hotswapagentforge.forge.HotswapEvent") }.isSuccess
private val obj = if (isForgeSidePresent) {
diff --git a/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupportHandle.kt b/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupportHandle.kt
index c006753a0..e0bb8470f 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupportHandle.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupportHandle.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.test.hotswap
interface HotswapSupportHandle {
+
fun load()
fun isLoaded(): Boolean
}
diff --git a/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupportImpl.kt b/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupportImpl.kt
index 044f5c817..45b81a1ab 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupportImpl.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/hotswap/HotswapSupportImpl.kt
@@ -1,9 +1,9 @@
package at.hannibal2.skyhanni.test.hotswap
import at.hannibal2.skyhanni.SkyHanniMod
-import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.LorenzUtils.makeAccessible
-import at.hannibal2.skyhanni.utils.LorenzUtils.removeFinal
+import at.hannibal2.skyhanni.utils.ChatUtils
+import at.hannibal2.skyhanni.utils.ReflectionUtils.makeAccessible
+import at.hannibal2.skyhanni.utils.ReflectionUtils.removeFinal
import moe.nea.hotswapagentforge.forge.ClassDefinitionEvent
import moe.nea.hotswapagentforge.forge.HotswapEvent
import moe.nea.hotswapagentforge.forge.HotswapFinishedEvent
@@ -12,6 +12,7 @@ import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class HotswapSupportImpl : HotswapSupportHandle {
+
override fun load() {
MinecraftForge.EVENT_BUS.register(this)
println("Hotswap Client in Skyhanni loaded")
@@ -22,7 +23,7 @@ class HotswapSupportImpl : HotswapSupportHandle {
val instance = SkyHanniMod.modules.find { it.javaClass.name == event.fullyQualifiedName } ?: return
val primaryConstructor = runCatching { instance.javaClass.getDeclaredConstructor() }.getOrNull()
Minecraft.getMinecraft().addScheduledTask {
- LorenzUtils.chat("Refreshing event subscriptions for module $instance!")
+ ChatUtils.chat("Refreshing event subscriptions for module $instance!")
MinecraftForge.EVENT_BUS.unregister(instance)
if (primaryConstructor == null) {
MinecraftForge.EVENT_BUS.register(instance)
@@ -30,13 +31,13 @@ class HotswapSupportImpl : HotswapSupportHandle {
SkyHanniMod.modules.remove(instance)
primaryConstructor.isAccessible = true
val newInstance = primaryConstructor.newInstance()
- LorenzUtils.chat("Reconstructing $instance -> $newInstance!")
+ ChatUtils.chat("Reconstructing $instance -> $newInstance!")
val instanceField = runCatching { instance.javaClass.getDeclaredField("INSTANCE") }.getOrNull()
?.takeIf { it.type == instance.javaClass }
?.makeAccessible()
?.removeFinal()
if (instanceField != null) {
- LorenzUtils.chat("Reinjected static instance $newInstance!")
+ ChatUtils.chat("Reinjected static instance $newInstance!")
instanceField.set(null, newInstance)
}
SkyHanniMod.modules.add(newInstance)
@@ -47,7 +48,7 @@ class HotswapSupportImpl : HotswapSupportHandle {
@SubscribeEvent
fun onHotswapDetected(event: HotswapFinishedEvent) {
- LorenzUtils.chat("Hotswap finished!")
+ ChatUtils.chat("Hotswap finished!")
}
override fun isLoaded(): Boolean {