mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-27 17:43:53 +01:00
implemented chatcommand_handler
This commit is contained in:
parent
ba93cb7bea
commit
9ad27404b0
@ -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)
|
||||
|
40
worldeditadditions_core/register/handler.lua
Normal file
40
worldeditadditions_core/register/handler.lua
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user