EventInterceptor¶
Represents an interceptor for events.
An event interceptor is returned by spell:intercept() and allows inline handling of events as they occur.
Unlike an event queue, an interceptor can cancel events by returning false from its callback function (if the event supports cancellation).
An interceptor must not call sleep() or any other function that pauses execution. It has to decide
immediately whether the event should continue (or be canceled) and return that decision as a boolean,
because the event can't be canceled after the fact. Therefore, use an interceptor only when you may need
to cancel the event, and always perform expensive post-processing outside of it.
Example: Canceling a death event
local i = spell:intercept("BeforeLivingEntityDeathEvent", function(evt)
if evt.entity.type.id == "zombie" then
evt.entity.health = 1
return false -- Cancel the death
end
return true
end)
while true do sleep(20) end -- Keep spell running
Fields¶
names: string[ ] — Read-Only¶
The names of the events that this interceptor listens to.
Methods¶
stop()¶
Stops this interceptor from receiving further events.
Example: Stopping on a specific message