So I’ve come across this issue, where the DataSource I get by opening a JDBC-MySQL URL through the SqlProvider gets closed beforeGameStoppingEvent has been executed.

The docs (https://docs.spongepowered.org/stable/en/plugin/database.html) clearly state to not store Connections. But no word about DataSources. And from my perspective that makes sense as creating a DataSource involves at least some kind of parsing the string, etc. So I naturally stored the DataSource I get from the SqlService#getDataSource(jdbcUrl) call.

However this DataSource gets closed before the GameStoppingEvent (not GameStoppedEvent). I mean most plugins using database stuff do at least some kind of cleanup during that stage so I think it’s too early to do it before the event. (After should be fine).

Though if it is intended and the call to get the DataSource is also very inexpensive, it should be also mentioned on the docs.
In any case the example should be extended to show that you either can keep the DataSource or that you can’t.

but no example is provided and I honestly don’t have the slightest clue what I should do with that method.
Pass my entire URL to it?
Pass mysql to it?
An example on how to use that would be more than apprechiated.

Now to make this clear, this not a complaint or anything, rather me asking for clarification as I’ve recieved contraticory infomation and some information just seems to contradict common sense/experience.

It looks like what you would do is have an alias->jbc string set in the SQL part of the sponge config, and then you could retrieve that String by calling getConnectionUrlFromAlias(<ALIAS_IN_CONFIG>)
I have not used this before, however, if more info beyond this is needed, I could figure it out.

In response to the DataSource issue, here is a bit how the whole DataSource system works (afaik):

When you call getDataSource, it does parse the string using regex, which given how often you should be calling this method (not ever single tick… if you’re doing that you are doing it wrong), isn’t that expensive.

It then uses that parsed data to create and CACHE a new DataSource. To me that makes it look like you are supposed to call getDataSource every time/frequently.

I’ll try to use the GameStoppingServerEvent instead of GameStoppingEvent.
And in my current implementation I call getDataSource every time I create a connection. Though if it’s cached, that should be alright. Though I’d definately prefer keeping the source in a variable for simplicity reasons.