forked from VoxeLibre/VoxeLibre
add public API to properly (take care of mcl_builtin_commands_overide) rename and alias chat command
This commit is contained in:
parent
884097a8e5
commit
f90243f6e5
|
@ -38,6 +38,20 @@ Register a complex chatcommand. If a chat command with the same name is already
|
|||
|
||||
Same as above but will overide existing command.
|
||||
|
||||
### `mcl_commands.register_chatcommand_alias(alias, cmd, [bypass])`
|
||||
|
||||
Register an alias called `alias` of the `cmd` command.
|
||||
If the setting `mcl_builtin_commands_overide` is set to `false`, the function will silently fail.
|
||||
If `bypass` is set to `true` the function will not take care of the above setting.
|
||||
Will warn if trying to alias to already existing command.
|
||||
|
||||
### `mcl_commands.rename_chatcommand(newname, cmd, [bypass])`
|
||||
|
||||
Rename `cmd` command to `newname`.
|
||||
If the setting `mcl_builtin_commands_overide` is set to `false`, the function will silently fail.
|
||||
If `bypass` is set to `true` the function will not take care of the above setting.
|
||||
Will warn if trying to rename to already existing command.
|
||||
|
||||
### paterns
|
||||
|
||||
mcl_commands adds many types for patterns
|
||||
|
|
|
@ -238,4 +238,29 @@ function mcl_commands.build(name, chat_def)
|
|||
cmd.privs = chat_def.privs
|
||||
cmd.description = chat_def.description
|
||||
return cmd
|
||||
end
|
||||
|
||||
function mcl_commands.register_chatcommand_alias(alias, cmd, bypass)
|
||||
if not bypass then bypass = false end
|
||||
if minetest.registered_chatcommands[alias] then
|
||||
minetest.log("warning", "[mcl_commands] trying to alias ["..cmd.."] to already existing ["..alias.."] command")
|
||||
elseif minetest.settings:get_bool("mcl_builtin_commands_overide", true) or bypass then
|
||||
minetest.register_chatcommand(alias, minetest.chatcommands[cmd])
|
||||
minetest.log("action", "[mcl_commands] ["..cmd.."] command aliased successfully to ["..alias.."]")
|
||||
else
|
||||
minetest.log("action", "[mcl_commands] ["..cmd.."] command not aliased to ["..alias.."]")
|
||||
end
|
||||
end
|
||||
|
||||
function mcl_commands.rename_chatcommand(newname, cmd, bypass)
|
||||
if not bypass then bypass = false end
|
||||
if minetest.registered_chatcommands[alias] then
|
||||
minetest.log("warning", "[mcl_commands] trying to rename ["..cmd.."] to already existing ["..alias.."] command")
|
||||
elseif minetest.settings:get_bool("mcl_builtin_commands_overide", true) or bypass then
|
||||
minetest.register_chatcommand(newname, minetest.chatcommands[cmd])
|
||||
minetest.unregister_chatcommand(cmd)
|
||||
minetest.log("action", "[mcl_commands] ["..cmd.."] command renamed successfully to ["..newname.."]")
|
||||
else
|
||||
minetest.log("action", "[mcl_commands] ["..cmd.."] command not renamed to ["..newname.."]")
|
||||
end
|
||||
end
|
|
@ -1,30 +1,23 @@
|
|||
local S = minetest.get_translator("mcl_commands")
|
||||
|
||||
local function register_chatcommand_alias(alias, cmd)
|
||||
local def = minetest.chatcommands[cmd]
|
||||
minetest.register_chatcommand(alias, def)
|
||||
end
|
||||
mcl_commands.register_chatcommand_alias("?", "help", false)
|
||||
mcl_commands.register_chatcommand_alias("pardon", "unban", false)
|
||||
mcl_commands.rename_chatcommand("stop", "shutdown", false)
|
||||
mcl_commands.register_chatcommand_alias("tell", "msg", false)
|
||||
mcl_commands.register_chatcommand_alias("w", "msg", false)
|
||||
mcl_commands.register_chatcommand_alias("tp", "teleport", false)
|
||||
mcl_commands.rename_chatcommand("clear", "clearinv", false)
|
||||
|
||||
local function rename_chatcommand(newname, cmd)
|
||||
local def = minetest.chatcommands[cmd]
|
||||
minetest.register_chatcommand(newname, def)
|
||||
minetest.unregister_chatcommand(cmd)
|
||||
end
|
||||
|
||||
if minetest.settings:get_bool("mcl_builtin_commands_overide", true) then
|
||||
register_chatcommand_alias("?", "help")
|
||||
register_chatcommand_alias("pardon", "unban")
|
||||
rename_chatcommand("stop", "shutdown")
|
||||
register_chatcommand_alias("tell", "msg")
|
||||
register_chatcommand_alias("w", "msg")
|
||||
register_chatcommand_alias("tp", "teleport")
|
||||
rename_chatcommand("clear", "clearinv")
|
||||
|
||||
minetest.register_chatcommand("banlist", {
|
||||
description = S("List bans"),
|
||||
privs = minetest.chatcommands["ban"].privs,
|
||||
func = function(name)
|
||||
return true, S("Ban list: @1", minetest.get_ban_list())
|
||||
end,
|
||||
})
|
||||
end
|
||||
mcl_commands.register_command("banlist", {
|
||||
func = function(cmd)
|
||||
cmd:sub("", {
|
||||
func = function(name)
|
||||
return true, S("Ban list: @1", minetest.get_ban_list())
|
||||
end,
|
||||
privs = {},
|
||||
})
|
||||
end,
|
||||
description = S("List bans"),
|
||||
params = "",
|
||||
privs = minetest.chatcommands["ban"].privs,
|
||||
})
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
local S = minetest.get_translator("mcl_commands")
|
||||
|
||||
minetest.register_chatcommand("list", {
|
||||
description = S("Show who is logged on"),
|
||||
mcl_commands.register_command("list", {
|
||||
func = function(cmd)
|
||||
cmd:sub("", {
|
||||
func = function(name)
|
||||
local players = ""
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
players = players..player:get_player_name().."\n"
|
||||
end
|
||||
return true, players
|
||||
end,
|
||||
privs = {},
|
||||
})
|
||||
end,
|
||||
description = S("Show who is logged on"),
|
||||
params = "",
|
||||
privs = {},
|
||||
func = function(name)
|
||||
local players = ""
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
players = players..player:get_player_name().."\n"
|
||||
end
|
||||
minetest.chat_send_player(name, players)
|
||||
end
|
||||
privs = {},
|
||||
})
|
|
@ -1,10 +1,15 @@
|
|||
local S = minetest.get_translator("mcl_commands")
|
||||
|
||||
minetest.register_chatcommand("seed", {
|
||||
description = S("Displays the world seed"),
|
||||
mcl_commands.register_command("seed", {
|
||||
func = function(cmd)
|
||||
cmd:sub("", {
|
||||
func = function(name)
|
||||
return true, "Seed: "..minetest.get_mapgen_setting("seed")
|
||||
end,
|
||||
privs = {},
|
||||
})
|
||||
end,
|
||||
description = S("Displays the world seed"),
|
||||
params = "",
|
||||
privs = {},
|
||||
func = function(name)
|
||||
minetest.chat_send_player(name, "Seed: "..minetest.get_mapgen_setting("seed"))
|
||||
end
|
||||
privs = {},
|
||||
})
|
Loading…
Reference in New Issue