// Initialize necessary fields
Map<String, String> context = null;
Boolean instant = false;
dScript script = null;
Duration delay = null;
String queue = scriptEntry.getResidingQueue().id;
// Iterate through Arguments to extract needed information
for (String arg : scriptEntry.getArguments()) {
// Specify scriptContainer to use
if (aH.matchesScript(arg)) {
script = aH.getScriptFrom(arg);
} // Delay the start of the queue
else if (aH.matchesValueArg("DELAY", arg, aH.ArgumentType.Duration)) {
delay = aH.getDurationFrom(arg);
} // Use a specific queue
else if (aH.matchesQueue(arg)) {
queue = aH.getStringFrom(arg);
} // TODO: Remove this argument for version 1.0
else if (aH.matchesValueArg("SPEED", arg, aH.ArgumentType.Duration)) {
dB.log("SPEED argument has been removed from RUNTASK! Instead, specify " +
"a speed on the task script itself, or use the 'QUEUE SET_SPEED:#' command " +
"inside the task script. This warning will be removed in version 1.0 " +
"and this command will be deprecated.");
} // Gets a new, randomly named queue
else if (aH.matchesArg("QUEUE", arg)) {
queue = ScriptQueue.getNextId("RUNTASK");
instant = false;
} // Run the script instantly.
else if (aH.matchesArg("INSTANT, INSTANTLY", arg)) {
queue = ScriptQueue.getNextId("RUNTASK");
instant = true;
} // Build context map if specified
else if (aH.matchesContext(arg)) {
context = aH.getContextFrom(arg);
} // Specify a script name without the 'script:' prefix
else if (ScriptRegistry.containsScript(aH.getStringFrom(arg))) {
script = aH.getScriptFrom(arg);
if (!script.getType().equalsIgnoreCase("TASK"))
script = null;
} else throw new InvalidArgumentsException("Unknown argument '" + arg + "'!");
}
// Must specify at least a valid script to run...
if (script == null)
throw new InvalidArgumentsException("Must define a SCRIPT to be run.");
// If not queue, and delayed, throw an exception... this cannot happen.
if (queue.equals(scriptEntry.getResidingQueue().id) && delay != null)
throw new InvalidArgumentsException("Cannot delay an INJECTED task script! Use 'QUEUE'.");
// Put important objects inside the scriptEntry to be sent to execute()
scriptEntry.addObject("instant", instant)
.addObject("queue", queue)
.addObject("delay", (delay != null ? delay.setPrefix("Delay") : null))
.addObject("script", script)
.addObject("context", context);
}