From cb20a6e744f7fc6c7c26439be6f8580c7c45ed18 Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Sat, 15 May 2021 22:48:51 +0200 Subject: [PATCH] Use reflections8 instead of reflections --- build.gradle.kts | 18 +++++++++++++----- .../kotlin/fr/username404/snowygui/Snowy.kt | 17 +++++++++++++++-- .../snowygui/gui/feature/ButtonInfo.kt | 2 +- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 3db3be7..324cd07 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -45,7 +45,7 @@ subprojects { keep("class $group.snowygui.fabric.**") keep("class $group.snowygui.forge.**") keepnames("class $group.snowygui.Snowy") - keepnames("class $group.snowygui.gui.feature.*") + keep("class $group.snowygui.gui.feature.**") keepclassmembers("class $group.snowygui.** { public protected ; }") keepattributes("*Annotation*, Signature, InnerClasses, EnclosingMethod, MethodParameters, Synthetic, Exceptions") obfuscationdictionary("$dictionariesDir/dictionary.txt") @@ -56,7 +56,14 @@ subprojects { adaptclassstrings() "$group.**".also { dontwarn(it); dontnote(it) } val homeDir = System.getProperty("java.home") as String - libraryjars(configurations.compileClasspath.get().filter { it.name.startsWith("kotlin") }) + libraryjars(configurations.compileClasspath.get().filter { file -> + listOf( + "kotlin", + "gson" + ).any { + file.name.startsWith(it) + } + }) if (JavaVersion.current().isJava9Compatible) { libraryjars("$homeDir/jmods/java.base.jmod") } else libraryjars("$homeDir/lib/rt.jar") @@ -81,8 +88,8 @@ subprojects { "$kotlinX:kotlinx-datetime:0.2.0", "com.typesafe:config:1.4.1", "io.github.config4k:config4k:0.4.2", - "org.reflections:reflections:0.9.12" - ).forEach { implementation(it); shadowC(it) { isTransitive = false } } + "net.oneandone.reflections8:reflections8:0.11.7", "org.javassist:javassist:3.28.0-GA" + ).forEach { implementation(it); shadowC(it) { isTransitive = false; } } "minecraft"("com.mojang:minecraft:${rootProject.property("minecraft")}") "mappings"(mappingsDep) } @@ -121,7 +128,8 @@ allprojects { withType(ShadowJar::class) { relocate("kotlinx-datetime", "${rootProject.group}.kotlinx-datetime") relocate("org.jetbrains", "${rootProject.group}.jetbrainslibs") - relocate("org.reflections", "${rootProject.group}.reflectionlib") + relocate("javassist", "${rootProject.group}.javassist") + relocate("org.reflections8", "${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 108b2df..55a15e6 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt @@ -6,15 +6,28 @@ 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 +import org.reflections8.Reflections +import org.reflections8.scanners.SubTypesScanner +import org.reflections8.scanners.TypeAnnotationsScanner +import org.reflections8.util.ClasspathHelper +import org.reflections8.util.ConfigurationBuilder abstract class Snowy { private val displayInitMessage: Boolean by obtained companion object { - val reflections = Reflections("fr.username404.snowygui") + val reflections = Reflections(ConfigurationBuilder() + .setUrls(ClasspathHelper.forClassLoader()) + .setScanners(SubTypesScanner(false), TypeAnnotationsScanner()) + .useParallelExecutor() + ) fun onEvent(e: String, lambda: argsLambda) = useKey(e).add(lambda) @JvmField val logs: Logger = LogManager.getLogger() + init { + reflections.allTypes.forEach { + if (it.contains("fr.username404")) logs.info(it) + } + } } private fun eventsInit() { onEvent("EndTick") { 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 59324ad..5d3d128 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 @@ -20,5 +20,5 @@ annotation class ButtonInfo( }; enum class Category(val translationKey: String, val categoryColor: Colors) { MISC("snowy.clickbox.misc", Colors.BLUE), RISKY("snowy.clickbox.risky", Colors.RED); - init { ClickGui.components.add(ClickBox(y = 0.0, name = TranslatableComponent(translationKey), color = categoryColor)) } + init { ClickGui.components.add(ClickBox(y = 4.0, name = TranslatableComponent(translationKey), color = categoryColor)) } }