Package VASSAL.command
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
,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.
CommandEncoder
s 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 Summary
Constructors Constructor Description Command()
-
Method Summary
Modifier and Type Method Description Command
append(Command c)
Append a subcommand to this Command.void
execute()
Execute this command by first invokingexecuteCommand()
, then invoking itself recursively on all subcommands.protected abstract void
executeCommand()
Perform the action which this Command representsString
getDetails()
Detailed information for toString()Command[]
getSubCommands()
Command
getUndoCommand()
protected boolean
hasNullSubcommands()
Deprecated, for removal: This API element is subject to removal in a future version.protected boolean
isAtomic()
Return true if this command has no sub-commands attached to it (other than null commands).boolean
isLoggable()
boolean
isNull()
protected abstract Command
myUndoCommand()
If the action can be undone, return a Command that performs the inverse action.void
stripSubCommands()
Remove all subcommands.String
toString()
-
Constructor Details
-
Command
public Command()
-
-
Method Details
-
getSubCommands
-
execute
public void execute()Execute this command by first invokingexecuteCommand()
, then invoking itself recursively on all subcommands. -
executeCommand
protected abstract void executeCommand()Perform the action which this Command represents -
myUndoCommand
If the action can be undone, return a Command that performs the inverse action. The Command returned should only undoexecuteCommand()
, 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, for removal: This API element is subject to removal in a future version.UseisAtomic()
-
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
-
getDetails
Detailed information for toString() -
append
Append a subcommand to this Command. -
getUndoCommand
- Returns:
- a Command that undoes not only this Command's action, but also the actions of all its subcommands.
-
isAtomic()