Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make onEnable always run before worlds load, remove onLoad, remove load: from plugin.yml #6330

Open
dktapps opened this issue Apr 10, 2024 · 0 comments
Labels
BC break Breaks API compatibility Category: API Related to the plugin API Opinions Wanted Request for comments & opinions from the community Type: Enhancement Contributes features or other improvements to PocketMine-MP

Comments

@dktapps
Copy link
Member

dktapps commented Apr 10, 2024

Description

This is linked to the following issues: #3067

We want to get rid of onLoad, and make onEnable the defacto standard (or possibly the other way round).

Right now, the only reason to use onLoad is if you want to use load: POSTWORLD to have onEnable do things after the worlds are loaded within the same plugin. This is an uncommon case, and it's also clunky: you can't register event handlers or schedule tasks during onLoad. This case could be better served by adding an event, e.g. StartupWorldsLoadedEvent, so that plugins can run their onEnable before the worlds load and do logic at the POSTWORLD step.

In short, your options for startup work are as follows:

  • POSTWORLD (most plugins) - you can't register new generators, world providers etc in time for worlds to load
  • STARTUP - you can do some extra stuff pre-world, but you can't do anything to worlds
  • POSTWORLD + onLoad - you can do some pre-world stuff and all normal post-world stuff, but you can't listen for world loading events, plugin load events, etc - onLoad also can't disable the plugin

With this proposal:

  • onEnable would effectively always have STARTUP order - you'd be able to do everything except interact with worlds
  • StartupWorldsLoadedEvent would allow you to do whatever extra postworld work you need
  • No weird restrictions and shuffling code between onLoad and onEnable trying to get them to work

This also has the happy side effect of deleting a confusing plugin.yml directive, making onEnable behaviour more predictable (no need to look at plugin.yml to see what you can and can't do), and removing some API cruft (no more getting confused between onLoad and onEnable).

Alternative methods

We could just remove the restrictions from onLoad instead (and perhaps make onEnable always run at POSTWORLD). However, I think that this would make the intended purpose of these two hooks even more confusing, as onEnable wouldn't live up to its name anymore.

@dktapps dktapps changed the title Make onEnable always run before worlds load Make onEnable always run before worlds load, remove onLoad, remove load: from plugin.yml Apr 10, 2024
@dktapps dktapps added Category: API Related to the plugin API Type: Enhancement Contributes features or other improvements to PocketMine-MP BC break Breaks API compatibility labels May 6, 2024
@dktapps dktapps added the Opinions Wanted Request for comments & opinions from the community label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BC break Breaks API compatibility Category: API Related to the plugin API Opinions Wanted Request for comments & opinions from the community Type: Enhancement Contributes features or other improvements to PocketMine-MP
Projects
None yet
Development

No branches or pull requests

1 participant