core: add register_alias command

it is backwards-compatible with worldedit.register_command
This commit is contained in:
Starbeamrainbowlabs 2022-05-19 22:50:53 +01:00
parent c2c0fa5d8d
commit 1750d62d3c
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
3 changed files with 50 additions and 7 deletions

View file

@ -1,14 +1,16 @@
worldedit.alias_command("smoothadv", "convolve") local wea_c = worldeditadditions_core
worldedit.alias_command("conv", "convolve")
worldedit.alias_command("naturalise", "layers") wea_c.register_alias("smoothadv", "convolve")
worldedit.alias_command("naturalize", "layers") wea_c.register_alias("conv", "convolve")
worldedit.alias_command("flora", "bonemeal") wea_c.register_alias("naturalise", "layers")
wea_c.register_alias("naturalize", "layers")
wea_c.register_alias("flora", "bonemeal")
-- Measure Tools -- Measure Tools
worldedit.alias_command("mcount", "count") wea_c.register_alias("mcount", "count")
worldedit.alias_command("mfacing", "mface") wea_c.register_alias("mfacing", "mface")
--- Overrides to core WorldEdit commands --- Overrides to core WorldEdit commands

View file

@ -0,0 +1,40 @@
local wea_c = worldeditadditions_core
local function register_alias(cmdname_target, cmdname_source, override)
if override == nil then override = false end
local def_source = wea_c.fetch_command_def(cmdname_source)
if not def_source then
minetest.log("error", "worldeditadditions_core: Failed to register alias for "..cmdname_source..""..cmdname_target..", as the source command doesn't exist.")
return false
end
if wea_c.fetch_command_def(cmdname_target) and not override then
minetest.log("error", "worldeditadditions_core: Failed to register alias for "..cmdname_source..""..cmdname_target..", as the target command exists and override wasn't set to true.")
return false
end
print("DEBUG ALIAS source "..cmdname_source.." target "..cmdname_target)
if minetest.chatcommands["/"..cmdname_target] then
minetest.override_chatcommand(
"/"..cmdname_target,
minetest.chatcommands["/"..cmdname_source]
)
else
minetest.register_chatcommand(
"/"..cmdname_target,
minetest.chatcommands["/"..cmdname_source]
)
end
wea_c.registered_commands[cmdname_target] = wea_c.registered_commands[cmdname_source]
if minetest.global_exists("worldedit") then
worldedit.registered_commands[cmdname_target] = worldedit.registered_commands[cmdname_source]
end
end
return register_alias

View file

@ -25,6 +25,7 @@ worldeditadditions_core = {
local wea_c = worldeditadditions_core local wea_c = worldeditadditions_core
wea_c.register_command = dofile(modpath.."/core/register_command.lua") wea_c.register_command = dofile(modpath.."/core/register_command.lua")
wea_c.fetch_command_def = dofile(modpath.."/core/fetch_command_def.lua") wea_c.fetch_command_def = dofile(modpath.."/core/fetch_command_def.lua")
wea_c.register_alias = dofile(modpath.."/core/register_alias.lua")
-- Initialise WorldEdit stuff if the WorldEdit mod is not present -- Initialise WorldEdit stuff if the WorldEdit mod is not present