cancelling events
event.cancel()
call this to stop the action from happening. for example, preventing players from breaking a block
it only does something on cancellable events
not every event can be cancelled. event.cancel() is always safe to call, it just quietly returns false and does nothing if the event doesn't support cancellation (for example, player_join/player_quit
events that do support cancellation include interactions, block break/place, and item drop/pickup
example: disable breaking certain blocks
@Katton.listen("block_break")
function protectSpawn(event) {
if (event.block == "glass") {
event.player.sendMessage("&cyou can't break that!")
event.cancel()
}
}
checking the return value
if you want to know whether the cancel actually took effect (useful mostly for debugging):
val wasCancelled = event.cancel()
if (!wasCancelled) {
Katton.log.warn("tried to cancel a noncancellable event")
}