PluginManager: ensure that handler candidates of async events with wrong return types don't attempt to register as sync events

this will cause other, more confusing errors to be thrown.

to be honest, I'm not sure if enforcing the return type here is even necessary (or desirable).
This commit is contained in:
Dylan K. Taylor 2024-11-13 21:30:24 +00:00
parent ac1cf73f8e
commit 972a9fb201
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -654,7 +654,10 @@ class PluginManager{
}
}
if(is_subclass_of($eventClass, AsyncEvent::class) && $this->canHandleAsyncEvent($handlerClosure)){
if(is_subclass_of($eventClass, AsyncEvent::class)){
if(!$this->canHandleAsyncEvent($handlerClosure)){
throw new PluginException("Event handler " . Utils::getNiceClosureName($handlerClosure) . " must return null|Promise<null> to be able to handle async events");
}
$this->registerAsyncEvent($eventClass, $handlerClosure, $priority, $plugin, $handleCancelled, $exclusiveCall);
}else{
$this->registerEvent($eventClass, $handlerClosure, $priority, $plugin, $handleCancelled);