Class ItemCommand

Object
ItemCommand
All Implemented Interfaces:
Command

public abstract class ItemCommand extends Object implements Command
An abstract class for the most normal commands.
Author:
maartenl
  • Constructor Details

    • ItemCommand

      protected ItemCommand(String aRegExpr)
      Constructor.
      Parameters:
      aRegExpr - a regular expression to which the command should follow. For example "give [A..Za..z]*1-4 to [A..Za..z]*". %me is a parameter that can be used when the name of the character playing is requested.
  • Method Details

    • getRegExpr

      public String getRegExpr()
      Description copied from interface: Command
      returns the regular expression the command structure must follow.
      Specified by:
      getRegExpr in interface Command
      Returns:
      String containing the regular expression.
      See Also:
    • run

      public abstract DisplayInterface run(String command, User aUser)
      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
      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.
    • parseCommand

      protected static String[] parseCommand(String aCommand)
      split up the command into different words.
      Parameters:
      aCommand - String containing the command
      Returns:
      String array where each String contains a word from the command.
    • parseCommand

      protected static String[] parseCommand(String aCommand, int limit)
      split up the command into different words.

      For example:

      parseCommand("bow to Marvin evilly", 4) returns array ["bow","to","Marvin", "evilly"]

      parseCommand("say to Marvin Greetings this morning.", 4) returns array ["say","to","Marvin", "Greetings this morning."]

      Parameters:
      aCommand - String containing the command
      limit - the result threshold, example 3 means the array holds three, the first two words and the rest in the third array element.
      Returns:
      String array where each String contains a word from the command.
      See Also: