I want to know the best solution for when during initialization, and something goes wrong in that process. This will most likely make the plugin unusable and throw millions of exceptions.
How do I disable/unload the plugin when a fail during initialization happens? I did not find anything in the PluginManager regarding this.
Easy, do your checks and have a simple boolean “enabled” that after the plugin init, you go and say “hey, were we enabled properly? No? Okay, keep that boolean false and don’t init listeners etc”.
Then third parties can check your API of “enabled” and go from there.
Disabling plugins while the server is running has the potential to create a myriad of issues which is why its not supported. I recommend implenenting a sort of “disabled mode” where the core functionality of your plugin doesnt work. (I.e. if the config fails to load, dont register commands, etc)
I would not prefer a plugin that crashs my production server and corrupts my worlds …
I would prefer a plugin that shutdown the server with an error message
I will most likely go with a similar solution that @pie_flavor presented. Unregister listeners, remove commands, cancels all scheduled tasks and log that the plugin was disabled with the reason why.