Handling events

Listening to events

You may listen to any Bukkit-based event (including events added by other plugins) by referencing the imported class. For example, if you wanted to listen to org.bukkit.event.entity.EnderDragonChangePhaseEvent:
example.sk
1
import:
2
org.bukkit.event.entity.EnderDragonChangePhaseEvent
3
4
on EnderDragonChangePhaseEvent:
5
# your code
Copied!
Some plugins use their own event handling system or do not pass their events through Bukkit's event executor (which is the case with some of Skript's internal events).
In order to listen to an event, it must extend org.bukkit.event.Event and be executed by Bukkit's event executor.
You may also listen to multiple events with the same handler. The events do not have to be related, but you should take appropriate precautions if you try to access methods that are available in one event but not in the other. For example, if you want to listen to both org.bukkit.event.entity.ProjectileLaunchEvent and org.bukkit.event.entity.ProjectileHitEvent
example.sk
1
import:
2
org.bukkit.event.entity.ProjectileLaunchEvent
3
org.bukkit.event.entity.ProjectileHitEvent
4
5
on ProjectileLaunchEvent and ProjectileHitEvent:
6
# your code
Copied!

Using the event expression

skript-mirror exposes an event expression, allowing you to access event values using reflection.
Syntax
example.sk
1
[the] event
Copied!
1
import:
2
org.bukkit.event.entity.EnderDragonChangePhaseEvent
3
org.bukkit.entity.EnderDragon$Phase as EnderDragonPhase
4
5
on EnderDragonChangePhaseEvent:
6
if event.getNewPhase() is EnderDragonPhase.CIRCLING!:
7
event.setNewPhase(EnderDragonPhase.CHARGE_PLAYER!)
Copied!
The event expression may also be used in normal Skript events.

Setting a priority level

The priority level of an event may be set to control when a particular event handler is run relative to other event handlers.
example.sk
1
import:
2
org.bukkit.event.entity.EnderDragonChangePhaseEvent
3
4
on EnderDragonChangePhaseEvent with priority highest:
5
# your code
Copied!
Any event priorities defined in org.bukkit.event.EventPriority may be used. Lower priority event handlers are run before higher priority event handlers.
Event Priorities
1
lowest
2
low
3
normal
4
high
5
highest
6
monitor
Copied!
highest is the highest priority event handler you should use if you are modifying the contents of an event. If you only care about the final result of the event, use monitor.

Handling cancelled events

By default, event handlers will not be called if an event is cancelled by a lower priority handler. This behavior can be changed by specifying that the handler should handle all events.
example.sk
1
import:
2
org.bukkit.event.block.BlockBreakEvent
3
4
on all BlockBreakEvent:
5
uncancel event
Copied!