Search code examples
javaminecraftbukkit

Spigot-API get another world into an World object in java


I know how to get the main world into a World object.

World world = Bukkit.getWorld("world");

This would be the default world where players can build on. I have a little mini game plugin and I want to tp the participating players into a game world. I tried getting the other world like you can see above but that gives me an null error.

World world = Bukkit.getWorld("gameworld");

How do I manage to do this? And does it have something to do with the world container "worlds" where I can but additional worlds in? Please help, ty


Solution

  • If you want to create a new world, use Bukkit.createWorld(). To load it, you have to call Bukkit.getWorld("name") in the onEnable() method of your plugin to load it (or you can call the Bukkit.createWorld(), since that only creates a new world if it doesn't exist yet, and also provides a World object).