diff options
Diffstat (limited to 'builtin/common/chatcommands.lua')
-rw-r--r-- | builtin/common/chatcommands.lua | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/builtin/common/chatcommands.lua b/builtin/common/chatcommands.lua index 52edda659..3d04391fb 100644 --- a/builtin/common/chatcommands.lua +++ b/builtin/common/chatcommands.lua @@ -29,6 +29,49 @@ function core.override_chatcommand(name, redefinition) core.registered_chatcommands[name] = chatcommand end +function core.register_list_command(command, desc, setting) + local def = {} + def.description = desc + def.params = "del <item> | add <item> | list" + function def.func(param) + local list = (minetest.settings:get(setting) or ""):split(",") + if param == "list" then + return true, table.concat(list, ", ") + else + local sparam = param:split(" ") + local cmd = sparam[1] + local item = sparam[2] + if cmd == "del" then + if not item then + return false, "Missing item." + end + local i = table.indexof(list, item) + if i == -1 then + return false, item .. " is not on the list." + else + table.remove(list, i) + core.settings:set(setting, table.concat(list, ",")) + return true, "Removed " .. item .. " from the list." + end + elseif cmd == "add" then + if not item then + return false, "Missing item." + end + local i = table.indexof(list, item) + if i ~= -1 then + return false, item .. " is already on the list." + else + table.insert(list, item) + core.settings:set(setting, table.concat(list, ",")) + return true, "Added " .. item .. " to the list." + end + end + end + return false, "Invalid usage. (See /help " .. command .. ")" + end + core.register_chatcommand(command, def) +end + local cmd_marker = "/" local function gettext(...) |