diff --git a/build.gradle.kts b/build.gradle.kts index 6add232..a4d51e3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -55,7 +55,8 @@ subprojects { flattenpackagehierarchy("$group.snowygui") allowaccessmodification() adaptclassstrings() - "$group.**".also { dontwarn(it); dontnote(it) } + dontnote("$group.**") + dontwarn("java.**") val homeDir = System.getProperty("java.home") as String libraryjars(configurations.compileClasspath.get().filter { file -> listOf( diff --git a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt index ba40297..479c3e1 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt @@ -10,6 +10,8 @@ import org.apache.logging.log4j.Logger abstract class Snowy { private val displayInitMessage: Boolean by obtained companion object { + @JvmStatic + protected val FeaturePackage: String = "fr.username404.snowygui.gui.feature" lateinit var annotatedButtons: Set> fun onEvent(e: String, lambda: argsLambda) = useKey(e).add(lambda) @JvmField diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt index 2b86fba..88f38a3 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt @@ -37,7 +37,7 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { } } } - private val info = this::class.findAnnotation() ?: throw Exception("Missing @Button annotaton") + private val info = this::class.findAnnotation() ?: throw Exception("Missing @ButtonInfo annotaton") override var color = info.parent.categoryColor val title = this@ButtonImpl::class.simpleName protected open fun execAction() = Unit diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonInfo.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonInfo.kt index 5d3d128..df8f5ee 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonInfo.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonInfo.kt @@ -19,6 +19,7 @@ annotation class ButtonInfo( } }; enum class Category(val translationKey: String, val categoryColor: Colors) { MISC("snowy.clickbox.misc", Colors.BLUE), - RISKY("snowy.clickbox.risky", Colors.RED); + RISKY("snowy.clickbox.risky", Colors.RED), + MACROS("snowy.clickbox.macros", Colors.GREEN); init { ClickGui.components.add(ClickBox(y = 4.0, name = TranslatableComponent(translationKey), color = categoryColor)) } } diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Colors.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Colors.kt index 7f08e56..e6f8b8b 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Colors.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Colors.kt @@ -5,5 +5,6 @@ enum class Colors(val hexValue: Int) { BLACK(0x000000), GOLD(0xe69500), BLUE(0x6C9E9D), - RED(0x660000); + RED(0x660000), + GREEN(0x00FF7F) } diff --git a/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt b/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt index 081d5b2..024899e 100644 --- a/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt +++ b/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt @@ -26,7 +26,7 @@ class FabricInit: Snowy(), ClientModInitializer { init { annotatedButtons = Reflections( ConfigurationBuilder() - .setUrls(ClasspathHelper.forClassLoader()) + .setUrls(ClasspathHelper.forPackage(FeaturePackage)) .setScanners(SubTypesScanner(false), TypeAnnotationsScanner()) .useParallelExecutor() ).getTypesAnnotatedWith(ButtonInfo::class.java) diff --git a/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt b/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt index 3f2a4f1..2a524bb 100644 --- a/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt +++ b/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt @@ -39,12 +39,12 @@ class ForgeInit: Snowy() { .map { obj: ModFileScanData -> obj.classes } .flatMap { obj: Set -> obj.stream() } .filter { data: ModFileScanData.ClassData? -> - (data!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(data) as Type).className.let { - if (it.contains("fr.username404") && !it.contains("mixins")) { - Class.forName(it).declaredAnnotations.any { annotation -> + (data!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(data) as Type).className.let { classname -> + classname.startsWith(FeaturePackage).let { + it && Class.forName(classname).declaredAnnotations.any { annotation -> annotation is ButtonInfo } - } else false + } } } .map { Class.forName((it!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(it) as Type).className) }