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.get("world");

        // 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["world"] as World

        // Unload the world (and save the world's chunks)
        Bukkit.getServer().unloadWorld(world, true)
    })
    .register()
commandAPICommand("unloadworld") {
    worldArgument("world")
    anyExecutor { sender, args ->
        val world = args["world"] as World

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