implemented chatcommand_handler

This commit is contained in:
VorTechnix 2021-06-30 08:36:04 -07:00
parent ba93cb7bea
commit 9ad27404b0
5 changed files with 44 additions and 3 deletions

@ -1,4 +1,4 @@
function worldeditadditions.register_command(def)
function worldeditadditions_core.register_command(def)
local def = table.copy(def)
assert(name and #name > 0)
assert(def.privs)

@ -0,0 +1,40 @@
function worldeditadditions_core.chatcommand_handler(cmd_name, name, param)
local def = assert(worldedit.registered_commands[cmd_name])
if def.require_pos == 2 then
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
if pos1 == nil or pos2 == nil then
worldedit.player_notify(name, "no region selected")
return
end
elseif def.require_pos == 1 then
local pos1 = worldedit.pos1[name]
if pos1 == nil then
worldedit.player_notify(name, "no position 1 selected")
return
end
end
local parsed = {def.parse(param)}
local success = table.remove(parsed, 1)
if not success then
worldedit.player_notify(name, parsed[1] or "invalid usage")
return
end
if def.nodes_needed then
local count = def.nodes_needed(name, unpack(parsed))
safe_region(name, count, function()
local success, msg = def.func(name, unpack(parsed))
if msg then
minetest.chat_send_player(name, msg)
end
end)
else
-- no "safe region" check
local success, msg = def.func(name, unpack(parsed))
if msg then
minetest.chat_send_player(name, msg)
end
end
end

@ -11,5 +11,6 @@
local we_cm = worldeditadditions_core.modpath .. "/register/"
dofile(we_cm.."check.lua")
dofile(we_cm.."handler.lua")
dofile(we_cm.."register.lua")
dofile(we_cm.."override.lua")

@ -11,7 +11,7 @@ function we_c.override_command(name, def)
params = def.params,
description = def.description,
func = function(player_name, param)
return chatcommand_handler(name, player_name, param)
return we_c.chatcommand_handler(name, player_name, param)
end,
})
worldedit.registered_commands[name] = def

@ -11,7 +11,7 @@ function we_c.register_command(name, def)
params = def.params,
description = def.description,
func = function(player_name, param)
return chatcommand_handler(name, player_name, param)
return we_c.chatcommand_handler(name, player_name, param)
end,
})
worldedit.registered_commands[name] = def