Interface StructureManager
-
Method Summary
Modifier and TypeMethodDescriptionCreates a copy of this structure.Creates a new empty structure.void
deleteStructure(NamespacedKey structureKey)
Unregisters the specified structure and deletes itsstructure file
from the primary world folder.void
deleteStructure(NamespacedKey structureKey, boolean unregister)
Deletes thestructure file
for the specified structure from the primary world folder.getStructure(NamespacedKey structureKey)
Gets a registered Structure.getStructureFile(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.Gets the currently registered structures.loadStructure(File file)
Reads a Structure from disk.loadStructure(InputStream inputStream)
Reads a Structure from a stream.loadStructure(NamespacedKey structureKey)
Loads the structure for the specified key and automatically registers it.loadStructure(NamespacedKey structureKey, boolean register)
Loads a structure for the specified key and optionallyregisters
it.registerStructure(NamespacedKey structureKey, Structure structure)
Registers the given structure.void
saveStructure(File file, Structure structure)
Save a structure to a file.void
saveStructure(OutputStream outputStream, Structure structure)
Save a structure to a stream.void
saveStructure(NamespacedKey structureKey)
Saves the currentlyregistered structure
for the specifiedkey
to the primary world folder as specified by {#getStructureFile(NamespacedKey}.void
saveStructure(NamespacedKey structureKey, Structure structure)
Saves a structure with a given key to the primary world folder.unregisterStructure(NamespacedKey structureKey)
Unregisters a structure.
-
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 Structure registerStructure(@NotNull NamespacedKey structureKey, @NotNull Structure structure)Registers the given structure. SeegetStructures()
.- Parameters:
structureKey
- The key for which to register the structurestructure
- The structure to register- Returns:
- The structure for the specified key, or
null
if the structure could not be found.
-
unregisterStructure
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
Loads a structure for the specified key and optionallyregisters
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 structureregister
-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. SeeloadStructure(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
Saves the currentlyregistered structure
for the specifiedkey
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 NamespacedKey structureKey, @NotNull Structure structure) throws IOExceptionSaves a structure with a given key to the primary world folder.- Parameters:
structureKey
- The key for which to save the structure forstructure
- The structure to save for this structureKey- Throws:
IOException
-
deleteStructure
Unregisters the specified structure and deletes itsstructure 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
Deletes thestructure 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 removeunregister
- 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
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
Reads a Structure from a stream.- Parameters:
inputStream
- The file of the structure- Returns:
- The read Structure
- Throws:
IOException
-
saveStructure
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 OutputStream outputStream, @NotNull Structure structure) throws IOExceptionSave 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
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
-