A program entry-point, which scripts can "listen" to from multiple triggers.
Events are an entry-point for a program: they always start a new process.
The event object is available from anywhere within the process it starts via the event expression. Events will usually register special literal properties (event-values) for scripts to read from.
Event Syntax
The event syntax handler should extend the EventHolder class.
1
publicclassMyEventSyntaxextendsEventHolder{
2
3
publicMyEventSyntax(){
4
super(myLibrary,"on my event");
5
}
6
7
@Override
8
publicClass<?extendsEvent>eventClass(){
9
returnMyEvent.class;// this is the actual event class
10
}
11
12
}
Copied!
Event syntax should always start with on for the sake of clarity.
Event Object
Most of the behaviour is handled within the event object. This is a separate class from the event syntax handler, and an instance is given to Skript in order to trigger the event.
1
publicclassMyEventextendsEvent{
2
3
publicMyEvent(){
4
}
5
6
@EventValue("name")// event-name
7
publicStringgetName(){
8
return script.getSimpleName();
9
}
10
11
@EventValue("number")// event-number
12
publicNumbergetNumber(){
13
return10.5;
14
}
15
16
}
Copied!
Triggering the Event
The event can be triggered from the Skript instance.
1
skript.runEvent(newMyEvent());
Copied!
It may also be run only for an individual script.
1
skript.runEvent(newMyEvent(), script);
Copied!
Event triggers will always start a new process (or recycle a finished one where possible) but multiple event triggers called at the same time will receive the same event object, so be careful with concurrency-sensitive data.
The script process can be retrieved from within an event-value method, since it is guaranteed to be run on a Skript thread.