Decouple RegisteredListener and Plugin/PluginManager #6524
Labels
BC break
Breaks API compatibility
Category: API
Related to the plugin API
Category: Core
Related to internal functionality
Type: Enhancement
Contributes features or other improvements to PocketMine-MP
Milestone
Description
It's currently basically impossible to use events without a
Plugin
context (and therefore aServer
context).This is because
RegisteredListener
requires aPlugin
instance, even though it's only actually needed for decoration & forHandlerList::unregister()
.In addition, it's non-trivial to construct a
RegisteredListener
, and the code needed to do so is baked intoPluginManager::registerEvent()
. That's before we even talk aboutListener
and the magic reflection detection.Proposed changes
RegisteredListener
, either by making it nullable, changing it to a more general?object $owner
, or possibly getting rid of it entirely. It's only needed for this.PluginManager::registerEvent()
out into somewhere with less dependencies (e.g. a static method inRegisteredListener
or similar - enables the use of closure event handlers by core codePluginManager::registerEvents()
out into somewhere in thepocketmine\event
package withoutPlugin
orServer
dependencies - enables the use ofListener
magic by core codeJustification
The server core code can't listen to its own events right now without a dummy
Plugin
instance, which comes with a bunch of unnecessary baggage.We also can't easily unit-test the events system, because a
Plugin
context and therefore aServer
context is required. We could probably mock this, but it's an unnecessary inconvenience.Alternative methods
The text was updated successfully, but these errors were encountered: