HOOK_EXECUTE_COMMAND


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

A plugin may implement a callback for this hook to intercept both in-game commands executed by the players and console commands executed by the server admin. The function is called for every in-game command sent from any player and for those server console commands that are not built in in the server.

If the command is in-game, the first parameter to the hook function is the player who's executing the command. If the command comes from the server console, the first parameter is nil.

The server calls this hook even for unregistered (unknown) console commands. It also calls the hook for unknown in-game commands, as long as they begin with a slash ('/'). If a plugin needs to intercept in-game chat messages not beginning with a slash, it should use the HOOK_CHAT hook.


Callback function

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

function MyOnExecuteCommand(Player, CommandSplit, EntireCommand)

Parameters:

NameTypeNotes
PlayercPlayerFor in-game commands, the player who has sent the message. For console commands, nil
CommandSplitarray-table of stringsThe command and its parameters, broken into a table by spaces
EntireCommandstringThe entire command as a single string

If the plugin returns false, Cuberite calls all the remaining hook handlers and finally the command will be executed. If the plugin returns true, the none of the remaining hook handlers will be called. In this case the plugin can return a second value, specifying whether what the command result should be set to, one of the CommandResult constants. If not provided, the value defaults to crBlocked.


Code examples

Registering the callback

cPluginManager:AddHook(cPluginManager.HOOK_EXECUTE_COMMAND, MyOnExecuteCommand);
Generated by APIDump on 2024-10-25 05:01:00, Build ID Unknown, Commit approx: 0325de7dacaf1e2feaea5eaab4791bc23d78f9e7