[SOLVED] Get all world names

As by title, there’s a method to know how many worlds a server has (and their relative names)? I’ve tried this

Sponge.getServer().getWorlds()

but if i print the size it says it’s 0 (meaning is empty)

I’m using this without any issues myself in API5.

for (World world : Sponge.getGame().getServer().getWorlds()) {
    ... world.getName() ...;
}

It’s weird. I’m calling that when loading the config file, maybe at that particular moment sponge has no knowledge about the worlds? And if so, how can i tell sponge to do that AFTER all worlds are loaded?

At what point are you looking for worlds?

Make sure you call the method after the GameStartingServerEvent has been fired…

Calling that in the GameStartedServerEvent has solved the problem. Thank you for the help :slight_smile:

IT also helps to read the difference of the state events and what they mean.