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

public abstract class BaseCommand extends Object
Represents the base AnimatedArchitecture command.

This handles all the basics shared by all commands and contains some utility methods for common actions.

  • Field Details

  • Constructor Details

  • Method Details

    • getCommand

      public abstract CommandDefinition getCommand()
      Gets the CommandDefinition that contains the definition of this BaseCommand.
      Returns:
      The CommandDefinition that contains the definition of this BaseCommand.
    • 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 the commandSender has access to a given StructureAttribute for a given structure.
      Parameters:
      structure - The structure to check.
      structureAttribute - The StructureAttribute to check.
      hasBypassPermission - Whether the commandSender has 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 this BaseCommand is available for IPlayers.
      Returns:
      True if an IPlayer can execute this command.
    • availableForNonPlayers

      protected boolean availableForNonPlayers()
      Checks if this BaseCommand is available for non-IPlayers (e.g. the server).
      Returns:
      True if a non-IPlayer can execute this command.
    • run

      public final CompletableFuture<?> run()
      Executes the command.
      Returns:
      The result of the execution.
    • runWithRawResult

      public final CompletableFuture<?> runWithRawResult(int timeout, TimeUnit timeUnit)
      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

      public final CompletableFuture<?> 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

      protected final CompletableFuture<?> startExecution()
      Starts the execution of this command. It performs the permission check (See hasPermission()) and runs executeCommand(PermissionsStatus) if the ICommandSender has access to either the user or the admin permission.
    • executeCommand

      protected abstract CompletableFuture<?> executeCommand(PermissionsStatus permissions)
      Executes the command. This method is only called if validateInput() and hasPermission() are true.

      Note that this method is called asynchronously.

      Parameters:
      permissions - Whether the ICommandSender has user and/or admin permissions.
      Returns:
      The future of the command execution.
    • getStructure

      protected CompletableFuture<Structure> getStructure(StructureRetriever structureRetriever, PermissionLevel permissionLevel)
      Attempts to get an Structure based on the provided StructureRetrieverFactory and the current ICommandSender.

      If no structure is found, the ICommandSender will be informed.

      Parameters:
      structureRetriever - The StructureRetrieverFactory to use
      permissionLevel - The minimum PermissionLevel required to retrieve the structure.
      Returns:
      The Structure if one could be retrieved.
    • hasPermission

      protected CompletableFuture<PermissionsStatus> hasPermission()
      Checks if the ICommandSender has the required permissions to use this command. See CommandDefinition.getUserPermission() and CommandDefinition.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

      public @NonNull String toString()
      Overrides:
      toString in class Object
    • getCommandSender

      public ICommandSender 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).