File tree Expand file tree Collapse file tree
src/main/kotlin/org/cobalt Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,7 +27,6 @@ object Cobalt : ClientModInitializer {
2727 TickScheduler , MainCommand , NotificationManager ,
2828 RotationExecutor ,
2929 ).forEach { EventBus .register(it) }
30-
3130 Config .loadModulesConfig()
3231 EventBus .register(this )
3332 println (" Cobalt Mod Initialized" )
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ object EventBus {
1818 private val listeners = ConcurrentHashMap <Class <* >, List <ListenerData >>()
1919
2020 private val registered = ConcurrentHashMap .newKeySet<Any >()
21- private val dynamicRunnable = ConcurrentHashMap <Class <out Event >, MutableList <Runnable >>()
21+ private val dynamicRunnable = ConcurrentHashMap <Class <out Event >, MutableList < ( Event ) -> Unit >> ()
2222
2323 @JvmStatic
2424 fun register (obj : Any ) {
@@ -203,15 +203,17 @@ object EventBus {
203203 }
204204
205205 @JvmStatic
206- fun registerEvent (eventClass : Class <out Event >, runnable : Runnable ) {
207- dynamicRunnable.computeIfAbsent(eventClass) { mutableListOf () }.add(runnable)
206+ fun < T : Event > registerEvent (eventClass : Class <T >, listener : ( T ) -> Unit ) {
207+ dynamicRunnable.computeIfAbsent(eventClass) { mutableListOf () }.add { event -> listener(event as T ) }
208208 }
209209
210+
210211 @JvmStatic
211- fun handleDynamic (event : Event ) {
212- dynamicRunnable.filter { (clazz, _) -> clazz.isAssignableFrom(event::class .java) }.forEach { (_, listeners) ->
213- listeners.forEach { it.run () }
214- }
212+ private fun handleDynamic (event : Event ) {
213+ dynamicRunnable.filter { (clazz, _) -> clazz.isAssignableFrom(event::class .java) }
214+ .forEach { (_, listeners) ->
215+ listeners.forEach { it(event) }
216+ }
215217 }
216218
217219}
You can’t perform that action at this time.
0 commit comments