I’ve seen a thread about this before but it involved NMS and forge and I am trying to do this with support for SpongeVanilla. The current way I have done this is
WorldCreationSettings.Builder builder = WorldCreationSettings.builder().name(name); WorldCreationSettings settings = builder.enabled(true).keepsSpawnLoaded(true).loadsOnStartup(true).build(); final Optional<WorldProperties> optionalProperties = Sponge.getGame().getServer().createWorldProperties(settings); WorldProperties properties = optionalProperties.get(); Sponge.getServer().saveWorldProperties(properties); Sponge.getServer().loadWorld(name);
Now I dont know if this is the correct way to do this but it has seemed to work with the exception of the amount of lag it produces. Usually on creation the server runs about 10000+ms behind. Now since minecraft is single threaded i dont know if this exactly is possible and I read something about how builders do async tasks, but I hope i can find a better way so i can avoid this amount of lag.