Class TargetCommand

Object
NormalCommand
TargetCommand
All Implemented Interfaces:
Command
Direct Known Subclasses:
BowCommand, CommunicationCommand, CurtseyCommand, EmotionCommand, EmotionToCommand, TellCommand

public abstract class TargetCommand extends NormalCommand
Indicates a command that needs or can have a target, like "action to Marvin" but necessarily, like "bow". Target needs to be in the same room.
Author:
maartenl
  • Constructor Details

    • TargetCommand

      public TargetCommand(String aRegExpr)
  • Method Details

    • actionTo

      protected abstract DisplayInterface actionTo(User aUser, Person aTarget, String verb, String command) throws MudException
      Run the action command to a target.
      Parameters:
      aUser - the one executing the command
      aTarget - the target of the command
      verb - the verb, usually the first word in the command, for example "cheer".
      command - the rest of the command, for example "bow to Marvin evilly", will provide "evilly". But "bow to Marvin" will return a null pointer.
      Returns:
      something to display
      Throws:
      MudException
    • action

      protected abstract DisplayInterface action(User aUser, String verb, String command) throws MudException
      Run an action without a target.
      Parameters:
      aUser - the one executing the command
      verb - the verb, usually the first word in the command, for example "bow".
      command - the rest of the command, for example "bow evilly" would return "evilly". "bow" would return null.
      Returns:
      something to display
      Throws:
      MudException
    • getTarget

      protected Person getTarget(String[] myParsed, User aUser) throws PersonNotFoundException
      Retrieves a target from the command line, detected in the form of "[command] to [target] stuff".
      Parameters:
      myParsed - the command, parsed. Usually only needs the first three words.
      aUser - the user issuing the command
      Returns:
      the Person found.
      Throws:
      PersonNotFoundException - if the person is not found in the room.
    • run

      public DisplayInterface run(String command, User aUser) throws MudException
      Description copied from interface: Command
      Runs the command. The usual sequence of events is:
      • parsing the command string
      • retrieving the appropriate information items/rooms/characters/etc)
      • doing the action
      • composing a return message for the user.
      Specified by:
      run in interface Command
      Specified by:
      run in class NormalCommand
      Parameters:
      command - the String containing the full command.
      aUser - the user that is executing the command
      Returns:
      DisplayInterface to display to the user, if it returns null, it means the command was unsuccessfull.
      Throws:
      MudException - if something goes wrong.