Skip to content

ItsHarshXD/WorldTemplateAPI

Repository files navigation

🌍 WorldTemplateAPI

WorldTemplateAPI is a Java library for Bukkit plugins that makes it easy to create and manage world templates on your Minecraft server. It works with Multiverse-Core to help you copy and load worlds without the hassle.

🚀 What It Does

  • Create Templates: Make templates from any world on your server.
  • Load New Worlds: Create fresh worlds from your saved templates.
  • Delete Templates: Remove templates you don't need anymore.
  • Custom Storage: Choose where you want to store your templates.
  • Works with Multiverse-Core: Connects smoothly with Multiverse-Core for better world management.

📋 What You Need

  • Java: Version 11 or newer.
  • Server: Spigot or PaperMC server.
  • Plugin: You need Multiverse-Core installed.

📥 How to Install

Replace "VERSION" with the latest release version and make sure to shade the library.

  1. Add to Your Project: Put this in your build.gradle file:
   dependencies {
       implementation 'com.github.ItsHarshXD:WorldTemplateAPI:VERSION'
   }
  1. Build: Run your build to download everything.

  2. Start Server: Make sure Multiverse-Core is running with your plugin.

🛠️ How to Use

Setting Up Template Storage

First, tell the API where to save your templates:

Path templateDir = Paths.get(getDataFolder().getAbsolutePath(), "templates");

worldTemplateAPI.setTemplateDirectory(templateDir);

try {
    if (!Files.exists(templateDir)) {
        Files.createDirectories(templateDir);
    }
} catch (IOException e) {
    getLogger().severe("Could not create template directory: " + e.getMessage());
}
  • directory: Where you want to store all your templates.

Creating a Template

To make a template from a world that already exists:

CompletableFuture<Boolean> success = worldTemplateAPI.createTemplateFromWorld("worldName", "templateName");
  • worldName: The world you want to copy.
  • templateName: What you want to call the template.

Loading a Template

To create a new world from a template:

CompletableFuture<World> newWorld = worldTemplateAPI.loadTemplate("templateName", "newWorldName");
  • templateName: The template you want to use.
  • newWorldName: What to name the new world.

Deleting a Template

To remove a template you don't need:

CompletableFuture<Boolean> deleted = worldTemplateAPI.deleteTemplate("templateName");
  • templateName: The template you want to delete.

📚 Available Methods

WorldTemplateAPI Methods

  • createTemplateFromWorld(String worldName, String templateName): Makes a template from a world.
  • loadTemplate(String templateName, String targetWorldName): Creates a world from a template.
  • deleteTemplate(String templateName): Removes a template.
  • setTemplateDirectory(Path directory): Sets where templates are stored.

🤝 Want to Help?

I'd love your help! If you have ideas or improvements, fork the repo and send a pull request. Feedback is always welcome!

📝 License

This project uses the MIT License - check the LICENSE file for details.


Questions? Need help? Feel free to reach out. Happy coding with WorldTemplateAPI! 🌟