2022-02-03 19:29:14 +00:00
|
|
|
package codes.som.hibiscus.api.feature
|
|
|
|
|
|
|
|
import codes.som.hibiscus.HibiscusMod
|
2022-02-03 21:43:06 +00:00
|
|
|
import codes.som.hibiscus.api.command.Command
|
2022-02-03 19:29:14 +00:00
|
|
|
import codes.som.hibiscus.api.event.*
|
|
|
|
import codes.som.hibiscus.api.feature.values.ValueRegistry
|
|
|
|
|
|
|
|
abstract class Feature(val name: String, val category: FeatureCategory) {
|
|
|
|
private val listeners = mutableListOf<TypedListener<*>>()
|
|
|
|
|
|
|
|
protected inline fun <reified T : Event> on(listener: Listener<T>) =
|
|
|
|
on(object : TypedListener<T>(T::class.java), Listener<T> by listener {})
|
|
|
|
|
|
|
|
protected fun <T : Event> on(listener: TypedListener<T>) =
|
|
|
|
listeners.add(listener)
|
|
|
|
|
|
|
|
val values = ValueRegistry()
|
|
|
|
|
|
|
|
var enabled: Boolean = false
|
|
|
|
set(value) {
|
|
|
|
val hasChanged = value != field
|
|
|
|
if (hasChanged) {
|
|
|
|
field = value
|
|
|
|
if (value) {
|
|
|
|
onEnable()
|
|
|
|
listeners.forEach { HibiscusMod.bus.registerTyped(it) }
|
|
|
|
} else {
|
|
|
|
listeners.forEach { HibiscusMod.bus.unregisterTyped(it) }
|
|
|
|
onDisable()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
open fun onEnable() {}
|
|
|
|
open fun onDisable() {}
|
|
|
|
|
2022-02-03 21:43:06 +00:00
|
|
|
open fun createFeatureCommand(): Command {
|
|
|
|
return FeatureCommand(this)
|
|
|
|
}
|
|
|
|
|
2022-02-03 19:29:14 +00:00
|
|
|
// TODO: Module commands
|
|
|
|
}
|