From f7b832508f7c8234770cadc73ef6c9a4511ab5c7 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Mon, 8 Mar 2021 18:53:01 +0100 Subject: [PATCH] cleanup --- mods/MISC/mcl_commands/init.lua | 34 +++++++++++++++++++------------- mods/MISC/mcl_commands/title.lua | 1 + 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/mods/MISC/mcl_commands/init.lua b/mods/MISC/mcl_commands/init.lua index 5b504b17ab..6ce426c781 100644 --- a/mods/MISC/mcl_commands/init.lua +++ b/mods/MISC/mcl_commands/init.lua @@ -27,26 +27,22 @@ mcl_commands.types = { function mcl_commands.register_command(name, func, def) def = def or {} - local cmd = mcl_commands.build(func) - cmd.def = def - def.func = cmd.run + local cmd = mcl_commands.build(func, def) if minetest.registered_chatcommands[name] then error("[mcl_commands] Failed to register command: ["..name.."] command already existing! Use mcl_commands.overide_command() if you want to overide existing command") end - minetest.register_chatcommand(name, def) + minetest.register_chatcommand(name, cmd) minetest.log("action", "[mcl_commands] ["..name.."] command registered successfully") return cmd end function mcl_commands.overide_command(name, func, def) def = def or {} - local cmd = mcl_commands.build(func) - cmd.def = def - def.func = cmd.run + local cmd = mcl_commands.build(func, def) if minetest.registered_chatcommands[name] then minetest.unregister_chatcommand(name) end - minetest.register_chatcommand(name, def) + minetest.register_chatcommand(name, cmd) minetest.log("action", "[mcl_commands] ["..name.."] command overridden successfully") return cmd end @@ -65,7 +61,7 @@ end local dprint = function() end -function mcl_commands.build(func) +function mcl_commands.build(func, def) local cmd = { _subs = {} } @@ -80,8 +76,9 @@ function mcl_commands.build(func) pattern = "^", params = {}, func = def.func, - privs = def.privs or {} - desc = def.desc + privs = def.privs or {}, + desc = def.desc, + params_desc = def.params or "", } -- End of param reached: add it to the pattern @@ -181,7 +178,7 @@ function mcl_commands.build(func) func(cmd) end - cmd.run = function(name, param) + cmd.func = function(name, param) for i = 1, #cmd._subs do local sub = cmd._subs[i] local res = { string.match(param, sub.pattern) } @@ -219,13 +216,22 @@ function mcl_commands.build(func) return sub.func(unpack(params)) end else - return false, "You don't have permission to run this command (missing privilege: "..minetest.serialize(missing_privs)..")" + return false, "You don't have permission to run this command (missing privilege: "..minetest.serialize(missing_privs)..")" --TODO:replace message end end end return false, "Invalid command" end - + if not def.params then + def.params = "" + end + local params_help = "" + for i = 1, #cmd._subs do + params_help = params_help..def.params.." "..cmd._subs[i].params_desc.." " + end + cmd.params = params_help + cmd.privs = def.privs + cmd.description = def.description return cmd end diff --git a/mods/MISC/mcl_commands/title.lua b/mods/MISC/mcl_commands/title.lua index c06b8e52a6..082038cc72 100644 --- a/mods/MISC/mcl_commands/title.lua +++ b/mods/MISC/mcl_commands/title.lua @@ -108,6 +108,7 @@ mcl_commands.register_command("title", function(cmd) func = function(name, target, json) return mcl_title.set(target, "title", json) end, + params = "", }) cmd:sub(":name:username subtitle :params:json", { func = function(name, target, json)