49 lines
1.3 KiB
Kotlin
49 lines
1.3 KiB
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.exploits.Ghost
|
|
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.player.NoFallDamage
|
|
import codes.som.hibiscus.features.visual.Freecam
|
|
import codes.som.hibiscus.util.Resettable
|
|
|
|
fun allFeatureClasses(): Array<() -> Feature> = arrayOf(
|
|
::NoFallDamage,
|
|
::Flight,
|
|
::Overlay,
|
|
::Speed,
|
|
::Criticals,
|
|
::Ghost,
|
|
::AntiGhost,
|
|
::Freecam,
|
|
)
|
|
|
|
class FeaturesRegistry : Resettable {
|
|
private val features = mutableListOf<Feature>()
|
|
|
|
init {
|
|
registerFeatures()
|
|
}
|
|
|
|
fun getAllFeatures() = features.asSequence()
|
|
inline fun <reified T : Feature> getFeature() =
|
|
getFeature(T::class.java)
|
|
|
|
@Suppress("UNCHECKED_CAST")
|
|
fun <T : Feature> getFeature(type: Class<T>) =
|
|
getAllFeatures().first { it.javaClass == type } as T
|
|
|
|
private fun registerFeatures() {
|
|
features.addAll(allFeatureClasses().map { it() })
|
|
}
|
|
|
|
override fun reset() {
|
|
features.clear()
|
|
registerFeatures()
|
|
}
|
|
}
|