Creating an Event
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
public class MyEventSyntax extends EventHolder {
2
3
public MyEventSyntax() {
4
super(myLibrary, "on my event");
5
}
6
7
@Override
8
public Class<? extends Event> eventClass() {
9
return MyEvent.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
public class MyEvent extends Event {
2
3
public MyEvent() {
4
}
5
6
@EventValue("name") // event-name
7
public String getName() {
8
return script.getSimpleName();
9
}
10
11
@EventValue("number") // event-number
12
public Number getNumber() {
13
return 10.5;
14
}
15
16
}
Copied!

Triggering the Event

The event can be triggered from the Skript instance.
1
skript.runEvent(new MyEvent());
Copied!
It may also be run only for an individual script.
1
skript.runEvent(new MyEvent(), 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.