@@ -22,6 +22,14 @@ partially handle the event before it happens and handle the rest after. While in
22
22
confusion (like handling the respawn event still referring to player's original position and dimension), but gives much
23
23
more control over these events.
24
24
25
+ Some events also provide the ability to cancel minecraft's processing of the event by returning ` 'cancel' ` from the event handler.
26
+ This only works for particular events that are triggered before they take an effect in the game.
27
+ However, cancelling the event will also stop events from subsequent apps from triggering.
28
+ The order of events being executed can be changed by specifying an ` 'event_priority' ` in the app config,
29
+ with the highest value being executed first.
30
+ Note that cancelling some events might introduce a desynchronization to the client from the server,
31
+ creating ghost items or blocks. This can be solved by updating the inventory or block to the client, by using ` inventory_set ` or ` set ` .
32
+
25
33
Programmers can also define their own events and signal other events, including built-in events, and across all loaded apps.
26
34
27
35
## App scopes and event distribution
@@ -142,6 +150,8 @@ Triggers with a right click action. Event is triggered right after a server rece
142
150
game manages to do anything about it. Event triggers when player starts eating food, or starts drawing a bow.
143
151
Use ` player_finishes_using_item ` , or ` player_releases_item ` to capture the end of these events.
144
152
153
+ This event can be cancelled by returning ` 'cancel' ` , which prevents the item from being used.
154
+
145
155
Event is not triggered when a player places a block, for that use
146
156
` player_right_clicks_block ` or ` player_places_block ` event.
147
157
@@ -156,21 +166,34 @@ Player using of an item is done. This is controlled server side and is responsib
156
166
eating. The event is triggered after confirming that the action is valid, and sending the feedback back
157
167
to the client, but before triggering it and its effects in game.
158
168
169
+ This event can be cancelled by returning ` 'cancel' ` , which prevents the player from finishing using the item.
170
+
159
171
### ` __on_player_clicks_block(player, block, face) `
160
172
Representing left-click attack on a block, usually signifying start of breaking of a block. Triggers right after the server
161
- receives a client packet, before anything happens on the server side.
173
+ receives a client packet, before anything happens on the server side.
174
+
175
+ This event can be cancelled by returning ` 'cancel' ` , which stops the player from breaking a block.
162
176
163
177
164
178
### ` __on_player_breaks_block(player, block) `
165
179
Called when player breaks a block, right before any changes to the world are done, but the decision is made to remove the block.
166
180
181
+ This event can be cancelled by returning ` 'cancel' ` , which prevents the block from being placed.
182
+
167
183
### ` __on_player_right_clicks_block(player, item_tuple, hand, block, face, hitvec) `
168
184
Called when player right clicks on a block with anything, or interacts with a block. This event is triggered right
169
185
before other interaction events, like ` 'player_interacts_with_block' ` or ` 'player_places_block' ` .
186
+
187
+ This event can be cancelled by returning ` 'cancel' ` , which prevents the player interaction.
170
188
171
189
### ` __on_player_interacts_with_block(player, hand, block, face, hitvec) `
172
190
Called when player successfully interacted with a block, which resulted in activation of said block,
173
191
right after this happened.
192
+
193
+ ### ` __on_player_placing_block(player, item_tuple, hand, block) `
194
+ Triggered when player places a block, before block is placed in the world.
195
+
196
+ This event can be cancelled by returning ` 'cancel' ` , which prevents the block from being placed.
174
197
175
198
### ` __on_player_places_block(player, item_tuple, hand, block) `
176
199
Triggered when player places a block, after block is placed in the world, but before scoreboard is triggered or player inventory
@@ -181,6 +204,8 @@ Triggered when player right clicks (interacts) with an entity, even if the entit
181
204
the item they are holding. The event is invoked after receiving a packet from the client, before anything happens server side
182
205
with that interaction.
183
206
207
+ This event can be cancelled by returning ` 'cancel' ` , which prevents the player interacting with the entity.
208
+
184
209
### ` __on_player_trades(player, entity, buy_left, buy_right, sell) `
185
210
Triggered when player trades with a merchant. The event is invoked after the server allow the trade, but before the inventory
186
211
changes and merchant updates its trade-uses counter.
@@ -195,13 +220,17 @@ on the player.
195
220
Triggered when a player clicks a recipe in the crafting window from the crafting book, after server received
196
221
a client request, but before any items are moved from its inventory to the crafting menu.
197
222
223
+ This event can be cancelled by returning ` 'cancel' ` , which prevents the recipe from being moved into the crafting grid.
224
+
198
225
### ` __on_player_switches_slot(player, from, to) `
199
226
Triggered when a player changes their selected hotbar slot. Applied right after the server receives the message to switch
200
227
the slot.
201
228
202
229
### ` __on_player_swaps_hands(player) `
203
230
Triggered when a player sends a command to swap their offhand item. Executed before the effect is applied on the server.
204
231
232
+ This event can be cancelled by returning ` 'cancel' ` , which prevents the hands from being swapped.
233
+
205
234
### ` __on_player_swings_hand(player, hand) `
206
235
Triggered when a player starts swinging their hand. The event typically triggers after a corresponding event that caused it
207
236
(` player_uses_item ` , ` player_breaks_block ` , etc.), but it triggers also after some failed events, like attacking the air. When
@@ -210,15 +239,21 @@ swinging continues as an effect of an action, no new swinging events will be iss
210
239
### ` __on_player_attacks_entity(player, entity) `
211
240
Triggered when a player attacks entity, right before it happens server side.
212
241
242
+ This event can be cancelled by returning ` 'cancel' ` , which prevents the player from attacking the entity.
243
+
213
244
### ` __on_player_takes_damage(player, amount, source, source_entity) `
214
245
Triggered when a player is taking damage. Event is executed right after potential absorbtion was applied and before
215
246
the actual damage is applied to the player.
216
247
248
+ This event can be cancelled by returning ` 'cancel' ` , which prevents the player from taking damage.
249
+
217
250
### ` __on_player_deals_damage(player, amount, entity) `
218
251
Triggered when a player deals damage to another entity. Its applied in the same moment as ` player_takes_damage ` if both
219
252
sides of the event are players, and similar for all other entities, just their absorbtion is taken twice, just noone ever
220
253
notices that ¯\_ (ツ)_ /¯
221
254
255
+ This event can be cancelled by returning ` 'cancel' ` , which prevents the damage from being dealt.
256
+
222
257
### ` __on_player_dies(player) `
223
258
Triggered when a player dies. Player is already dead, so don't revive them then. Event applied before broadcasting messages
224
259
about players death and applying external effects (like mob anger etc).
@@ -267,6 +302,8 @@ Four events triggered when player controls for sneaking and sprinting toggle.
267
302
Triggered when the game receives the request from a player to drop one item or full stack from its inventory.
268
303
Event happens before anything is changed server side.
269
304
305
+ These events can be cancelled by returning ` 'cancel' ` , which prevents the player dropping the items.
306
+
270
307
### ` __on_player_picks_up_item(player, item) `
271
308
Triggered AFTER a player successfully ingested an item in its inventory. Item represents the total stack of items
272
309
ingested by the player. The exact position of these items is unknown as technically these
@@ -281,6 +318,8 @@ Triggered when a player sends a disconnect package or is forcefully disconnected
281
318
### ` __on_player_message(player, message) `
282
319
Triggered when a player sends a chat message or runs a command.
283
320
321
+ This event can be cancelled by returning ` 'cancel' ` , which prevents the message from being sent.
322
+
284
323
### ` __on_statistic(player, category, event, value) `
285
324
Triggered when a player statistic changes. Doesn't notify on periodic an rhythmic events, i.e.
286
325
` time_since_death ` , ` time_since_rest ` , and ` played_one_minute ` since these are triggered every tick. Event
0 commit comments