Class DatabaseManager
java.lang.Object
nl.pim16aap2.animatedarchitecture.core.api.restartable.Restartable
nl.pim16aap2.animatedarchitecture.core.managers.DatabaseManager
- All Implemented Interfaces:
IDebuggable,IRestartable
Manages all database interactions.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents the result of an action requested from the database.static final classstatic final recordRepresents the identifier of a structure.static final recordContains the result of an attempt to insert a structure into the database. -
Constructor Summary
ConstructorsConstructorDescriptionDatabaseManager(RestartableHolder restartableHolder, IStorage storage, StructureDeletionManager structureDeletionManager, dagger.Lazy<PowerBlockManager> powerBlockManager, IAnimatedArchitectureEventFactory animatedArchitectureEventFactory, IAnimatedArchitectureEventCaller animatedArchitectureEventCaller, DebuggableRegistry debuggableRegistry) Constructs a newDatabaseManager. -
Method Summary
Modifier and TypeMethodDescriptionaddOwner(Structure structure, IPlayer player, PermissionLevel permission) addOwner(Structure structure, IPlayer player, PermissionLevel permission, @Nullable IPlayer responsible) Adds a player as owner to aStructureat a given level of ownership.addStructure(Structure structure) addStructure(Structure structure, @Nullable IPlayer responsible) Inserts aStructureinto the database.countStructuresByName(String structureName) The number ofStructures in the database with a specific name.countStructuresOwnedByPlayer(UUID playerUUID) Gets the number ofStructures owned by a player.countStructuresOwnedByPlayer(UUID playerUUID, String structureName) Counts the number ofStructures with a specific name owned by a player.deleteStructure(Structure structure) deleteStructure(Structure structure, @Nullable IPlayer responsible) Removes aStructurefrom the database.ObtainsIStorage.DatabaseStatethe database is in.Gets the debug information for this object.getIdentifiersFromPartial(String input, @Nullable IPlayer player, PermissionLevel maxPermission, Collection<Property<?>> properties) Retrieves allDatabaseManager.StructureIdentifiers that start with the provided input.getPlayerData(String playerName) Tries to get all the players with a given name.getPlayerData(UUID uuid) Tries to find thePlayerDatafor a player with the givenUUID.getStructure(long structureUID) Gets theStructurewith a specific UID.getStructure(UUID uuid, long structureUID) Gets theStructurewith the given UID owned by the player.getStructure(IPlayer player, long structureUID) Gets theStructurewith the given UID owned by the player.getStructures(String name) Gets allStructures with a specific name, regardless over ownership.getStructures(UUID playerUUID) Gets allStructureowned by a player.getStructures(UUID playerUUID, String structureID) Gets allStructureowned by a player.getStructures(IPlayer player) SeegetStructures(UUID).getStructures(IPlayer player, String name) getStructures(IPlayer player, String name, PermissionLevel maxPermission) Gets allStructureowned by a player with a specific name.getStructuresInChunk(int chunkX, int chunkZ) Gets a list of structure UIDs that have their rotation point in a given chunk.getStructuresOfType(String typeName) Obtains all structures of a given type.getStructuresOfType(String typeName, int version) Obtains all structures of a specific version of a given type.voidHandles the initialization.removeOwner(Structure structure, UUID playerUUID) removeOwner(Structure structure, UUID playerUUID, @Nullable IPlayer responsible) removeOwner(Structure structure, IPlayer player) removeOwner(Structure structure, IPlayer player, @Nullable IPlayer responsible) voidshutDown()Handles a shutdown.syncStructureData(StructureSnapshot snapshot) Updates the all data of anStructure.updatePlayer(IPlayer player) Updates the name of a player in the database, to make sure the player's name and UUID don't go out of sync.
-
Constructor Details
-
DatabaseManager
@Inject public DatabaseManager(RestartableHolder restartableHolder, IStorage storage, StructureDeletionManager structureDeletionManager, dagger.Lazy<PowerBlockManager> powerBlockManager, IAnimatedArchitectureEventFactory animatedArchitectureEventFactory, IAnimatedArchitectureEventCaller animatedArchitectureEventCaller, DebuggableRegistry debuggableRegistry) Constructs a newDatabaseManager.- Parameters:
restartableHolder- The object managing restarts for this object.storage- TheIStorageto use for all database calls.
-
-
Method Details
-
getDatabaseState
ObtainsIStorage.DatabaseStatethe database is in.- Returns:
- The
IStorage.DatabaseStatethe database is in.
-
initialize
public void initialize()Description copied from interface:IRestartableHandles the initialization.- Specified by:
initializein interfaceIRestartable
-
shutDown
public void shutDown()Description copied from interface:IRestartableHandles a shutdown.- Specified by:
shutDownin interfaceIRestartable
-
addStructure
Inserts aStructureinto the database and assumes that the structure was NOT created by anIPlayer. SeeaddStructure(Structure, IPlayer).- Parameters:
structure- The newStructure.- Returns:
- The future result of the operation. If the operation was successful this will be true.
-
addStructure
public CompletableFuture<DatabaseManager.StructureInsertResult> addStructure(Structure structure, @Nullable @Nullable IPlayer responsible) Inserts aStructureinto the database.- Parameters:
structure- The newStructure.responsible- TheIPlayerresponsible for creating the structure. This is used for theIStructurePrepareCreateEventand theIStructureCreatedEvent. This may be null.- Returns:
- The future result of the operation.
-
deleteStructure
Removes aStructurefrom the database and assumes that the structure was NOT deleted by anIPlayer. SeedeleteStructure(Structure, IPlayer).- Parameters:
structure- The structure that will be deleted.- Returns:
- The future result of the operation.
-
deleteStructure
public CompletableFuture<DatabaseManager.ActionResult> deleteStructure(Structure structure, @Nullable @Nullable IPlayer responsible) Removes aStructurefrom the database.- Parameters:
structure- The structure that will be deleted.responsible- TheIPlayerresponsible for creating the structure. This is used for theIStructurePrepareDeleteEvent. This may be null.- Returns:
- The future result of the operation.
-
getStructuresInChunk
Gets a list of structure UIDs that have their rotation point in a given chunk.- Parameters:
chunkX- The x-coordinate of the chunk (in chunk space).chunkZ- The z-coordinate of the chunk (in chunk space).- Returns:
- A list of structure UIDs that have their rotation point in a given chunk.
-
getStructuresOfType
Obtains all structures of a given type.- Parameters:
typeName- The name of the type. SeeStructureType.getFullKey().- Returns:
- All structures of the given type.
-
getStructuresOfType
Obtains all structures of a specific version of a given type.- Parameters:
typeName- The name of the type. SeeStructureType.getFullKey().version- The version of the type.- Returns:
- All structures of the given type and version.
-
getStructures
-
getStructures
-
getStructures
Gets allStructureowned by a player. -
getStructures
SeegetStructures(UUID). -
getStructures
public CompletableFuture<List<Structure>> getStructures(IPlayer player, String name, PermissionLevel maxPermission) Gets allStructureowned by a player with a specific name. -
getStructures
Gets allStructures with a specific name, regardless over ownership. -
updatePlayer
Updates the name of a player in the database, to make sure the player's name and UUID don't go out of sync.- Parameters:
player- The Player.- Returns:
- The future result of the operation. If the operation was successful this will be true.
-
getPlayerData
Tries to find thePlayerDatafor a player with the givenUUID.- Parameters:
uuid- TheUUIDof a player.- Returns:
- The
PlayerDatathat represents the player.
-
getPlayerData
Tries to get all the players with a given name. Because names are not unique, this may result in any number of matches.If you know the player's UUID, it is recommended to use
getPlayerData(UUID)instead.- Parameters:
playerName- The name of the player(s).- Returns:
- All the players with the given name.
-
getStructure
Gets theStructurewith a specific UID. -
getStructure
Gets theStructurewith the given UID owned by the player. If the given player does not own the provided structure, no structure will be returned. -
getStructure
Gets theStructurewith the given UID owned by the player. If the given player does not own the * provided structure, no structure will be returned. -
countStructuresOwnedByPlayer
Gets the number ofStructures owned by a player. -
countStructuresOwnedByPlayer
public CompletableFuture<Integer> countStructuresOwnedByPlayer(UUID playerUUID, String structureName) Counts the number ofStructures with a specific name owned by a player. -
countStructuresByName
The number ofStructures in the database with a specific name. -
addOwner
public CompletableFuture<DatabaseManager.ActionResult> addOwner(Structure structure, IPlayer player, PermissionLevel permission) Adds a player as owner to aStructureat a given level of ownership and assumes that the structure was NOT deleted by anIPlayer. SeeaddOwner(Structure, IPlayer, PermissionLevel, IPlayer). -
addOwner
public CompletableFuture<DatabaseManager.ActionResult> addOwner(Structure structure, IPlayer player, PermissionLevel permission, @Nullable @Nullable IPlayer responsible) Adds a player as owner to aStructureat a given level of ownership. -
removeOwner
public CompletableFuture<DatabaseManager.ActionResult> removeOwner(Structure structure, IPlayer player) -
removeOwner
public CompletableFuture<DatabaseManager.ActionResult> removeOwner(Structure structure, IPlayer player, @Nullable @Nullable IPlayer responsible) - Parameters:
structure- TheStructure.player- TheIPlayer.responsible- TheIPlayerresponsible for creating the structure. This is used for theIStructurePrepareDeleteEvent. This may be null.- Returns:
- The future result of the operation.
-
removeOwner
public CompletableFuture<DatabaseManager.ActionResult> removeOwner(Structure structure, UUID playerUUID) Remove aIPlayeras owner of aStructureand assumes that the structure was NOT deleted by anIPlayer. SeeremoveOwner(Structure, UUID, IPlayer). -
removeOwner
public CompletableFuture<DatabaseManager.ActionResult> removeOwner(Structure structure, UUID playerUUID, @Nullable @Nullable IPlayer responsible) - Parameters:
structure- TheStructure.playerUUID- TheUUIDof theIPlayer.responsible- TheIPlayerresponsible for creating the structure. This is used for theIStructurePrepareDeleteEvent. This may be null.- Returns:
- The future result of the operation.
-
syncStructureData
public CompletableFuture<DatabaseManager.ActionResult> syncStructureData(StructureSnapshot snapshot) Updates the all data of anStructure. This includes both the base data and the type-specific data.- Parameters:
snapshot- TheStructurethat describes the base data of structure.- Returns:
- The result of the operation.
-
getIdentifiersFromPartial
public CompletableFuture<List<DatabaseManager.StructureIdentifier>> getIdentifiersFromPartial(String input, @Nullable @Nullable IPlayer player, PermissionLevel maxPermission, Collection<Property<?>> properties) Retrieves allDatabaseManager.StructureIdentifiers that start with the provided input.For example, this method can retrieve the identifiers "1", "10", "11", "100", etc from an input of "1" or "MyDoor", "MyPortcullis", "MyOtherStructure", etc. from an input of "My".
- Parameters:
input- The partial identifier to look for.player- The player that should own the structures. May be null to disregard ownership.properties- The properties that the structures must have. When specified, only structures that have all of these properties will be returned.- Returns:
- All
DatabaseManager.StructureIdentifiers that start with the provided input.
-
getDebugInformation
Description copied from interface:IDebuggableGets the debug information for this object.- Specified by:
getDebugInformationin interfaceIDebuggable- Returns:
- The debug information or null if there's nothing to log at this time.
-