Add a @Ignore annotation, make Macro.command a jvm field and add a isValidForButtonCollection function to Snowy.kt
This commit is contained in:
parent
dae08e3957
commit
c7729af67f
|
@ -4,12 +4,15 @@ import com.google.gson.Gson
|
||||||
import com.google.gson.GsonBuilder
|
import com.google.gson.GsonBuilder
|
||||||
import fr.username404.snowygui.EventSnowy.Companion.useKey
|
import fr.username404.snowygui.EventSnowy.Companion.useKey
|
||||||
import fr.username404.snowygui.config.Configuration.obtained
|
import fr.username404.snowygui.config.Configuration.obtained
|
||||||
|
import fr.username404.snowygui.gui.feature.Ignored
|
||||||
import fr.username404.snowygui.misc.AddKeyMaps
|
import fr.username404.snowygui.misc.AddKeyMaps
|
||||||
import io.github.config4k.getValue
|
import io.github.config4k.getValue
|
||||||
import org.apache.logging.log4j.LogManager
|
import org.apache.logging.log4j.LogManager
|
||||||
import org.apache.logging.log4j.Logger
|
import org.apache.logging.log4j.Logger
|
||||||
|
import kotlin.reflect.full.hasAnnotation
|
||||||
|
|
||||||
abstract class Snowy {
|
abstract class Snowy {
|
||||||
|
protected fun Class<*>.isValidForButtonCollection(): Boolean = (!(kotlin.isAbstract || kotlin.hasAnnotation<Ignored>()))
|
||||||
private val displayInitMessage: Boolean by obtained
|
private val displayInitMessage: Boolean by obtained
|
||||||
companion object {
|
companion object {
|
||||||
val Gson: Gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()
|
val Gson: Gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()
|
||||||
|
|
|
@ -26,3 +26,8 @@ annotation class ButtonInfo(
|
||||||
MACROS("snowy.clickbox.macros", Colors.GREEN);
|
MACROS("snowy.clickbox.macros", Colors.GREEN);
|
||||||
init { ClickGui.components.add(ClickBox(y = 4.0, name = TranslatableComponent(translationKey), color = categoryColor)) }
|
init { ClickGui.components.add(ClickBox(y = 4.0, name = TranslatableComponent(translationKey), color = categoryColor)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Excludes a class from button collection
|
||||||
|
*/
|
||||||
|
annotation class Ignored
|
|
@ -4,9 +4,10 @@ import com.google.gson.annotations.Expose
|
||||||
import net.minecraft.client.Minecraft
|
import net.minecraft.client.Minecraft
|
||||||
import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type
|
import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type
|
||||||
|
|
||||||
|
@Ignored
|
||||||
@ButtonInfo(Category.MACROS, kind = Type.CLICK)
|
@ButtonInfo(Category.MACROS, kind = Type.CLICK)
|
||||||
data class Macro(
|
data class Macro(
|
||||||
@Expose private val command: String,
|
@Expose @JvmField private val command: String,
|
||||||
@Expose override val title: String = command
|
@Expose override val title: String = command
|
||||||
): ButtonImpl() {
|
): ButtonImpl() {
|
||||||
override fun execAction() = Minecraft.getInstance().player!!.chat("/$command")
|
override fun execAction() = Minecraft.getInstance().player!!.chat("/$command")
|
||||||
|
|
|
@ -29,6 +29,6 @@ class FabricInit: Snowy(), ClientModInitializer {
|
||||||
.setUrls(ClasspathHelper.forPackage(FeaturePackage))
|
.setUrls(ClasspathHelper.forPackage(FeaturePackage))
|
||||||
.setScanners(SubTypesScanner(false), TypeAnnotationsScanner())
|
.setScanners(SubTypesScanner(false), TypeAnnotationsScanner())
|
||||||
.useParallelExecutor()
|
.useParallelExecutor()
|
||||||
).getTypesAnnotatedWith(ButtonInfo::class.java).filterNot { it.kotlin.isAbstract || it.kotlin.isData; }.toSet()
|
).getTypesAnnotatedWith(ButtonInfo::class.java).filter { it.isValidForButtonCollection() }.toSet()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -42,7 +42,7 @@ class ForgeInit: Snowy() {
|
||||||
(data!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(data) as Type).className.let { classname ->
|
(data!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(data) as Type).className.let { classname ->
|
||||||
classname.startsWith(FeaturePackage).let {
|
classname.startsWith(FeaturePackage).let {
|
||||||
it && with(Class.forName(classname)) {
|
it && with(Class.forName(classname)) {
|
||||||
(!(kotlin.isAbstract || kotlin.isData)) && declaredAnnotations.any { annotation ->
|
isValidForButtonCollection() && declaredAnnotations.any { annotation ->
|
||||||
annotation is ButtonInfo
|
annotation is ButtonInfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue