Class StructureDatabaseHandler

java.lang.Object
org.bukkit.scheduler.BukkitRunnable
com.ryandw11.structure.io.StructureDatabaseHandler
All Implemented Interfaces:
Runnable

public class StructureDatabaseHandler extends org.bukkit.scheduler.BukkitRunnable
Handles the saving and reading of structures from the spawned structure database.

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 Details

  • Method Details

    • addStructure

      public void addStructure(org.bukkit.Location loc, Structure structure)
      Add a structure to the database.

      Internal Use Only. To manually add a structure after spawning it through Structure.spawn(Location), use StructureHandler.putSpawnedStructure(Location, Structure) instead!

      Parameters:
      loc - The location of the structure.
      structure - The structure.
    • getStructure

      public CompletableFuture<Structure> getStructure(org.bukkit.Location location)
      Get a structure from the structure database using its location.

      The completed future completes exceptionally with StructureNotFoundException if a structure at the specified location cannot be found.

      It also completes exceptionally with StructureDatabaseException if a SQL error occurs when attempting to retrieve the structure.

      Usage 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 using NearbyStructuresRequest.

      Warning: This operation is (somewhat) expensive on the server. Use sparingly.

      The completed future could be completed exceptionally. (RateLimitException or StructureDatabaseException).

      Parameters:
      request - The nearby structures request to be made.
      Returns:
      A completable future containing the NearbyStructuresResponse.
    • getStructureLocations

      public CompletableFuture<List<org.bukkit.Location>> getStructureLocations(Structure structure)
      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

      public void cancel() throws IllegalStateException
      Overrides:
      cancel in class org.bukkit.scheduler.BukkitRunnable
      Throws:
      IllegalStateException