public abstract class Trigger extends Object implements Cloneable, IObservable
Modifier and Type | Field and Description |
---|---|
protected Map<UUID,Long> |
cooldowns |
protected Map<String,Executor> |
executorMap |
protected Map<Object,Object> |
gvarMap |
protected TriggerInfo |
info |
protected IObserver |
observer |
protected Map<String,Placeholder> |
placeholderMap |
protected Node |
root |
protected String |
script |
Constructor and Description |
---|
Trigger(TriggerInfo info,
String script)
This constructor does not initialize the fields.
|
Modifier and Type | Method and Description |
---|---|
boolean |
activate(Object e,
Map<String,Object> scriptVars)
Start this trigger.
|
protected boolean |
checkCooldown(Object e) |
abstract Trigger |
clone() |
TriggerInfo |
getInfo() |
String |
getScript()
get the actual plain code of this trigger.
|
protected String |
getTimingId()
Get unique id to be used as fully qualified name for the Timings System.
|
void |
init() |
protected Interpreter |
initInterpreter(Map<String,Object> scriptVars)
Create interpreter with appropriate options and variables.
|
boolean |
isSync()
Check if this Trigger is sync mode.
|
void |
notifyObservers() |
void |
setScript(String script) |
void |
setSync(boolean sync)
Set this Trigger's sync mode.
|
protected void |
start(Object e,
Map<String,Object> scriptVars,
Interpreter interpreter,
boolean sync)
The actual execution part.
|
protected void |
start(Timings.Timing timing,
Object e,
Map<String,Object> scriptVars,
Interpreter interpreter,
boolean sync)
The actual execution part.
|
protected void |
startInterpretation(Object e,
Map<String,Object> scriptVars,
Interpreter interpreter,
boolean sync)
Start interpreting the code.
|
String |
toString() |
protected final TriggerInfo info
protected IObserver observer
protected String script
protected Node root
protected Map<String,Placeholder> placeholderMap
public Trigger(TriggerInfo info, String script)
init()
method
in order to make the Trigger work properly. If you want to create a Trigger with customized
behavior, it's not necessary to call init()
but need to override initInterpreter(Map)
,
startInterpretation(Object, Map, Interpreter, boolean)
, or activate(Object, Map)
method as your needpublic void notifyObservers()
notifyObservers
in interface IObservable
public TriggerInfo getInfo()
protected String getTimingId()
public void init() throws AbstractTriggerManager.TriggerInitFailedException
IOException
- low level exception from LexerLexerException
- throws if lexical analysis failedParserException
- throws if parsing failedAbstractTriggerManager.TriggerInitFailedException
public String getScript()
public void setScript(String script) throws AbstractTriggerManager.TriggerInitFailedException
public boolean isSync()
public void setSync(boolean sync)
sync
- public boolean activate(Object e, Map<String,Object> scriptVars)
e
- the Event associated with this TriggerscriptVars
- the temporary local variablesprotected boolean checkCooldown(Object e)
e
- protected Interpreter initInterpreter(Map<String,Object> scriptVars)
scriptVars
- protected void startInterpretation(Object e, Map<String,Object> scriptVars, Interpreter interpreter, boolean sync)
e
- The Event associated with this TriggerscriptVars
- temporary variablesinterpreter
- The Interpretersync
- set it true will make this method run in the thread that
has called this method. This is useful when this trigger has to cancel an Event;
set it to false will let it run in separate thread. This is more efficient if you
only need to read data from Event and never interact with it.protected void start(Timings.Timing timing, Object e, Map<String,Object> scriptVars, Interpreter interpreter, boolean sync)
e
- scriptVars
- interpreter
- sync
- timing
- protected void start(Object e, Map<String,Object> scriptVars, Interpreter interpreter, boolean sync)
e
- scriptVars
- interpreter
- sync
-