From a20da5a79b5b05839862c8e8fd165b18368729c1 Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Sat, 1 Jun 2024 20:47:08 +1000 Subject: Backend: Auto load annotation (#1904) Co-authored-by: Brady --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 5d1bb52ad..6fd2154e8 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -14,7 +14,6 @@ import at.hannibal2.skyhanni.data.ActionBarStatsData import at.hannibal2.skyhanni.data.BitsAPI import at.hannibal2.skyhanni.data.BlockData import at.hannibal2.skyhanni.data.BossbarData -import at.hannibal2.skyhanni.data.ChatManager import at.hannibal2.skyhanni.data.CropAccessoryData import at.hannibal2.skyhanni.data.EntityData import at.hannibal2.skyhanni.data.EntityMovementData @@ -453,6 +452,7 @@ import at.hannibal2.skyhanni.features.stranded.HighlightPlaceableNpcs import at.hannibal2.skyhanni.features.summonings.SummoningMobManager import at.hannibal2.skyhanni.features.summonings.SummoningSoulsName import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper +import at.hannibal2.skyhanni.skyhannimodule.LoadedModules import at.hannibal2.skyhanni.test.HighlightMissingRepoItems import at.hannibal2.skyhanni.test.PacketTest import at.hannibal2.skyhanni.test.ParkourWaypointSaver @@ -512,9 +512,10 @@ class SkyHanniMod { HotswapSupport.load() - // data loadModule(this) - loadModule(ChatManager) + LoadedModules.modules.forEach { loadModule(it) } + + // data loadModule(PlayerChatManager()) loadModule(PlayerNameFormatter()) loadModule(HypixelData()) @@ -1007,9 +1008,13 @@ class SkyHanniMod { } catch (e: Exception) { Exception("Error reading repo data", e).printStackTrace() } + loadedClasses.clear() } + private val loadedClasses = mutableSetOf() + fun loadModule(obj: Any) { + if (!loadedClasses.add(obj.javaClass.name)) throw IllegalStateException("Module ${obj.javaClass.name} is already loaded") modules.add(obj) MinecraftForge.EVENT_BUS.register(obj) } -- cgit