Interface StructureManager
-
Method Summary
Modifier and TypeMethodDescriptionCreates a copy of this structure.Creates a new empty structure.void
deleteStructure(@NotNull NamespacedKey structureKey)
Unregisters the specified structure and deletes itsstructure file
from the primary world folder.void
deleteStructure(@NotNull NamespacedKey structureKey, boolean unregister)
Deletes thestructure file
for the specified structure from the primary world folder.getStructure(@NotNull NamespacedKey structureKey)
Gets a registered Structure.getStructureFile(@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.Gets the currently registered structures.loadStructure(@NotNull File file)
Reads a Structure from disk.loadStructure(@NotNull InputStream inputStream)
Reads a Structure from a stream.loadStructure(@NotNull NamespacedKey structureKey)
Loads the structure for the specified key and automatically registers it.loadStructure(@NotNull NamespacedKey structureKey, boolean register)
Loads a structure for the specified key and optionallyregisters
it.registerStructure(@NotNull NamespacedKey structureKey, @NotNull Structure structure)
Registers the given structure.void
saveStructure(@NotNull File file, @NotNull Structure structure)
Save a structure to a file.void
saveStructure(@NotNull OutputStream outputStream, @NotNull Structure structure)
Save a structure to a stream.void
saveStructure(@NotNull NamespacedKey structureKey)
Saves the currentlyregistered structure
for the specifiedkey
to the primary world folder as specified by {#getStructureFile(NamespacedKey}.void
saveStructure(@NotNull NamespacedKey structureKey, @NotNull Structure structure)
Saves a structure with a given key to the primary world folder.unregisterStructure(@NotNull 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 @Nullable Structure registerStructure(@NotNull @NotNull NamespacedKey structureKey, @NotNull @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
@Nullable @Nullable Structure loadStructure(@NotNull @NotNull NamespacedKey structureKey, boolean register)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 @NotNull NamespacedKey structureKey, @NotNull @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
void deleteStructure(@NotNull @NotNull NamespacedKey structureKey, boolean unregister) throws IOExceptionDeletes 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
@NotNull @NotNull Structure loadStructure(@NotNull @NotNull InputStream inputStream) throws IOExceptionReads 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 IOExceptionSave 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 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
-