From abb695ad07cf733dfaf1af7c69609f94aa6440f1 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Mon, 15 Mar 2021 12:40:36 +0800 Subject: [PATCH] Created API Usages (markdown) --- API-Usages.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 API-Usages.md diff --git a/API-Usages.md b/API-Usages.md new file mode 100644 index 0000000..cb4e679 --- /dev/null +++ b/API-Usages.md @@ -0,0 +1,38 @@ +This pages provides examples and explanation for the common API usages of Multiverse-Core introduced [here](Developer-API-Starter). It's impossible to cover all API methods in this guide, but rest assured we have [javadocs](http://ci.onarandombox.com/job/Multiverse-Core/javadoc/overview-summary.html) and [source code](https://github.com/Multiverse/Multiverse-Core/tree/main/src/main/java/com/onarandombox/MultiverseCore/api) provided. + +## [MVWorldManager](http://ci.onarandombox.com/job/Multiverse-Core/javadoc/com/onarandombox/MultiverseCore/api/MVWorldManager.html) +The MVWorldManager interface is the heart of managing worlds in Multiverse. You can use various methods in this class to create, delete, regen worlds and much more! + +### Getting the WorldManager instance +```java +MVWorldManager worldManager = core.getMVWorldManager(); +``` +If you are unsure of getting the Multiverse-Core instance, see [here](Developer-API-Starter#getting-the-multiverse-plugin-instances). + +### Creating a world +Lets now create a new overworld called `creative`. +```java +worldManager.addWorld( + "creative", // The worldname + World.Environment.NORMAL, // The overworld environment type. + null, // The world seed. Any seed is fine for me, so we just pass null. + WorldType.NORMAL, // Nothing special. If you want something like a flat world, change this. + true, // This means we want to structures like villages to generator, Change to false if you don't want this. + null // Specifies a custom generator. We are not using any so we just pass null. +); +``` +Things to note: +* World names follow the Bukkit API's [`NamespacedKey`](https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/NamespacedKey.html), which means it does not allow spaces or special characters. + +### Loading/Unloading a world +You may want to unload worlds when unused and load them back when it's needed. +```java +// unloading +worldManager.unloadWorld("creative"); + +// loading +worldManager.loadWorld("creative"); +``` +Things to note: +* You cannot unload the default world defined in `level-name` of `server.properties`. +* You can only load worlds that are known by Multiverse, use the `MVWorldManager#addWorld` method mentioned previously. \ No newline at end of file