Class StructureDatabaseHandler
- All Implemented Interfaces:
Runnable
This class handles all operations asynchronously. It is also thread safe.
All CompletableFutures returned are not guaranteed to be on the main thread.
Access this class from StructureHandler.getStructureDatabaseHandler()
Note: This feature needs to be enabled by the user in the config.
-
Constructor Summary
ConstructorsConstructorDescriptionStructureDatabaseHandler(CustomStructures plugin)Construct the StructureDatabaseHandler. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStructure(org.bukkit.Location loc, Structure structure)Add a structure to the database.voidcancel()findNearby(NearbyStructuresRequest request)Find structures closest to a certain location.getStructure(org.bukkit.Location location)Get a structure from the structure database using its location.CompletableFuture<List<org.bukkit.Location>>getStructureLocations(Structure structure)Get all the locations of a structure.voidrun()Methods inherited from class org.bukkit.scheduler.BukkitRunnable
getTaskId, isCancelled, runTask, runTaskAsynchronously, runTaskLater, runTaskLaterAsynchronously, runTaskTimer, runTaskTimerAsynchronously
-
Constructor Details
-
StructureDatabaseHandler
Construct the StructureDatabaseHandler.For internal use only. Access through
StructureHandler.getStructureDatabaseHandler().Throws
StructureDatabaseExceptionif it cannot connect to the SQLite database successfully.- Parameters:
plugin- The instance of the plugin.
-
-
Method Details
-
addStructure
Add a structure to the database.Internal Use Only. To manually add a structure after spawning it through
Structure.spawn(Location), useStructureHandler.putSpawnedStructure(Location, Structure)instead!- Parameters:
loc- The location of the structure.structure- The structure.
-
getStructure
Get a structure from the structure database using its location.The completed future completes exceptionally with
StructureNotFoundExceptionif a structure at the specified location cannot be found.It also completes exceptionally with
UsageStructureDatabaseExceptionif a SQL error occurs when attempting to retrieve the structure.databaseHandler.getStructure(myLocation)
.thenAccept(structure -> {
System.out.println(structure.getName());
})
.exceptionally(exception -> {
System.out.println("Structure not found or an error occurred");
return null;
});
- Parameters:
location- The location to get.- Returns:
- The completable future that this will return.
-
findNearby
Find structures closest to a certain location. Customize the request usingNearbyStructuresRequest.Warning: This operation is (somewhat) expensive on the server. Use sparingly.
The completed future could be completed exceptionally. (
RateLimitExceptionorStructureDatabaseException).- Parameters:
request- The nearby structures request to be made.- Returns:
- A completable future containing the NearbyStructuresResponse.
-
getStructureLocations
Get all the locations of a structure.- Parameters:
structure- The structure to find the locations for.- Returns:
- A completable future containing the list of locations.
-
run
public void run() -
cancel
- Overrides:
cancelin classorg.bukkit.scheduler.BukkitRunnable- Throws:
IllegalStateException
-