Class BaseCommand
java.lang.Object
nl.pim16aap2.animatedarchitecture.core.commands.BaseCommand
- Direct Known Subclasses:
Cancel, Confirm, Debug, InspectPowerBlock, ListStructures, Menu, NewStructure, Restart, SetName, Specify, StopStructures, StructureTargetCommand, UpdateCreator, Version
Represents the base AnimatedArchitecture command.
This handles all the basics shared by all commands and contains some utility methods for common actions.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseCommand(ICommandSender commandSender, IExecutor executor) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanChecks if thisBaseCommandis available for non-IPlayers (e.g. the server).protected booleanChecks if thisBaseCommandis available forIPlayers.protected abstract CompletableFuture<?> executeCommand(PermissionsStatus permissions) Executes the command.abstract CommandDefinitionGets theCommandDefinitionthat contains the definition of thisBaseCommand.The entity (e.g. player, server, or command block) that initiated the command.protected CompletableFuture<Structure> getStructure(StructureRetriever structureRetriever, PermissionLevel permissionLevel) Attempts to get anStructurebased on the providedStructureRetrieverFactoryand the currentICommandSender.protected booleanhasAccessToAttribute(Structure structure, StructureAttribute structureAttribute, boolean hasBypassPermission) Checks if thecommandSenderhas access to a givenStructureAttributefor a given structure.protected CompletableFuture<PermissionsStatus> Checks if theICommandSenderhas the required permissions to use this command.final CompletableFuture<?> run()Executes the command.final CompletableFuture<?> Executes the command.final CompletableFuture<?> runWithRawResult(int timeout, TimeUnit timeUnit) Executes the command with a timeout.protected final voidprotected final CompletableFuture<?> Starts the execution of this command.@NonNull StringtoString()protected voidChecks if the input is valid before starting any potentially expensive tasks.
-
Field Details
-
executor
-
localizer
-
-
Constructor Details
-
BaseCommand
-
-
Method Details
-
getCommand
Gets theCommandDefinitionthat contains the definition of thisBaseCommand.- Returns:
- The
CommandDefinitionthat contains the definition of thisBaseCommand.
-
validateInput
protected void validateInput()Checks if the input is valid before starting any potentially expensive tasks. -
hasAccessToAttribute
protected boolean hasAccessToAttribute(Structure structure, StructureAttribute structureAttribute, boolean hasBypassPermission) Checks if thecommandSenderhas access to a givenStructureAttributefor a given structure.- Parameters:
structure- The structure to check.structureAttribute- TheStructureAttributeto check.hasBypassPermission- Whether thecommandSenderhas bypass permission or not.- Returns:
- True if the command sender has access to the provided attribute for the given structure.
-
availableForPlayers
protected boolean availableForPlayers()Checks if thisBaseCommandis available forIPlayers.- Returns:
- True if an
IPlayercan execute this command.
-
availableForNonPlayers
protected boolean availableForNonPlayers()Checks if thisBaseCommandis available for non-IPlayers (e.g. the server).- Returns:
- True if a non-
IPlayercan execute this command.
-
run
-
runWithRawResult
Executes the command with a timeout.This method does not handle exceptions. This is useful if you want to handle exceptions yourself.
- Parameters:
timeout- The timeout.timeUnit- The time unit of the timeout.- Returns:
- The result of the execution.
-
runWithRawResult
Executes the command.This method is the same as
run(), but it does not handle exceptions. This is useful if you want to handle exceptions yourself.- Returns:
- The result of the execution.
-
sendGenericErrorMessage
protected final void sendGenericErrorMessage() -
startExecution
Starts the execution of this command. It performs the permission check (SeehasPermission()) and runsexecuteCommand(PermissionsStatus)if theICommandSenderhas access to either the user or the admin permission. -
executeCommand
Executes the command. This method is only called ifvalidateInput()andhasPermission()are true.Note that this method is called asynchronously.
- Parameters:
permissions- Whether theICommandSenderhas user and/or admin permissions.- Returns:
- The future of the command execution.
-
getStructure
protected CompletableFuture<Structure> getStructure(StructureRetriever structureRetriever, PermissionLevel permissionLevel) Attempts to get anStructurebased on the providedStructureRetrieverFactoryand the currentICommandSender.If no structure is found, the
ICommandSenderwill be informed.- Parameters:
structureRetriever- TheStructureRetrieverFactoryto usepermissionLevel- The minimumPermissionLevelrequired to retrieve the structure.- Returns:
- The
Structureif one could be retrieved.
-
hasPermission
Checks if theICommandSenderhas the required permissions to use this command. SeeCommandDefinition.getUserPermission()andCommandDefinition.getAdminPermission().- Returns:
- A pair of booleans that indicates whether the user has access to the user and admin permission nodes respectively. For both, true indicates that they do have access to the node and false that they do not.
-
toString
-
getCommandSender
The entity (e.g. player, server, or command block) that initiated the command.This is the entity that is held responsible for the command (i.e. their permissions are checked, and they will receive error/success/information messages when applicable).
-