From 530ecb36cb73c865f0ea4f8d0924e04df9080315 Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Wed, 30 Jun 2021 16:27:49 +0200 Subject: [PATCH] Remove useless duplicated code in ForgeInit.kt --- common/src/main/kotlin/fr/username404/snowygui/Snowy.kt | 5 +++-- .../kotlin/fr/username404/snowygui/forge/ForgeInit.kt | 9 +-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt index 00c3525..7e93fef 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt @@ -11,12 +11,13 @@ import org.apache.logging.log4j.Logger import java.lang.reflect.Modifier abstract class Snowy { - protected fun Class<*>.isValidForButtonCollection(): Boolean = (!((Modifier.isAbstract(javaClass.modifiers)) || javaClass.annotations.any { it is ButtonInfo && it.ignored })) + protected fun Class<*>.isValidForButtonCollection(): Boolean = + !Modifier.isAbstract(modifiers) && declaredAnnotations.any { it is ButtonInfo && !it.ignored } private val displayInitMessage: Boolean by Configuration companion object { val MissingComponent: TranslatableComponent = object: TranslatableComponent(null) { override fun getString(): String = "MISSING_COMPONENT" } @JvmStatic - protected val FeaturePackage: String = "fr.username404.snowygui.gui.feature" + protected val FeaturePackage: String = ButtonInfo::class.java.packageName lateinit var annotatedButtons: Set> fun onEvent(e: Any, lambda: argsLambda) = useKey(e.toString()).add(lambda) @JvmField 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 c24ea44..376838f 100644 --- a/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt +++ b/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt @@ -4,7 +4,6 @@ import fr.username404.snowygui.Snowy import fr.username404.snowygui.config.SnowyConfigScreen import fr.username404.snowygui.config.configScreenParent import fr.username404.snowygui.gui.feature.ButtonImpl -import fr.username404.snowygui.gui.feature.ButtonInfo import net.minecraftforge.fml.ExtensionPoint import net.minecraftforge.fml.ModList import net.minecraftforge.fml.common.Mod @@ -34,13 +33,7 @@ class ForgeInit: Snowy() { .flatMap { obj: Set -> obj.stream() } .filter { data: ModFileScanData.ClassData? -> (data!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(data) as Type).className.let { classname -> - classname.startsWith(FeaturePackage).let { - it && with(Class.forName(classname)) { - isValidForButtonCollection() && declaredAnnotations.any { annotation -> - annotation is ButtonInfo - } - } - } + classname.startsWith(FeaturePackage) && Class.forName(classname).isValidForButtonCollection() } } .map { Class.forName((it!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(it) as Type).className).asSubclass(ButtonImpl::class.java)}