World arguments

A picture of world arguments in action

The WorldArgument class allows a command sender to refer to a loaded Bukkit World.

Example - Unloading world

Say we want to unload a world on our Minecraft server. We want to create a command with the following syntax:

/unloadworld <world>

Using the world from the WorldArgument, we can then unload the world safely using Bukkit.getServer().unloadWorld() and passing true (to save chunks):

new CommandAPICommand("unloadworld")
    .withArguments(new WorldArgument("world"))
    .executes((sender, args) -> {
        World world = (World) args[0];

        // Unload the world (and save the world's chunks)
        Bukkit.getServer().unloadWorld(world, true);
    })
    .register();
CommandAPICommand("unloadworld")
    .withArguments(WorldArgument("world"))
    .executes(CommandExecutor { sender, args ->
        val world = args[0] as World

        // Unload the world (and save the world's chunks)
        Bukkit.getServer().unloadWorld(world, true)
    })
    .register()