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
ConstructorsConstructorDescriptionBaseCommand(ICommandSender commandSender, ILocalizer localizer, ITextFactory textFactory) -
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<Optional<Structure>> getStructure(StructureRetriever doorRetriever, PermissionLevel permissionLevel) Attempts to get anStructurebased on the providedStructureRetrieverFactoryand the currentICommandSender.protected booleanhasAccessToAttribute(Structure door, StructureAttribute doorAttribute, 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.protected final CompletableFuture<?> Starts the execution of this command.toString()protected booleanChecks if the input is valid before starting any potentially expensive tasks.
-
Field Details
-
localizer
-
textFactory
-
-
Constructor Details
-
BaseCommand
-
-
Method Details
-
getCommand
Gets theCommandDefinitionthat contains the definition of thisBaseCommand.- Returns:
- The
CommandDefinitionthat contains the definition of thisBaseCommand.
-
validInput
protected boolean validInput()Checks if the input is valid before starting any potentially expensive tasks.- Returns:
- True if the input is valid.
-
hasAccessToAttribute
protected boolean hasAccessToAttribute(Structure door, StructureAttribute doorAttribute, boolean hasBypassPermission) Checks if thecommandSenderhas access to a givenStructureAttributefor a given structure.- Parameters:
door- The structure to check.doorAttribute- 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
Executes the command.- Returns:
- The result of the execution.
-
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 ifvalidInput()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<Optional<Structure>> getStructure(StructureRetriever doorRetriever, PermissionLevel permissionLevel) Attempts to get anStructurebased on the providedStructureRetrieverFactoryand the currentICommandSender.If no structure is found, the
ICommandSenderwill be informed.- Parameters:
doorRetriever- 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).
-