Plugin dependencies and plugin initialization

Plugins can define dependencies on other plugins using a simple string with a list of plugins to load before or after, and whether they're required for the plugin to run. However, currently this does only affect the construction of the plugin (the call to the constructor), not any of the initialization events when almost everything of plugin initialization will take place.

(The only reason it works kind of currently on SpongeForge is that the events are registered in the order of dependencies. This is however basically an implementation detail of the event manager, and as soon as one of the plugins defines a priority on the initialization events it will already get called out of order.)

Therefore the only thing plugins can rely on is that the classes of the dependencies are on the classpath, but not that the plugin was actually already initialized. One issue that results from this is that plugins have no way to tell if their dependencies were successfully initialized either. Sponge will catch and log all exceptions happening in the initialization events, but it is nowhere stored for plugins (nor the users) to check - the only way to check if a plugin was initialized correctly is to check the log files (and basically hope that nothing else breaks, because all other event handlers etc. will be still called, no matter what happened during the initialization phase).

Generally this is just something plugin developers have to keep in mind, there are still the priorities events are called in as well as multiple plugin initialization events plugins can use to handle things which require initialization of the other plugins. However, we don't need a complex dependency system if it does actually just affect whether the classes are already on classpath or not - then a simple list of (optional required) dependencies is enough.

On the other hand, changing the way plugin initialization is done would probably either require major changes in the event manager, or a different way these events are called with that doesn't go through the global event manager directly.

Note: This is just a problem with how Sponge plugins are loaded. Forge handles initialization on a different way, therefore it's not a problem for Forge mods: - Afaik initalization events on Forge have no priority plugins can set - Forge calls the initialization events per-mod, with mod-specific properties they can get, so it's not an event handled through the normal global event manager - The server will crash if one of the mods throws an exception in the initialization events (iirc)

该提问来源于开源项目:SpongePowered/SpongeAPI

查看全部
weixin_39657662
weixin_39657662
2020/11/25 11:42
  • 点赞
  • 收藏
  • 回答
    私信

16个回复