Class StructureRetrieverFactory
StructureRetriever and StructureFinder instances.
Structure Retrievers
This factory contains several methods of creating new structure retrievers using various input types:
// Get the retriever for the structure with UID 1:
structureRetrieverFactory.of(1L);
structureRetrieverFactory.of("1");
// Get the retriever for all structures named "MyDoor":
structureRetrieverFactory.of("MyDoor");
// Wrap an existing structure in a retriever:
structureRetrieverFactory.of(myStructure);
Structure Finders
This factory also contains methods for creating new structure finders using the "search" methods.
The finders are used to find structures based on partial information.
Each finder is associated with an ICommandSender that is responsible for the finder. This is used to
determine which structures the finder is allowed to find. If the command sender is not a player, the finder will be
able to find all structures. If it is a player, the finder will only be able to find structures that the player has
permission to access. If not specified, only structures that were created by the player will be found.
For example, to find all structures whose name starts with "My", you can use:
// Find all structures whose name starts with "My" that were created by the player:
structureRetrieverFactory.find(player, "My");
// Find all structures whose name starts with "My" that the player either created
// or is admin/user of:
structureRetrieverFactory.find(player, "My", PermissionLevel.USER);
The StructureFinderCache is used to cache the finders. When creating a finder, you can choose whether to use
this cache. If the cache is used (which it is unless otherwise specified), the finder will first check if there is a
cached result for the given command sender. If there is, the cached result will be used and updated using the
provided input. If there is no cached result, a new finder will be created and cached. The cache is backed by a
TimedCache, so the results are kept in memory for a
few minutes after the last time they were accessed. When specified to not use the cache, the search method will
always create a new finder instance.
The cache is used to allow calling the search method with progressive input without keeping track of the finder instance yourself. For example, you can call the method with "My" and then with "MyW" to first find all structures whose name starts with "My" and then narrow that down to structures whose name starts with "MyW". When calling the search method within the timeout period of the cache, these two calls to the search method will result in a single database query.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents different ways a structure finder can be instantiated. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StructureRetrieverFactory.StructureFinderModeThe default mode to use when searching for structures when not specified.static final PermissionLevelThe default permission level to use when searching for structures when not specified. -
Method Summary
Modifier and TypeMethodDescriptionof(long structureUID) Creates a newStructureRetrieverfrom its UID.Creates a newStructureRetrieverfrom its ID.of(CompletableFuture<Optional<Structure>> structure) Creates a newStructureRetrieverfrom a structure that is being retrieved.Creates a newStructureRetrieverfrom the structure object itself.static StructureRetrieverofStructure(CompletableFuture<Optional<Structure>> structure) Creates a newStructureRetrieverfrom a structure that is still being retrieved.static StructureRetrieverofStructure(@Nullable Structure structure) Creates a newStructureRetrieverfrom the structure object itself.ofStructures(CompletableFuture<List<Structure>> structures) Creates a newStructureRetrieverfrom a list of structures.ofStructures(List<Structure> structures) Creates a newStructureRetrieverfrom a list of structures.search(ICommandSender commandSender, String input, Collection<Property<?>> properties) search(ICommandSender commandSender, String input, PermissionLevel maxPermission, Collection<Property<?>> properties) search(ICommandSender commandSender, String input, StructureRetrieverFactory.StructureFinderMode mode, Collection<Property<?>> properties) search(ICommandSender commandSender, String input, StructureRetrieverFactory.StructureFinderMode mode, PermissionLevel maxPermission, Collection<Property<?>> properties) Gets theStructureFinderto find structures from partial string matches.search(ICommandSender commandSender, String input, StructureRetrieverFactory.StructureFinderMode mode, PermissionLevel maxPermission, Property<?>... properties)
-
Field Details
-
DEFAULT_PERMISSION_LEVEL
The default permission level to use when searching for structures when not specified. -
DEFAULT_MODE
The default mode to use when searching for structures when not specified.
-
-
Method Details
-
of
Creates a newStructureRetrieverfrom its ID.- Parameters:
structureID- The identifier (name or UID) of the structure.- Returns:
- The new
StructureRetriever.
-
of
Creates a newStructureRetrieverfrom its UID.- Parameters:
structureUID- The UID of the structure.- Returns:
- The new
StructureRetriever.
-
of
Creates a newStructureRetrieverfrom the structure object itself.- Parameters:
structure- The structure object itself.- Returns:
- The new
StructureRetriever.
-
of
Creates a newStructureRetrieverfrom a structure that is being retrieved.- Parameters:
structure- The structure that is being retrieved.- Returns:
- The new
StructureRetriever.
-
search
public StructureFinder search(ICommandSender commandSender, String input, StructureRetrieverFactory.StructureFinderMode mode, PermissionLevel maxPermission, Collection<Property<?>> properties) Gets theStructureFinderto find structures from partial string matches.If a
StructureFinderalready exists for this- Parameters:
commandSender- The command sender (e.g. player) that is responsible for searching for the structure.input- The input to use as search query.mode- The mode to use for obtaining aStructureFinderinstance. Defaults toStructureRetrieverFactory.StructureFinderMode.USE_CACHE.maxPermission- The maximum permission (inclusive) of the structure owner of the structures to find. Does not apply if the command sender is not a player. Defaults toPermissionLevel.CREATOR.properties- The properties that the structures must have. When specified, only structures that have all of these properties will be found. When not specified, the properties of the structures are not checked.- Returns:
- The
StructureFinderinstance.
-
search
public StructureFinder search(ICommandSender commandSender, String input, StructureRetrieverFactory.StructureFinderMode mode, PermissionLevel maxPermission, Property<?>... properties) -
search
public StructureFinder search(ICommandSender commandSender, String input, PermissionLevel maxPermission, Collection<Property<?>> properties) Seesearch(ICommandSender, String, StructureFinderMode, PermissionLevel, Collection).Uses
DEFAULT_MODEas the default caching mode. -
search
public StructureFinder search(ICommandSender commandSender, String input, Collection<Property<?>> properties) Seesearch(ICommandSender, String, StructureFinderMode, PermissionLevel, Collection).Uses
DEFAULT_PERMISSION_LEVELas the default permission level.Uses
DEFAULT_MODEas the default caching mode. -
search
public StructureFinder search(ICommandSender commandSender, String input, StructureRetrieverFactory.StructureFinderMode mode, Collection<Property<?>> properties) Seesearch(ICommandSender, String, StructureFinderMode, PermissionLevel, Collection).Uses
PermissionLevel.CREATORas the default permission level. -
ofStructure
Creates a newStructureRetrieverfrom the structure object itself.- Parameters:
structure- The structure object itself.- Returns:
- The new
StructureRetriever.
-
ofStructure
Creates a newStructureRetrieverfrom a structure that is still being retrieved.- Parameters:
structure- The future structure.- Returns:
- The new
StructureRetriever.
-
ofStructures
Creates a newStructureRetrieverfrom a list of structures.- Parameters:
structures- The structures.- Returns:
- The new
StructureRetriever.
-
ofStructures
Creates a newStructureRetrieverfrom a list of structures.- Parameters:
structures- The structures.- Returns:
- The new
StructureRetriever.
-