@@ -24,6 +24,7 @@ import com.lambda.event.events.TickEvent
2424import com.lambda.event.listener.SafeListener.Companion.listen
2525import com.lambda.interaction.request.ManagerUtils.accumulatedManagerPriority
2626import com.lambda.threading.runSafe
27+ import kotlin.reflect.KClass
2728
2829/* *
2930 * This class handles requests, offering specific opening times, and an option to queue a request for the
@@ -57,25 +58,7 @@ abstract class RequestHandler<R : Request>(
5758 var activeThisTick = false ; protected set
5859
5960 override fun load (): String {
60- openStages.forEach {
61- when (it) {
62- is TickEvent .Pre -> openRequestsFor(it)
63- is TickEvent .Post -> openRequestsFor(it)
64- is TickEvent .Network .Pre -> openRequestsFor(it)
65- is TickEvent .Network .Post -> openRequestsFor(it)
66- is TickEvent .Input .Pre -> openRequestsFor(it)
67- is TickEvent .Input .Post -> openRequestsFor(it)
68- is TickEvent .WorldRender .Pre -> openRequestsFor(it)
69- is TickEvent .WorldRender .Post -> openRequestsFor(it)
70- is TickEvent .Sound .Pre -> openRequestsFor(it)
71- is TickEvent .Sound .Post -> openRequestsFor(it)
72- is TickEvent .Render .Pre -> openRequestsFor(it)
73- is TickEvent .Render .Post -> openRequestsFor(it)
74- is TickEvent .Player .Pre -> openRequestsFor(it)
75- is TickEvent .Player .Post -> openRequestsFor(it)
76- else -> throw IllegalArgumentException (" Event '$it ' is not allowed for requests" )
77- }
78- }
61+ openStages.forEach { openRequestsFor(it::class , it) }
7962
8063 listen<TickEvent .Post >(Int .MIN_VALUE ) {
8164 activeThisTick = false
@@ -87,8 +70,8 @@ abstract class RequestHandler<R : Request>(
8770 /* *
8871 * opens the handler for requests for the duration of the given event
8972 */
90- private inline fun <reified T : Event > openRequestsFor (stage : T ) {
91- listen< T >( priority = Int .MAX_VALUE - (accumulatedManagerPriority - stagePriority)) {
73+ private inline fun <reified T : Event > openRequestsFor (instance : KClass < out T >, stage : T ) {
74+ listen(instance, priority = Int .MAX_VALUE - (accumulatedManagerPriority - stagePriority)) {
9275 tickStage = stage
9376 queuedRequest?.let { request ->
9477 handleRequest(request)
@@ -99,7 +82,8 @@ abstract class RequestHandler<R : Request>(
9982 onOpen?.invoke(this )
10083 preEvent()
10184 }
102- listen<T >(priority = Int .MIN_VALUE + stagePriority) {
85+
86+ listen(instance, priority = Int .MIN_VALUE + stagePriority) {
10387 onClose?.invoke(this )
10488 acceptingRequests = false
10589 }
0 commit comments