Is it worth auto-loading custom packages?
Posted: Thu Apr 28, 2016 8:00 pm
Hey there,
Writing this after noticing some kind of a flaw in my packages.
The question is, maybe it's worth to pre-load custom packages on server startup? Just import them from their directories so that they can register their events, start listening to listeners etc.
Example 1. Hot plug issue.
If you load the plugin that uses the package only after somebody joins the server, your package won't know of this player. You'll need to implement some kind of a hot-plug mechanism to go through PlayerIter and detect all existing players on the server. You don't need to do it, however, if the package was pre-loaded in the first place.
Example 2. Package doesn't always need to be imported by the plugins it's used by.
I have a package that basically works with events. It doesn't export anything to be imported by the actual plugin. The thing is, since it's never imported - it's never actually loaded. I was developing my plugin and was like, "ah, why the package doesn't fire its events?..". Then I realized I have to add an extra (unused) import statement for this package so it will get loaded when the plugin gets loaded. But then again, it will be loaded only with the plugin - and what if the plugin is being hot-plugged?
Maybe not all packages deserve or need pre-loading, but for some packages it will simplify the things. So maybe it's worth implementing some kind of a list of the packages that should load on startup, or even creating another directory for such packages?
Writing this after noticing some kind of a flaw in my packages.
The question is, maybe it's worth to pre-load custom packages on server startup? Just import them from their directories so that they can register their events, start listening to listeners etc.
Example 1. Hot plug issue.
If you load the plugin that uses the package only after somebody joins the server, your package won't know of this player. You'll need to implement some kind of a hot-plug mechanism to go through PlayerIter and detect all existing players on the server. You don't need to do it, however, if the package was pre-loaded in the first place.
Example 2. Package doesn't always need to be imported by the plugins it's used by.
I have a package that basically works with events. It doesn't export anything to be imported by the actual plugin. The thing is, since it's never imported - it's never actually loaded. I was developing my plugin and was like, "ah, why the package doesn't fire its events?..". Then I realized I have to add an extra (unused) import statement for this package so it will get loaded when the plugin gets loaded. But then again, it will be loaded only with the plugin - and what if the plugin is being hot-plugged?
Maybe not all packages deserve or need pre-loading, but for some packages it will simplify the things. So maybe it's worth implementing some kind of a list of the packages that should load on startup, or even creating another directory for such packages?