Skip to content

Commit e8b7179

Browse files
committedJan 4, 2017
Expose and document chatcommands as minetest.registered_chatcommands
1 parent ca36296 commit e8b7179

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed
 

Diff for: ‎builtin/game/chatcommands.lua

+10-9
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44
-- Chat command handler
55
--
66

7-
core.chatcommands = {}
7+
core.registered_chatcommands = {}
8+
core.chatcommands = core.registered_chatcommands -- BACKWARDS COMPATIBILITY
89
function core.register_chatcommand(cmd, def)
910
def = def or {}
1011
def.params = def.params or ""
1112
def.description = def.description or ""
1213
def.privs = def.privs or {}
1314
def.mod_origin = core.get_current_modname() or "??"
14-
core.chatcommands[cmd] = def
15+
core.registered_chatcommands[cmd] = def
1516
end
1617

1718
core.register_on_chat_message(function(name, message)
1819
local cmd, param = string.match(message, "^/([^ ]+) *(.*)")
1920
if not param then
2021
param = ""
2122
end
22-
local cmd_def = core.chatcommands[cmd]
23+
local cmd_def = core.registered_chatcommands[cmd]
2324
if not cmd_def then
2425
return false
2526
end
@@ -107,7 +108,7 @@ core.register_chatcommand("help", {
107108
if param == "" then
108109
local msg = ""
109110
local cmds = {}
110-
for cmd, def in pairs(core.chatcommands) do
111+
for cmd, def in pairs(core.registered_chatcommands) do
111112
if core.check_player_privs(name, def.privs) then
112113
cmds[#cmds + 1] = cmd
113114
end
@@ -118,7 +119,7 @@ core.register_chatcommand("help", {
118119
.. " or '/help all' to list everything."
119120
elseif param == "all" then
120121
local cmds = {}
121-
for cmd, def in pairs(core.chatcommands) do
122+
for cmd, def in pairs(core.registered_chatcommands) do
122123
if core.check_player_privs(name, def.privs) then
123124
cmds[#cmds + 1] = format_help_line(cmd, def)
124125
end
@@ -134,7 +135,7 @@ core.register_chatcommand("help", {
134135
return true, "Available privileges:\n"..table.concat(privs, "\n")
135136
else
136137
local cmd = param
137-
local def = core.chatcommands[cmd]
138+
local def = core.registered_chatcommands[cmd]
138139
if not def then
139140
return false, "Command not available: "..cmd
140141
else
@@ -161,7 +162,7 @@ local function handle_grant_command(caller, grantname, grantprivstr)
161162
if not (caller_privs.privs or caller_privs.basic_privs) then
162163
return false, "Your privileges are insufficient."
163164
end
164-
165+
165166
if not core.get_auth_handler().get_auth(grantname) then
166167
return false, "Player " .. grantname .. " does not exist."
167168
end
@@ -204,7 +205,7 @@ core.register_chatcommand("grant", {
204205
local grantname, grantprivstr = string.match(param, "([^ ]+) (.+)")
205206
if not grantname or not grantprivstr then
206207
return false, "Invalid parameters (see /help grant)"
207-
end
208+
end
208209
return handle_grant_command(name, grantname, grantprivstr)
209210
end,
210211
})
@@ -215,7 +216,7 @@ core.register_chatcommand("grantme", {
215216
func = function(name, param)
216217
if param == "" then
217218
return false, "Invalid parameters (see /help grantme)"
218-
end
219+
end
219220
return handle_grant_command(name, name, param)
220221
end,
221222
})

Diff for: ‎doc/lua_api.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2076,6 +2076,7 @@ Call these functions only at load time!
20762076

20772077
### Other registration functions
20782078
* `minetest.register_chatcommand(cmd, chatcommand definition)`
2079+
* Adds definition to minetest.registered_chatcommands
20792080
* `minetest.register_privilege(name, definition)`
20802081
* `definition`: `"description text"`
20812082
* `definition`: `{ description = "description text", give_to_singleplayer = boolean}`

0 commit comments

Comments
 (0)
Please sign in to comment.