Type@ember/types
types.Intercept
Runs while the action is happening, before it takes effect. A handler returns false to deny the action, or edits the event's writable fields; it must not yield. Handlers run in connect order and the first false wins.
Methods
intercept:intercept(handler: (event: E) -> boolean?) -> types.ConnectionAdds handler to the intercept's handlers.
local world = require("@ember/world")
-- Events come in pairs. The intercept (`breaking`) runs while the break is happening and decides
-- it: return false to cancel it, or change a writable field such as `drops`. It must not yield.
local spawnArea = world.regions.single("spawn")
world.breaking:intercept(function(event)
if spawnArea:contains(event.position) then
event.player:send("<red>Spawn is protected.")
return false
end
-- Anything other than false lets it through.
return true
end)
-- The signal (`broken`) fires afterwards, only for breaks nothing cancelled, so it never sees a
-- block at spawn. Its handlers are tasks and may wait.
world.broken:connect(function(event)
local position, block = event.position, event.block
task.wait(30)
world.setBlock(position, block.id, block.state)
end)