summaryrefslogtreecommitdiff
path: root/builtin/client
diff options
context:
space:
mode:
authorElijah Duffy <enduffy2014@outlook.com>2020-10-03 09:38:08 -0700
committerGitHub <noreply@github.com>2020-10-03 17:38:08 +0100
commit7d3641021b755be133dea58404fcb039211fbe52 (patch)
treebd62b4e197492242c84d6e001dfefc8090389b33 /builtin/client
parent07500479191ed927ab661b3758ffcd2fd43158c5 (diff)
downloadminetest-7d3641021b755be133dea58404fcb039211fbe52.tar.gz
minetest-7d3641021b755be133dea58404fcb039211fbe52.tar.bz2
minetest-7d3641021b755be133dea58404fcb039211fbe52.zip
Lua API: Add register_on_chatcommand to SSM and CSM (#7862)
Allows catching a chatcommand call just after the command and the parameters are parsed but before its existence is checked and before the corresponding function is run. Returning `true` from a callback function will prevent default handling of the command leaving mods to handle the command manually.
Diffstat (limited to 'builtin/client')
-rw-r--r--builtin/client/chatcommands.lua5
-rw-r--r--builtin/client/register.lua1
2 files changed, 6 insertions, 0 deletions
diff --git a/builtin/client/chatcommands.lua b/builtin/client/chatcommands.lua
index 5cb1b40bb..0e8d4dd03 100644
--- a/builtin/client/chatcommands.lua
+++ b/builtin/client/chatcommands.lua
@@ -23,6 +23,11 @@ core.register_on_sending_chat_message(function(message)
return true
end
+ -- Run core.registered_on_chatcommand callbacks.
+ if core.run_callbacks(core.registered_on_chatcommand, 5, cmd, param) then
+ return true
+ end
+
local cmd_def = core.registered_chatcommands[cmd]
if cmd_def then
core.set_last_run_mod(cmd_def.mod_origin)
diff --git a/builtin/client/register.lua b/builtin/client/register.lua
index c1b4965c1..acd36ab36 100644
--- a/builtin/client/register.lua
+++ b/builtin/client/register.lua
@@ -63,6 +63,7 @@ core.registered_on_mods_loaded, core.register_on_mods_loaded = make_registration
core.registered_on_shutdown, core.register_on_shutdown = make_registration()
core.registered_on_receiving_chat_message, core.register_on_receiving_chat_message = make_registration()
core.registered_on_sending_chat_message, core.register_on_sending_chat_message = make_registration()
+core.registered_on_chatcommand, core.register_on_chatcommand = make_registration()
core.registered_on_death, core.register_on_death = make_registration()
core.registered_on_hp_modification, core.register_on_hp_modification = make_registration()
core.registered_on_damage_taken, core.register_on_damage_taken = make_registration()