Class StructureLoader

java.lang.Object
com.github.darksoulq.abyssallib.world.structure.StructureLoader

public class StructureLoader extends Object
Manages the loading, saving, and registration of serialized structure files. This class scans the structures/ directory and automatically registers valid JSON and compressed structural files into the Registries.STRUCTURES registry. It relies on namespaced subfolders to determine the unique Key for each structure.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Initializes the structure folder and performs a recursive scan for valid files.
    static Structure
    load(Path path)
    Loads and deserializes a structure from a specific file path on the disk.
    static Structure
    loadResource(org.bukkit.plugin.Plugin plugin, String resourcePath)
    Loads a structure embedded within a plugin's internal JAR resources.
    static boolean
    save(net.kyori.adventure.key.Key id, Structure structure)
    Serializes and saves a structure to the disk using the specified identifier.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • StructureLoader

      public StructureLoader()
  • Method Details

    • load

      public static void load()
      Initializes the structure folder and performs a recursive scan for valid files. Found files ending in .struct or .json are processed and automatically registered into the internal structure registry.
    • load

      public static Structure load(Path path)
      Loads and deserializes a structure from a specific file path on the disk. Supports both raw JSON files and GZIP compressed .struct files.
      Parameters:
      path - The Path pointing to the target file.
      Returns:
      The deserialized Structure instance, or null if parsing fails.
    • loadResource

      public static Structure loadResource(org.bukkit.plugin.Plugin plugin, String resourcePath)
      Loads a structure embedded within a plugin's internal JAR resources. Supports both raw JSON files and GZIP compressed .struct files.
      Parameters:
      plugin - The Plugin instance owning the internal resource.
      resourcePath - The internal String path within the JAR (e.g., "assets/myplugin/structures/house.json").
      Returns:
      The deserialized Structure instance, or null if the resource is missing or invalid.
    • save

      public static boolean save(net.kyori.adventure.key.Key id, Structure structure)
      Serializes and saves a structure to the disk using the specified identifier. The file is automatically saved at structures/<namespace>/<path>.struct utilizing GZIP compression to minimize disk footprint.
      Parameters:
      id - The Key defining the namespace and file name layout.
      structure - The Structure instance to serialize and save.
      Returns:
      True if the I/O write operation was successful, false otherwise.