Add a @Ignore annotation, make Macro.command a jvm field and add a isValidForButtonCollection function to Snowy.kt

This commit is contained in:
Username404 2021-05-20 14:24:13 +02:00
parent dae08e3957
commit c7729af67f
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
5 changed files with 12 additions and 3 deletions

View File

@ -4,12 +4,15 @@ import com.google.gson.Gson
import com.google.gson.GsonBuilder
import fr.username404.snowygui.EventSnowy.Companion.useKey
import fr.username404.snowygui.config.Configuration.obtained
import fr.username404.snowygui.gui.feature.Ignored
import fr.username404.snowygui.misc.AddKeyMaps
import io.github.config4k.getValue
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import kotlin.reflect.full.hasAnnotation
abstract class Snowy {
protected fun Class<*>.isValidForButtonCollection(): Boolean = (!(kotlin.isAbstract || kotlin.hasAnnotation<Ignored>()))
private val displayInitMessage: Boolean by obtained
companion object {
val Gson: Gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()

View File

@ -26,3 +26,8 @@ annotation class ButtonInfo(
MACROS("snowy.clickbox.macros", Colors.GREEN);
init { ClickGui.components.add(ClickBox(y = 4.0, name = TranslatableComponent(translationKey), color = categoryColor)) }
}
/**
* Excludes a class from button collection
*/
annotation class Ignored

View File

@ -4,9 +4,10 @@ import com.google.gson.annotations.Expose
import net.minecraft.client.Minecraft
import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type
@Ignored
@ButtonInfo(Category.MACROS, kind = Type.CLICK)
data class Macro(
@Expose private val command: String,
@Expose @JvmField private val command: String,
@Expose override val title: String = command
): ButtonImpl() {
override fun execAction() = Minecraft.getInstance().player!!.chat("/$command")

View File

@ -29,6 +29,6 @@ class FabricInit: Snowy(), ClientModInitializer {
.setUrls(ClasspathHelper.forPackage(FeaturePackage))
.setScanners(SubTypesScanner(false), TypeAnnotationsScanner())
.useParallelExecutor()
).getTypesAnnotatedWith(ButtonInfo::class.java).filterNot { it.kotlin.isAbstract || it.kotlin.isData; }.toSet()
).getTypesAnnotatedWith(ButtonInfo::class.java).filter { it.isValidForButtonCollection() }.toSet()
}
}

View File

@ -42,7 +42,7 @@ class ForgeInit: Snowy() {
(data!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(data) as Type).className.let { classname ->
classname.startsWith(FeaturePackage).let {
it && with(Class.forName(classname)) {
(!(kotlin.isAbstract || kotlin.isData)) && declaredAnnotations.any { annotation ->
isValidForButtonCollection() && declaredAnnotations.any { annotation ->
annotation is ButtonInfo
}
}