Class StructureRetrieverFactory

java.lang.Object
nl.pim16aap2.animatedarchitecture.core.structures.retriever.StructureRetrieverFactory

public final class StructureRetrieverFactory extends Object
Represents the factory for 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.