Class StructureTargetCommand
- Direct Known Subclasses:
AddOwner, Delete, Info, Lock, MovePowerBlock, RemoveOwner, SetBlocksToMove, SetOpenDirection, SetOpenStatus, SetProperty
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final recordA simple description of a structure. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final StructureAttributeprotected final StructureRetrieverFields inherited from class BaseCommand
executor, localizer -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedStructureTargetCommand(ICommandSender commandSender, IExecutor executor, StructureRetriever structureRetriever, StructureAttribute structureAttribute) protectedStructureTargetCommand(ICommandSender commandSender, IExecutor executor, StructureRetriever structureRetriever, StructureAttribute structureAttribute, boolean sendUpdatedInfo, @Nullable CommandFactory commandFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected final CompletableFuture<?> executeCommand(PermissionsStatus permissions) Executes the command.Gets all required properties for this command.protected final StructureTargetCommand.StructureDescriptiongetRetrievedStructureDescription(@Nullable Structure retrieverResult) Gets the structure description of theretrieverResult.protected final StructureTargetCommand.StructureDescriptiongetRetrievedStructureDescription(@Nullable Structure retrieverResult, IMessageable messageable) Gets the structure description of theretrieverResult.@Nullable StructureThe result of thestructureRetriever.protected voidhandleDatabaseActionCancelled(Structure retrieverResult) Called byhandleDatabaseActionResult(DatabaseManager.ActionResult, Structure)when the database action was cancelled.protected voidhandleDatabaseActionFail(Structure retrieverResult) Called byhandleDatabaseActionResult(DatabaseManager.ActionResult, Structure)when the database action failed.protected final voidhandleDatabaseActionResult(DatabaseManager.ActionResult result, Structure structure) Handles the results of a database action by informing the user of any non-success states.protected voidhandleDatabaseActionSuccess(Structure retrieverResult) Called byhandleDatabaseActionResult(DatabaseManager.ActionResult, Structure)when the database action was successful.protected booleanhasRequiredProperties(Structure structure, List<Property<?>> requiredProperties) Checks if theStructurehas all the required properties.protected voidChecks if execution of this command is allowed for the givenStructure.protected voidnotifyMissingProperties(Structure structure) Notifies theICommandSenderthat the targetedStructureis missing required properties.protected abstract CompletableFuture<?> performAction(Structure structure) Performs the action of this command on theStructure.protected voidsendUpdatedInfo(Structure structure) Sends the updated info of the structure to theICommandSender.@NonNull StringtoString()Methods inherited from class BaseCommand
availableForNonPlayers, availableForPlayers, getCommand, getCommandSender, getStructure, hasAccessToAttribute, hasPermission, run, runWithRawResult, runWithRawResult, sendGenericErrorMessage, startExecution, validateInput
-
Field Details
-
structureRetriever
-
structureAttribute
-
-
Constructor Details
-
StructureTargetCommand
@Contract("_, _, _, _, true, null -> fail") protected StructureTargetCommand(ICommandSender commandSender, IExecutor executor, StructureRetriever structureRetriever, StructureAttribute structureAttribute, boolean sendUpdatedInfo, @Nullable CommandFactory commandFactory) -
StructureTargetCommand
protected StructureTargetCommand(ICommandSender commandSender, IExecutor executor, StructureRetriever structureRetriever, StructureAttribute structureAttribute)
-
-
Method Details
-
executeCommand
Description copied from class:BaseCommandExecutes the command. This method is only called ifBaseCommand.validateInput()andBaseCommand.hasPermission()are true.Note that this method is called asynchronously.
- Specified by:
executeCommandin classBaseCommand- Parameters:
permissions- Whether theICommandSenderhas user and/or admin permissions.- Returns:
- The future of the command execution.
-
sendUpdatedInfo
Sends the updated info of the structure to theICommandSender.Only applies if
sendUpdatedInfois true.- Parameters:
structure- The structure to send the updated info of.
-
notifyMissingProperties
Notifies theICommandSenderthat the targetedStructureis missing required properties.- Parameters:
structure- TheStructurethat is missing the required properties.
-
isAllowed
protected void isAllowed(Structure structure, boolean bypassPermission) throws CommandExecutionException Checks if execution of this command is allowed for the givenStructure.If it is not allowed, an exception will be thrown.
- Parameters:
structure- TheStructurethat is the target for this command.bypassPermission- Whether theICommandSenderhas bypass access.- Throws:
CommandExecutionException- If theICommandSenderis not allowed to perform the action on theStructure.
-
hasRequiredProperties
Checks if theStructurehas all the required properties. -
performAction
-
getRetrievedStructureDescription
protected final StructureTargetCommand.StructureDescription getRetrievedStructureDescription(@Nullable Structure retrieverResult) Gets the structure description of theretrieverResult.This is a shortcut for
getRetrievedStructureDescription(Structure, IMessageable)withBaseCommand.getCommandSender()as theIMessageable.- Parameters:
retrieverResult- TheStructurethat was retrieved.- Returns:
- The structure description of the
retrieverResult.
-
getRetrievedStructureDescription
protected final StructureTargetCommand.StructureDescription getRetrievedStructureDescription(@Nullable Structure retrieverResult, IMessageable messageable) Gets the structure description of theretrieverResult.- Parameters:
retrieverResult- TheStructurethat was retrieved.messageable- TheIMessageableto use for localization.- Returns:
- The structure description of the
retrieverResult.
-
getRequiredProperties
Gets all required properties for this command.If targeted structure does not have all required properties, the command will not be executed.
By default, this returns an empty list. Subclasses that require specific properties should override this method.
- Returns:
- A list of all required properties.
-
handleDatabaseActionCancelled
Called byhandleDatabaseActionResult(DatabaseManager.ActionResult, Structure)when the database action was cancelled. -
handleDatabaseActionSuccess
Called byhandleDatabaseActionResult(DatabaseManager.ActionResult, Structure)when the database action was successful. -
handleDatabaseActionFail
Called byhandleDatabaseActionResult(DatabaseManager.ActionResult, Structure)when the database action failed. -
handleDatabaseActionResult
protected final void handleDatabaseActionResult(DatabaseManager.ActionResult result, Structure structure) Handles the results of a database action by informing the user of any non-success states.To customize the handling, you can override
handleDatabaseActionFail(Structure),handleDatabaseActionCancelled(Structure), orhandleDatabaseActionSuccess(Structure).- Parameters:
result- The result obtained from the database.structure- The structure that was the target of the command.
-
toString
- Overrides:
toStringin classBaseCommand
-
getStructureRetriever
-
getStructureAttribute
-
getRetrieverResult
The result of thestructureRetriever.This will not be available until after
executeCommand(PermissionsStatus)has started, but beforeperformAction(Structure)is called.Even after the result has been set, it may still be null in case no doors were found.
-