Is it possible to get a list of all worlds on the server?

Hi!

I tried to do something like this:

List<World> worlds = (List<World>) server.getWorlds();

It doesn’t quite seem to work though. How can I get a list of all the worlds on the server?

Thanks!

Sponge.getServer().getWorlds()

https://jd.spongepowered.org/5.1.0/org/spongepowered/api/Server.html#getWorlds--

That does not work, that’s exactly what I tried.

To clarify my example:
server = Sponge.getServer();

Ah, getWorlds is only loaded worlds, getAllWorldProperties will get all worlds unloaded and loaded.

1 Like

Why are you casting the Collection to a List? You don’t know if it is one.

Well my question’s topic is asking for a way to get a list. I put what I tried. If you have a better way, I would appreciate if you could share it.

1 Like