From 3d08c24c17f8acecdcdb1459c9a49a122db8fdaa Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Sat, 15 May 2021 17:15:24 +0200 Subject: [PATCH] Initialize every button in Snowy.kt --- build.gradle.kts | 4 +++- .../src/main/kotlin/fr/username404/snowygui/Snowy.kt | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index cf35485..3db3be7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -80,7 +80,8 @@ subprojects { listOf( "$kotlinX:kotlinx-datetime:0.2.0", "com.typesafe:config:1.4.1", - "io.github.config4k:config4k:0.4.2" + "io.github.config4k:config4k:0.4.2", + "org.reflections:reflections:0.9.12" ).forEach { implementation(it); shadowC(it) { isTransitive = false } } "minecraft"("com.mojang:minecraft:${rootProject.property("minecraft")}") "mappings"(mappingsDep) @@ -120,6 +121,7 @@ allprojects { withType(ShadowJar::class) { relocate("kotlinx-datetime", "${rootProject.group}.kotlinx-datetime") relocate("org.jetbrains", "${rootProject.group}.jetbrainslibs") + relocate("org.reflections", "${rootProject.group}.reflectionlib") relocate("com.typesafe.config", "${rootProject.group}.typesafe.config") relocate("io.github.config4k", "${rootProject.group}.config4k") relocate("net.arikia.dev.drpc", "${rootProject.group}.drpc") diff --git a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt index 95bd834..e37b24b 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt @@ -2,14 +2,17 @@ package fr.username404.snowygui import fr.username404.snowygui.EventSnowy.Companion.useKey import fr.username404.snowygui.config.Configuration.obtained +import fr.username404.snowygui.gui.feature.ButtonInfo import fr.username404.snowygui.misc.AddKeyMaps import io.github.config4k.getValue import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger +import org.reflections.Reflections abstract class Snowy { private val displayInitMessage: Boolean by obtained companion object { + val reflections = Reflections("fr.username404.snowygui") fun onEvent(e: String, lambda: argsLambda) = useKey(e).add(lambda) @JvmField val logs: Logger = LogManager.getLogger() @@ -25,6 +28,15 @@ abstract class Snowy { } fun atInit() { if (displayInitMessage) logs.info("Init point of SnowyGUI hit.") + reflections.getTypesAnnotatedWith(ButtonInfo::class.java).forEach { // Initializes every button + logs.info( + try { + it.getConstructor().newInstance() + } catch (e: NoSuchMethodException) { + it.kotlin.objectInstance + } + ) + } eventsInit() } } \ No newline at end of file