Interface StructureManager


public interface StructureManager
  • Method Details

    • getStructures

      Gets the currently registered structures.

      These are the currently loaded structures that the StructureManager is aware of. When a structure block refers to a structure, these structures are checked first. If the specified structure is not found among the currently registered structures, the StructureManager may dynamically read the structure from the primary world folder, DataPacks, or the server's own resources. Structures can be registered via registerStructure(NamespacedKey, Structure)

      Returns:
      an unmodifiable shallow copy of the currently registered structures
    • getStructure

      Gets a registered Structure.
      Parameters:
      structureKey - The key for which to get the structure
      Returns:
      The structure that belongs to the structureKey or null if there is none registered for that key.
    • registerStructure

      @Nullable @Nullable Structure registerStructure(@NotNull @NotNull NamespacedKey structureKey, @NotNull @NotNull Structure structure)
      Registers the given structure. See getStructures().
      Parameters:
      structureKey - The key for which to register the structure
      structure - The structure to register
      Returns:
      The structure for the specified key, or null if the structure could not be found.
    • unregisterStructure

      @Nullable @Nullable Structure unregisterStructure(@NotNull @NotNull NamespacedKey structureKey)
      Unregisters a structure. Unregisters the specified structure. If the structure still exists in the primary world folder, a DataPack, or is part of the server's own resources, it may be loaded and registered again when it is requested by a plugin or the server itself.
      Parameters:
      structureKey - The key for which to save the structure for
      Returns:
      The structure that was registered for that key or null if there was none
    • loadStructure

      @Nullable @Nullable Structure loadStructure(@NotNull @NotNull NamespacedKey structureKey, boolean register)
      Loads a structure for the specified key and optionally registers it.

      This will first check the already loaded registered structures, and otherwise load the structure from the primary world folder, DataPacks, and the server's own resources (in this order).

      When loading the structure from the primary world folder, the given key is translated to a file as specified by getStructureFile(NamespacedKey).

      Parameters:
      structureKey - The key for which to load the structure
      register - true to register the loaded structure.
      Returns:
      The structure, or null if no structure was found for the specified key
    • loadStructure

      Loads the structure for the specified key and automatically registers it. See loadStructure(NamespacedKey, boolean).
      Parameters:
      structureKey - The key for which to load the structure
      Returns:
      The structure for the specified key, or null if the structure could not be found.
    • saveStructure

      void saveStructure(@NotNull @NotNull NamespacedKey structureKey)
      Saves the currently registered structure for the specified key to the primary world folder as specified by {#getStructureFile(NamespacedKey}.
      Parameters:
      structureKey - The key for which to save the structure for
    • saveStructure

      void saveStructure(@NotNull @NotNull NamespacedKey structureKey, @NotNull @NotNull Structure structure) throws IOException
      Saves a structure with a given key to the primary world folder.
      Parameters:
      structureKey - The key for which to save the structure for
      structure - The structure to save for this structureKey
      Throws:
      IOException
    • deleteStructure

      void deleteStructure(@NotNull @NotNull NamespacedKey structureKey) throws IOException
      Unregisters the specified structure and deletes its structure file from the primary world folder. Note that this method cannot be used to delete vanilla Minecraft structures, or structures from DataPacks. Unregistering these structures will however work fine.
      Parameters:
      structureKey - The key of the structure to remove
      Throws:
      IOException - If the file could not be removed for some reason.
    • deleteStructure

      void deleteStructure(@NotNull @NotNull NamespacedKey structureKey, boolean unregister) throws IOException
      Deletes the structure file for the specified structure from the primary world folder. Note that this method cannot be used to delete vanilla Minecraft structures, or structures from DataPacks. Unregistering these structures will however work fine.
      Parameters:
      structureKey - The key of the structure to remove
      unregister - Whether to also unregister the specified structure if it is currently loaded.
      Throws:
      IOException - If the file could not be removed for some reason.
    • getStructureFile

      @NotNull @NotNull File getStructureFile(@NotNull @NotNull NamespacedKey structureKey)
      Gets the location where a structure file would exist in the primary world directory based on the NamespacedKey using the format world/generated/{NAMESPACE}/structures/{KEY}.nbt. This method will always return a file, even if none exists at the moment.
      Parameters:
      structureKey - The key to build the filepath from.
      Returns:
      The location where a file with this key would be.
    • loadStructure

      Reads a Structure from disk.
      Parameters:
      file - The file of the structure
      Returns:
      The read structure
      Throws:
      IOException - when the given file can not be read from
    • loadStructure

      @NotNull @NotNull Structure loadStructure(@NotNull @NotNull InputStream inputStream) throws IOException
      Reads a Structure from a stream.
      Parameters:
      inputStream - The file of the structure
      Returns:
      The read Structure
      Throws:
      IOException
    • saveStructure

      void saveStructure(@NotNull @NotNull File file, @NotNull @NotNull Structure structure) throws IOException
      Save a structure to a file. This will overwrite a file if it already exists.
      Parameters:
      file - the target to save to.
      structure - the Structure to save.
      Throws:
      IOException - when the given file can not be written to.
    • saveStructure

      void saveStructure(@NotNull @NotNull OutputStream outputStream, @NotNull @NotNull Structure structure) throws IOException
      Save a structure to a stream.
      Parameters:
      outputStream - the stream to write to.
      structure - the Structure to save.
      Throws:
      IOException - when the given file can not be written to.
    • createStructure

      @NotNull @NotNull Structure createStructure()
      Creates a new empty structure.
      Returns:
      an empty structure.
    • copy

      Creates a copy of this structure.
      Parameters:
      structure - The structure to copy
      Returns:
      a copy of the structure