2017-01-22 09:05:09 +01:00
|
|
|
-- Minetest: builtin/client/chatcommands.lua
|
|
|
|
|
|
|
|
|
|
|
|
core.register_on_sending_chat_messages(function(message)
|
2017-03-25 00:43:36 +01:00
|
|
|
local first_char = message:sub(1,1)
|
|
|
|
if first_char == "/" or first_char == "." then
|
|
|
|
core.display_chat_message("issued command: " .. message)
|
2017-01-22 09:05:09 +01:00
|
|
|
end
|
2017-01-27 07:41:10 +01:00
|
|
|
|
2017-03-25 00:43:36 +01:00
|
|
|
if first_char ~= "." then
|
|
|
|
return false
|
|
|
|
end
|
2017-01-27 07:41:10 +01:00
|
|
|
|
2017-03-25 00:43:36 +01:00
|
|
|
local cmd, param = string.match(message, "^%.([^ ]+) *(.*)")
|
2017-01-22 09:05:09 +01:00
|
|
|
if not param then
|
|
|
|
param = ""
|
|
|
|
end
|
2017-01-27 07:41:10 +01:00
|
|
|
|
2017-03-25 00:43:36 +01:00
|
|
|
if not cmd then
|
|
|
|
core.display_chat_message("-!- Empty command")
|
|
|
|
return true
|
|
|
|
end
|
2017-01-27 07:41:10 +01:00
|
|
|
|
2017-03-25 00:43:36 +01:00
|
|
|
local cmd_def = core.registered_chatcommands[cmd]
|
2017-01-22 09:05:09 +01:00
|
|
|
if cmd_def then
|
|
|
|
core.set_last_run_mod(cmd_def.mod_origin)
|
2017-01-27 07:41:10 +01:00
|
|
|
local _, message = cmd_def.func(param)
|
2017-01-22 09:05:09 +01:00
|
|
|
if message then
|
|
|
|
core.display_chat_message(message)
|
|
|
|
end
|
2017-03-25 00:43:36 +01:00
|
|
|
else
|
|
|
|
core.display_chat_message("-!- Invalid command: " .. cmd)
|
2017-01-22 09:05:09 +01:00
|
|
|
end
|
2017-01-27 07:41:10 +01:00
|
|
|
|
2017-03-25 00:43:36 +01:00
|
|
|
return true
|
2017-01-27 07:41:10 +01:00
|
|
|
end)
|