hibiscus/src/main/kotlin/codes/som/hibiscus/features/FeaturesRegistry.kt

33 lines
991 B
Kotlin

package codes.som.hibiscus.features
import codes.som.hibiscus.api.feature.Feature
import codes.som.hibiscus.features.combat.Criticals
import codes.som.hibiscus.features.exploits.AntiGhost
import codes.som.hibiscus.features.movement.Flight
import codes.som.hibiscus.features.movement.Speed
import codes.som.hibiscus.features.overlay.Overlay
import codes.som.hibiscus.features.exploits.Ghost
import codes.som.hibiscus.features.player.NoFallDamage
val ALL_FEATURES: Array<() -> Feature> = arrayOf(
::NoFallDamage,
::Flight,
::Overlay,
::Speed,
::Criticals,
::Ghost,
::AntiGhost,
)
class FeaturesRegistry {
private val features = ALL_FEATURES.map { it() }.sortedBy { it.name }
fun getAllFeatures() = features.asSequence()
inline fun <reified T : Feature> getFeature() =
getFeature(T::class.java)
@Suppress("UNCHECKED_CAST")
fun <T : Feature> getFeature(type: Class<T>) =
features.first { it.javaClass == type } as T
}