diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt index 3fbf41541..65c252bae 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt @@ -1,15 +1,18 @@ package at.hannibal2.skyhanni.config import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.core.config.Position import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.jsonobjects.local.FriendsJson import at.hannibal2.skyhanni.data.jsonobjects.local.JacobContestsJson import at.hannibal2.skyhanni.data.jsonobjects.local.KnownFeaturesJson import at.hannibal2.skyhanni.data.jsonobjects.local.VisualWordsJson import at.hannibal2.skyhanni.data.jsonobjects.other.HypixelApiTrophyFish +import at.hannibal2.skyhanni.events.LorenzEvent import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity import at.hannibal2.skyhanni.features.misc.update.UpdateManager import at.hannibal2.skyhanni.utils.FeatureTogglesByDefaultAdapter +import at.hannibal2.skyhanni.utils.IdentityCharacteristics import at.hannibal2.skyhanni.utils.KotlinTypeAdapterFactory import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzRarity @@ -29,6 +32,7 @@ import com.google.gson.TypeAdapterFactory import com.google.gson.stream.JsonReader import com.google.gson.stream.JsonToken import com.google.gson.stream.JsonWriter +import io.github.notenoughupdates.moulconfig.annotations.ConfigLink import io.github.notenoughupdates.moulconfig.observer.PropertyTypeAdapterFactory import io.github.notenoughupdates.moulconfig.processor.BuiltinMoulConfigGuis import io.github.notenoughupdates.moulconfig.processor.ConfigProcessorDriver @@ -214,6 +218,31 @@ class ConfigManager { BuiltinMoulConfigGuis.addProcessors(processor) UpdateManager.injectConfigProcessor(processor) ConfigProcessorDriver(processor).processConfig(features) + + try { + findPositionLinks(features, mutableSetOf()) + } catch (e: Exception) { + if (LorenzEvent.isInGuardedEventHandler) + throw e + } + } + + private fun findPositionLinks(obj: Any?, slog: MutableSet<IdentityCharacteristics<Any>>) { + if (obj == null) return + if (!obj.javaClass.name.startsWith("at.hannibal2.skyhanni.")) return + val ic = IdentityCharacteristics(obj) + if (ic in slog) return + slog.add(ic) + for (field in obj.javaClass.fields) { + field.isAccessible = true + if (field.type != Position::class.java) { + findPositionLinks(field.get(obj), slog) + continue + } + val configLink = field.getAnnotation(ConfigLink::class.java) ?: continue + val position = field.get(obj) as Position + position.setLink(configLink) + } } private fun firstLoadFile(file: File?, fileType: ConfigFileType, defaultValue: Any): Any { |