When the server starts there are a few worlds I would like to delete before they are loaded. server.deleteWorld() accepts an WorldProperties argument. server.getAllWorldProperties() returns all world properties.
I was thinking I could use server.getAllWorldProperties() to delete some of the worlds (I also delete these worlds when the server shuts down, but the worlds won’t get deleted if the server crashes for example). So I threw this in real quick:
Server server = ...;
void onServerAboutToStart(GameAboutToStartServerEvent event) {
Log.info("Total worlds: " + server.getWorldProperties().size()); // prints "0" to console
for (WorldProperties world : server.getWorldProperties()) {
if (world.getName().startsWith("foo")) {
server.deleteWorld(world);
}
}
}
The problem is that it seems like server.getAllWorldProperties() returns an empty collection during GameAboutToStartServerEvent, so this won’t work. I assume that WorldProperties are not loaded until GameStartingServerEvent is ran, but by then it is already too late because the world has already been loaded. I would then have to unload it and then delete it, which seems like a waste of time.
Is there a way to access and delete the world properties before the worlds are loaded? Or do I have to manually use IO to delete the folders world/foo_world
and config/sponge/worlds/minecraft/overworld/foo_world
?