]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - builtin/common/chatcommands.lua
Merge branch 'master' of https://github.com/minetest/minetest
[dragonfireclient.git] / builtin / common / chatcommands.lua
index 7c3da0601c44546f5b82d84379506920183af7d5..817f1f526186d2657ba9084731d12adf844ec8d5 100644 (file)
@@ -69,6 +69,51 @@ function core.override_chatcommand(name, redefinition)
        core.registered_chatcommands[name] = chatcommand
 end
 
+if INIT == "client" then
+       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
+end
+
 local function format_help_line(cmd, def)
        local cmd_marker = INIT == "client" and "." or "/"
        local msg = core.colorize("#00ffff", cmd_marker .. cmd)