]> git.lizzy.rs Git - worldedit.git/commitdiff
Add //help command (fixes #123)
authorsfan5 <sfan5@live.de>
Sun, 1 Jan 2017 21:26:58 +0000 (22:26 +0100)
committersfan5 <sfan5@live.de>
Sun, 1 Jan 2017 21:27:22 +0000 (22:27 +0100)
worldedit_commands/init.lua

index 088191ccc00e2ed56a43b8dc4f2e63ec98597488..7fcdb18efe71eb620a1acbbdcb1d5d5a638fc0d7 100644 (file)
@@ -93,6 +93,56 @@ minetest.register_chatcommand("/about", {
        end,\r
 })\r
 \r
+-- mostly copied from builtin/chatcommands.lua with minor modifications\r
+minetest.register_chatcommand("/help", {\r
+       privs = {},\r
+       params = "[all/<cmd>]",\r
+       description = "Get help for WorldEdit commands",\r
+       func = function(name, param)\r
+               local function is_we_command(cmd)\r
+                       return cmd:sub(0, 1) == "/"\r
+               end\r
+               local function format_help_line(cmd, def)\r
+                       local msg = minetest.colorize("#00ffff", "/"..cmd)\r
+                       if def.params and def.params ~= "" then\r
+                               msg = msg .. " " .. def.params\r
+                       end\r
+                       if def.description and def.description ~= "" then\r
+                               msg = msg .. ": " .. def.description\r
+                       end\r
+                       return msg\r
+               end\r
+\r
+               if not minetest.check_player_privs(name, "worldedit") then\r
+                       return false, "You are not allowed to use any WorldEdit commands."\r
+               end\r
+               if param == "" then\r
+                       local msg = ""\r
+                       local cmds = {}\r
+                       for cmd, def in pairs(minetest.chatcommands) do\r
+                               if is_we_command(cmd) and minetest.check_player_privs(name, def.privs) then\r
+                                       cmds[#cmds + 1] = cmd:sub(2) -- strip the /\r
+                               end\r
+                       end\r
+                       table.sort(cmds)\r
+                       return true, "Available commands: " .. table.concat(cmds, " ") .. "\n"\r
+                                       .. "Use '//help <cmd>' to get more information,"\r
+                                       .. " or '//help all' to list everything."\r
+               elseif param == "all" then\r
+                       local cmds = {}\r
+                       for cmd, def in pairs(minetest.chatcommands) do\r
+                               if is_we_command(cmd) and minetest.check_player_privs(name, def.privs) then\r
+                                       cmds[#cmds + 1] = format_help_line(cmd, def)\r
+                               end\r
+                       end\r
+                       table.sort(cmds)\r
+                       return true, "Available commands:\n"..table.concat(cmds, "\n")\r
+               else\r
+                       return minetest.chatcommands["help"].func(name, "/" .. param)\r
+               end\r
+       end,\r
+})\r
+\r
 minetest.register_chatcommand("/inspect", {\r
        params = "on/off/1/0/true/false/yes/no/enable/disable/<blank>",\r
        description = "Enable or disable node inspection",\r