Class Command

java.lang.Object
VASSAL.command.Command
Direct Known Subclasses:
AddPiece, AddSecretNoteCommand, AlertCommand, BasicLogger.LogCommand, BoardPicker.SetBoards, ChangePiece, ChangePropertyCommand, Chatter.DisplayText, ConditionalCommand, Deck.LoadDeckCommand, EventLog.StoreEvents, FlareCommand, GameState.SetupCommand, GlobalProperty.SetGlobalProperty, InviteCommand, LOS_Thread.LOSCommand, ModuleExtension.RegCmd, MovePiece, NewGameIndicator.MarkGameNotNew, NotesWindow.SetPublicNote, NotesWindow.SetScenarioNote, NullCommand, ObscurableOptions.SetAllowed, PlayAudioClipCommand, PlayerRoster.Add, PrivMsgCommand, RemovePiece, SetPersistentPropertyCommand, SetPrivateTextCommand, SoundEncoder.Cmd, SpecialDiceButton.ShowResults, SynchCommand, TextClient.ShowText, TurnTracker.SetTurn

public abstract class Command extends Object
A Command represents an action that needs to be transmitted from one client to another - any action that could change the game state of a multiplayer game should be encapsulated in a Command object. When performing actions during the game, corresponding Commands will be logged in the correct logfile and/or sent to other players through the server. CommandEncoders then serialise (CommandEncoder.encode(VASSAL.command.Command)) and deserialise (CommandEncoder.decode(java.lang.String)) Commands to and from an ascii based representation. Commands are encoded by the generated client prior to being sent across network or saved in a log or save file. Commands are decoded by the receiving client on receipt from the network or on reading from a log or save file. Save game creation is a special case where every GameComponent is asked to generate a Command that when executed will cause itself to be recreated in its present state. The execute() method implements the execution of the command and is called by the receiving client after building the Command using decode. The execute method is sometimes called on the generating client but does not need to be if the Command is being created to encapsulate something that has already happened on the generating client. Commands can be strung together into compound commands with the append(VASSAL.command.Command) method. Although Commands can be linked into compound commands this way, each CommandEncoder need only handle single (not compound) commands.
  • Constructor Details

    • Command

      public Command()
  • Method Details

    • getSubCommands

      public Command[] getSubCommands()
    • execute

      public void execute()
      Execute this command by first invoking executeCommand(), then invoking itself recursively on all subcommands.
    • executeCommand

      protected abstract void executeCommand()
      Perform the action which this Command represents
    • myUndoCommand

      protected abstract Command myUndoCommand()
      If the action can be undone, return a Command that performs the inverse action. The Command returned should only undo executeCommand(), not the actions of subcommands
    • stripSubCommands

      public void stripSubCommands()
      Remove all subcommands.
    • isNull

      public boolean isNull()
      Returns:
      true if this command does nothing
    • isLoggable

      public boolean isLoggable()
      Returns:
      true if this command should be stored in a logfile
    • hasNullSubcommands

      @Deprecated(since="2020-08-06", forRemoval=true) protected boolean hasNullSubcommands()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • isAtomic

      protected boolean isAtomic()
      Return true if this command has no sub-commands attached to it (other than null commands).
      Returns:
      True if this command has no sub-commands
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getDetails

      public String getDetails()
      Detailed information for toString()
    • append

      public Command append(Command c)
      Append a subcommand to this Command.
    • getUndoCommand

      public Command getUndoCommand()
      Returns:
      a Command that undoes not only this Command's action, but also the actions of all its subcommands.
    • isNullOrContainsOnly

      public boolean isNullOrContainsOnly(Class<?> target)
      Return true if this Command is a NullCommand or only contains Null Commands or commands of the same type as target
      Parameters:
      target - Class to inspect for
      Returns:
      true if this command contains only non-null Commands target class Commands