HOOK_PLAYER_LEFT_CLICK


Index:
Articles
Classes
Hooks

Quick navigation:
BLOCK_SPREAD
BLOCK_TO_PICKUPS
BREWING_COMPLETED
BREWING_COMPLETING
CHAT
CHUNK_AVAILABLE
CHUNK_GENERATED
CHUNK_GENERATING
CHUNK_UNLOADED
CHUNK_UNLOADING
COLLECTING_PICKUP
CRAFTING_NO_RECIPE
DISCONNECT
DROPSPENSE
ENTITY_ADD_EFFECT
ENTITY_CHANGED_WORLD
ENTITY_CHANGING_WORLD
ENTITY_TELEPORT
EXECUTE_COMMAND
EXPLODED
EXPLODING
HANDSHAKE
HOPPER_PULLING_ITEM
HOPPER_PUSHING_ITEM
KILLED
KILLING
LOGIN
LOGIN_FORGE
PLAYER_ANIMATION
PLAYER_BREAKING_BLOCK
PLAYER_BROKEN_BLOCK
PLAYER_CROUCHED
PLAYER_DESTROYED
PLAYER_EATING
PLAYER_FISHED
PLAYER_FISHING
PLAYER_FOOD_LEVEL_CHANGE
PLAYER_JOINED
PLAYER_LEFT_CLICK
PLAYER_MOVING
PLAYER_OPENING_WINDOW
PLAYER_PLACED_BLOCK
PLAYER_PLACING_BLOCK
PLAYER_RIGHT_CLICK
PLAYER_RIGHT_CLICKING_ENTITY
PLAYER_SHOOTING
PLAYER_SPAWNED
PLAYER_TOSSING_ITEM
PLAYER_USED_BLOCK
PLAYER_USED_ITEM
PLAYER_USING_BLOCK
PLAYER_USING_ITEM
PLUGINS_LOADED
PLUGIN_MESSAGE
POST_CRAFTING
PRE_CRAFTING
PROJECTILE_HIT_BLOCK
PROJECTILE_HIT_ENTITY
SERVER_PING
SPAWNED_ENTITY
SPAWNED_MONSTER
SPAWNING_ENTITY
SPAWNING_MONSTER
TAKE_DAMAGE
TICK
UPDATED_SIGN
UPDATING_SIGN
WEATHER_CHANGED
WEATHER_CHANGING
WORLD_STARTED
WORLD_TICK

This hook is called when Cuberite receives a left-click packet from the client. It is called before any processing whatsoever is performed on the packet, meaning that hacked / malicious clients may be trigerring this event very often and with unchecked parameters. Therefore plugin authors are advised to use extreme caution with this callback.

Plugins may refuse the default processing for the packet, causing Cuberite to behave as if the packet has never arrived. This may, however, create inconsistencies in the client - the client may think that they broke a block, while the server didn't process the breaking, etc. For this reason, if a plugin refuses the processing, Cuberite sends the block specified in the packet back to the client (as if placed anew), if the status code specified a block-break action. For other actions, plugins must rectify the situation on their own.

The client sends the left-click packet for several other occasions, such as dropping the held item (Q keypress) or shooting an arrow. This is reflected in the Status code. Consult the protocol documentation for details on the actions.


Callback function

The default name for the callback function is OnPlayerLeftClick. It has the following signature:

function MyOnPlayerLeftClick(Player, BlockX, BlockY, BlockZ, BlockFace, Action)

Parameters:

NameTypeNotes
PlayercPlayerThe player whose client sent the packet
BlockXnumberX-coord of the block
BlockYnumberY-coord of the block
BlockZnumberZ-coord of the block
BlockFacenumberFace of the block upon which the player interacted. One of the BLOCK_FACE_ constants
ActionnumberAction to be performed on the block ("status" in the protocol docs)

If the function returns false or no value, Cuberite calls other plugins' callbacks and finally sends the packet for further processing.

If the function returns true, no other plugins are called, processing is halted. If the action was a block dig, Cuberite sends the block specified in the coords back to the client. The packet is dropped.


Code examples

Registering the callback

cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_LEFT_CLICK, MyOnPlayerLeftClick);
Generated by APIDump on 2024-07-12 00:49:19, Build ID 63, Commit 5f4d2f004bc41bc44d0df7376e48cbb5567db1be