Denizen API: Difference between revisions
Aufdemrand (talk | contribs) |
Aufdemrand (talk | contribs) |
||
Line 27: | Line 27: | ||
* <code>.getTriggerType()</code> contains a <code>TriggerType</code> of the script, that is, what type of 'TRIGGER' triggered it. | * <code>.getTriggerType()</code> contains a <code>TriggerType</code> of the script, that is, what type of 'TRIGGER' triggered it. | ||
*: This will be either <code>TriggerType.ATTACK</code>, <code>TriggerType.CLICK</code>, <code>TriggerType.CHAT</code>, <code>TriggerType.PROXIMITY</code>, <code>TriggerType.TASK</code>, or <code>TriggerType.LOCATION</code>. More types are likely to be implemented. | *: This will be either <code>TriggerType.ATTACK</code>, <code>TriggerType.CLICK</code>, <code>TriggerType.CHAT</code>, <code>TriggerType.PROXIMITY</code>, <code>TriggerType.TASK</code>, or <code>TriggerType.LOCATION</code>. More types are likely to be implemented. | ||
* <code>.getPlayer()</code> contains a <code>Player</code> object of the triggering Player, if triggered by a player, that is. | |||
*: If triggered from a <code>ACTIVITY</code> script, this would be null. | |||
* <code>.getDenizen()</code> contains a <code>NPC</code> Citizens2 object, again, if a NPC object is sent with it. | |||
*: If triggered from a <code>TASK</code> script, this is null. | |||
* <code>.getInitiatedTime()</code> contains a <code>Long System.currentTimeMillis()</code> of the system time in which it was sent to your Command for processing. | * <code>.getInitiatedTime()</code> contains a <code>Long System.currentTimeMillis()</code> of the system time in which it was sent to your Command for processing. | ||
Line 33: | Line 39: | ||
* <code>.getTexts()</code> contains a <code>String[]</code> of 2 elements. | * <code>.getTexts()</code> contains a <code>String[]</code> of 2 elements. | ||
*: First element, <code>.getTexts[0]</code> for example, has the 'raw text' that the player typed to initiate the command. Second element, <code>.getTexts[1]</code> contains the 'friendly text', most likely the Chat Trigger that was set in the script. As you can probaly guess, if | *: First element, <code>.getTexts[0]</code> for example, has the 'raw text' that the player typed to initiate the command. Second element, <code>.getTexts[1]</code> contains the 'friendly text', most likely the Chat Trigger that was set in the script. As you can probaly guess, if <code>.getTriggerType()</code> isn't a <code>TriggerType.CHAT</code> this will most likely be null. |
Revision as of 21:24, 5 July 2012
In Denizen, the Script Command system is extensible by design. It's very easy to make your own commands (and soon Requirements) extend the built-in features. On top of that, Denizen has some features available that may be of use to Plugin Developers.
Building your own Commands
The ScriptCommand Object
When Denizen reads scripts, each line is turned into a SciptCommand object that contains the command, the arguments, and various other data and objects, as described below. Your command is an extension of this base Command class, and each time your command is called in for execution, it's this class that is executed and handled a ScriptCommand. How the Command uses the ScriptCommand information is of course, up to you.
What a ScriptCommand holds
ScriptCommands hold data about the situation surrounding the event that activates your command. Which type of script activates your Command, the ScriptCommand can have a multitude of information available.
.getCommand()
of course, contains aString
of the name of your command.- Useful if your command module contains instructions for more than one command. You can register multiple commands to your module, as discussed later in this document. See the
ENGAGE
command for a useful example of utilizing this information.
- Useful if your command module contains instructions for more than one command. You can register multiple commands to your module, as discussed later in this document. See the
.arguments()
has aString[]
of all the arguments the player provided.- This pre-formats arguments that have used quotes, for instance, if the script command is
YOURCOMMAND argument1 argument2 'this is argument3'
, this object would have 3 items in the array.
- This pre-formats arguments that have used quotes, for instance, if the script command is
.sendingQueue()
returns aQueueType
of eitherQueueType.TRIGGER
,QueueType.TASK
, orQueueType.ACTIVITY
- This contains the type of queue that sent the command. If the command was issues from a TASK script, for example, this would contain
QueueType.TASK
- This contains the type of queue that sent the command. If the command was issues from a TASK script, for example, this would contain
.getScript()
contains aString
name of the script.
.getStep()
contains anInteger
of the step of the script.- Note that if this was a
TASK
script, for example, this would be null.
- Note that if this was a
.getTriggerType()
contains aTriggerType
of the script, that is, what type of 'TRIGGER' triggered it.- This will be either
TriggerType.ATTACK
,TriggerType.CLICK
,TriggerType.CHAT
,TriggerType.PROXIMITY
,TriggerType.TASK
, orTriggerType.LOCATION
. More types are likely to be implemented.
- This will be either
.getPlayer()
contains aPlayer
object of the triggering Player, if triggered by a player, that is.- If triggered from a
ACTIVITY
script, this would be null.
- If triggered from a
.getDenizen()
contains aNPC
Citizens2 object, again, if a NPC object is sent with it.- If triggered from a
TASK
script, this is null.
- If triggered from a
.getInitiatedTime()
contains aLong System.currentTimeMillis()
of the system time in which it was sent to your Command for processing.
.getDelayedTime()
contains aLong System.currentTimeMillis()
of the system time that was set by using the.setDelay(Long newTime)
. This is null by default. Check out theWAIT
command for a functional example of usage.
.getTexts()
contains aString[]
of 2 elements.- First element,
.getTexts[0]
for example, has the 'raw text' that the player typed to initiate the command. Second element,.getTexts[1]
contains the 'friendly text', most likely the Chat Trigger that was set in the script. As you can probaly guess, if.getTriggerType()
isn't aTriggerType.CHAT
this will most likely be null.
- First element,