Skip to content

Developer API The basics

ImIllusion edited this page May 5, 2023 · 1 revision

Cosmos is a world template management system, which handles all the complicated logic behind the process of creating a template, choosing a location to paste it on, actually pasting it and handling any unloads, as well as storing the templates in a database.

But what is a template?

A TemplatedArea is a fixed-size representation of a pre-defined area of blocks that can be pasted in any given location. Here's a basic example on how to paste a template.

Player player = ...;
TemplatedArea template = ...;

Location pasteLocation = player.getLocation();

template.paste(pasteLocation).thenRun(() -> {
    player.sendMessage("The template has finished pasting!");
});

How can I unload such a template?

A PastedArea is an extension of a TemplatedArea, but contains information about where it is located. A PastedArea is created when a template is pasted, and is returned on the Future provided by the paste method.

Here's a basic example on how to unload a template.

Player player = ...;

template.paste(pasteLocation).thenAccept(pastedArea -> {
    // store this somewhere, or just unload after a bit
    player.sendMessage("The area has been pasted.");

    pastedArea.unload().thenRun(() -> {
        player.sendMessage("The area has been unloaded.");
    });
});

How can I create one?

Check the Development API - Serializers wiki for that

How can I get one from a database?

Check the Development API - Data Containers wiki for that