public abstract class UserDefinedCommand extends java.lang.Object implements CommandIfc
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
RETURN_KEY
The return key character (0x0D).
|
Constructor and Description |
---|
UserDefinedCommand()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
atPrompt(int validPrompts)
Checks if you are at any of the valid prompts.
|
void |
endCommand(boolean finished)
Called by the framework when the command is finished.
You can override this method to clean up after the command if needed. |
java.lang.Object |
execInstance()
Executes a command instance.
Should only be called from static exec() methods. |
java.lang.String |
getClassName()
Gets the command class name.
|
java.lang.String |
getName()
Called by the framework to get the name of the command.
You should override this method. |
java.util.Enumeration |
getParams()
Gets the command parameters.
|
java.net.URL |
getResource(java.lang.String resource)
Finds a resource with a given name.
|
boolean |
initCommand()
Called by the framework to initialise the command.
You should override this method to make your own initialisation. |
void |
initInstance()
Initialises a command instance.
Should only be called from static exec() methods. |
boolean |
isInternal()
Indicates if this is an internal SWATH command or not.
|
boolean |
isUserDefined()
Indicates if this command is user defined or not.
|
void |
onEvent(EventIfc event)
This method is called for each posted event.
You can override this method to handle events. |
void |
onText(java.lang.String buffer,
java.lang.String text)
This method is called when new text has arrived from the game server.
You can override this method to scan for incoming text. The current text buffer contains both the previous text and the new text that just arrived. |
void |
postEvent(UserDefinedEvent event)
This method posts an event in the SWATH event queue.
|
void |
printTrace(java.lang.Exception e)
Print an exception and the complete stack trace
in the SWATH console window.
|
void |
printTrace(java.lang.String text)
Print trace text in the SWATH console window.
|
void |
registerParam(Parameter param)
This method is used to register a command parameter.
|
void |
sendString(java.lang.String str)
Sends a string to the TW server.
|
void |
setBufferText(java.lang.String text)
Sets the current text buffer content.
|
void |
setResult(java.lang.Object result)
Sets the result value that will be returned when the command is finished.
|
void |
skipBufferText(int count)
Removes characters from the current text buffer.
|
void |
startCommand()
Called by the framework to start executing the command.
You should override this method. Normally you send some text to the TW server and then handle all incoming text and events using the methods onText and onEvent . |
public static final java.lang.String RETURN_KEY
public final boolean isUserDefined()
CommandIfc
isUserDefined
in interface CommandIfc
true
if user defined, otherwise false
.public final boolean isInternal()
CommandIfc
isInternal
in interface CommandIfc
true
if internal, otherwise false
.public final java.lang.String getClassName()
CommandIfc
getClassName
in interface CommandIfc
public final void registerParam(Parameter param) throws CommandException
param
- The parameter to register.CommandException
- If no more parameters could be added.public final java.util.Enumeration getParams()
getParams
in interface CommandIfc
public final void initInstance() throws CommandException, java.lang.Exception
exec()
methods.CommandException
- If the command initialisation fails for some reason.java.lang.Exception
execInstance()
public final java.lang.Object execInstance() throws CommandException, java.lang.Exception
exec()
methods.CommandException
- If the command execution fails for some reason.java.lang.Exception
initInstance()
public final void skipBufferText(int count)
count
- Number of characters to remove.setBufferText(java.lang.String)
,
onText(java.lang.String, java.lang.String)
public final void setBufferText(java.lang.String text)
text
- The new content.skipBufferText(int)
,
onText(java.lang.String, java.lang.String)
public final void setResult(java.lang.Object result)
result
- The result.execInstance()
public final boolean atPrompt(int validPrompts) throws java.lang.Exception
validPrompts
- The valid prompts. (Combine several prompts with logical OR)true
if you are at a valid prompt,
otherwise false
.java.lang.Exception
Swath.NO_PROMPT
,
Swath.COMMAND_PROMPT
,
Swath.COMPUTER_PROMPT
,
Swath.PLANET_PROMPT
,
Swath.CITADEL_PROMPT
,
Swath.CORP_PROMPT
,
Swath.STARDOCK_PROMPT
,
Swath.ALL_PROMPTS
public final java.net.URL getResource(java.lang.String resource)
resource
- The name of the wanted resource.null
if not found.public final void sendString(java.lang.String str) throws java.lang.Exception
str
- The string to send.java.lang.Exception
RETURN_KEY
public final void postEvent(UserDefinedEvent event)
event
- The event to post.public final void printTrace(java.lang.String text) throws java.lang.Exception
text
- The text to print.java.lang.Exception
public final void printTrace(java.lang.Exception e) throws java.lang.Exception
e
- The exception to print.java.lang.Exception
public java.lang.String getName()
getName
in interface CommandIfc
public boolean initCommand() throws java.lang.Exception
true
if the initialisation was successful,
otherwise false
.java.lang.Exception
atPrompt(int)
,
printTrace(java.lang.String)
,
setResult(java.lang.Object)
public void startCommand() throws java.lang.Exception
onText
and onEvent
.java.lang.Exception
sendString(java.lang.String)
,
postEvent(com.swath.UserDefinedEvent)
,
printTrace(java.lang.String)
,
setResult(java.lang.Object)
,
onText(java.lang.String, java.lang.String)
,
onEvent(com.swath.EventIfc)
public void endCommand(boolean finished) throws java.lang.Exception
finished
- true
if the command finished correctly or
false
if the command was interrupted in some way.java.lang.Exception
public void onText(java.lang.String buffer, java.lang.String text) throws java.lang.Exception
skipBufferText
and setBufferText
methods.buffer
- The current text buffer.text
- The new incoming text.java.lang.Exception
skipBufferText(int)
,
setBufferText(java.lang.String)
,
sendString(java.lang.String)
,
postEvent(com.swath.UserDefinedEvent)
,
printTrace(java.lang.String)
,
setResult(java.lang.Object)
public void onEvent(EventIfc event) throws java.lang.Exception
event
- The event.java.lang.Exception
sendString(java.lang.String)
,
postEvent(com.swath.UserDefinedEvent)
,
printTrace(java.lang.String)
,
setResult(java.lang.Object)