forked from VoxeLibre/VoxeLibre
improve chat command definition
This commit is contained in:
parent
155548f384
commit
43c641f84f
|
@ -25,9 +25,9 @@ mcl_commands.types = {
|
|||
json = "(.+)",
|
||||
}
|
||||
|
||||
function mcl_commands.register_command(name, func, def)
|
||||
function mcl_commands.register_command(name, def)
|
||||
def = def or {}
|
||||
local cmd = mcl_commands.build(func, def)
|
||||
local cmd = mcl_commands.build(name, 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
|
||||
|
@ -36,9 +36,9 @@ function mcl_commands.register_command(name, func, def)
|
|||
return cmd
|
||||
end
|
||||
|
||||
function mcl_commands.overide_command(name, func, def)
|
||||
function mcl_commands.overide_command(name, def)
|
||||
def = def or {}
|
||||
local cmd = mcl_commands.build(func, def)
|
||||
local cmd = mcl_commands.build(name, def)
|
||||
if minetest.registered_chatcommands[name] then
|
||||
minetest.unregister_chatcommand(name)
|
||||
end
|
||||
|
@ -61,7 +61,7 @@ end
|
|||
|
||||
local dprint = function() end
|
||||
|
||||
function mcl_commands.build(func, def)
|
||||
function mcl_commands.build(def)
|
||||
local cmd = {
|
||||
_subs = {}
|
||||
}
|
||||
|
@ -174,8 +174,8 @@ function mcl_commands.build(func, def)
|
|||
table.insert(self._subs, sub)
|
||||
end
|
||||
|
||||
if func then
|
||||
func(cmd)
|
||||
if def.func then
|
||||
def.func(cmd)
|
||||
end
|
||||
|
||||
cmd.func = function(name, param)
|
||||
|
@ -218,13 +218,17 @@ function mcl_commands.build(func, def)
|
|||
else
|
||||
local missing_privs_str = ""
|
||||
for i = 1, #missing_privs do
|
||||
if not i == #missing_privs then
|
||||
missing_privs_str = missing_privs_str..missing_privs[i].." "
|
||||
else
|
||||
missing_privs_str = missing_privs_str..missing_privs[i]
|
||||
end
|
||||
end
|
||||
return false, "You don't have permission to run this command (missing privilege: "..missing_privs_str..")" --TODO:replace message
|
||||
end
|
||||
end
|
||||
end
|
||||
return false, "Invalid command"
|
||||
return false, "Invalid parameters: "
|
||||
end
|
||||
if not def.params then
|
||||
def.params = ""
|
||||
|
|
|
@ -4,15 +4,31 @@ minetest.register_privilege("announce", {
|
|||
description = S("Can use /say"),
|
||||
give_to_singleplayer = false,
|
||||
})
|
||||
minetest.register_chatcommand("say", {
|
||||
params = S("<message>"),
|
||||
description = S("Send a message to every player"),
|
||||
privs = {announce=true},
|
||||
func = function(name, param)
|
||||
if not param then
|
||||
return false, S("Invalid usage, see /help say.")
|
||||
end
|
||||
minetest.chat_send_all(("["..name.."] "..param))
|
||||
|
||||
mcl_commands.register_command("say", function(cmd)
|
||||
cmd:sub(":message:text", {
|
||||
func = function(name, message)
|
||||
minetest.chat_send_all(("["..name.."] "..message))
|
||||
return true
|
||||
end})
|
||||
end,
|
||||
{
|
||||
description = S("Send a message to every player"),
|
||||
params = S("<message>"),
|
||||
privs = {
|
||||
announce = true,
|
||||
}
|
||||
})
|
||||
|
||||
mcl_commands.register_command("say", {
|
||||
func = function(cmd)
|
||||
cmd:sub(":message:text", {
|
||||
func = function(name, message)
|
||||
minetest.chat_send_all(("["..name.."] "..message))
|
||||
return true
|
||||
end})
|
||||
end,
|
||||
description = S("Send a message to every player"),
|
||||
params = S("<message>"),
|
||||
privs = {announce = true},
|
||||
})
|
|
@ -103,7 +103,8 @@ function mcl_title.reset(playername)
|
|||
end
|
||||
end
|
||||
|
||||
mcl_commands.register_command("title", function(cmd)
|
||||
mcl_commands.register_command("title", {
|
||||
func = function(cmd)
|
||||
cmd:sub(":name:username title :params:json", {
|
||||
func = function(name, target, json)
|
||||
return mcl_title.set(target, "title", json)
|
||||
|
@ -134,10 +135,8 @@ mcl_commands.register_command("title", function(cmd)
|
|||
return mcl_title.reset(target)
|
||||
end,
|
||||
})
|
||||
end, {
|
||||
end,
|
||||
description = "Controls text displayed on the screen.",
|
||||
params = "<target> command <params>",
|
||||
privs = {
|
||||
server = true,
|
||||
}
|
||||
privs = {server = true},
|
||||
})
|
Loading…
Reference in New Issue