package codes.som.hibiscus.api.feature import codes.som.hibiscus.Hibiscus import codes.som.hibiscus.api.command.Command 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>() protected inline fun on( crossinline cond: () -> Boolean = { true }, phase: EventPhase = EventPhase.NORMAL, listener: Listener ) = on(object : TypedListener(T::class.java, phase) { override fun on(event: T) { if (cond()) listener.on(event) } }) protected fun on(listener: TypedListener) = 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 { Hibiscus.bus.registerTyped(it) } } else { listeners.forEach { Hibiscus.bus.unregisterTyped(it) } onDisable() } } } var hiddenInOverlay = false open fun onEnable() {} open fun onDisable() {} open fun createFeatureCommand(): Command { return FeatureCommand(this) } open fun loadData() {} // TODO: Module commands }