core: finish initial register_command

This commit is contained in:
Starbeamrainbowlabs 2022-05-16 23:40:03 +01:00
parent 19c8d0e7b9
commit fa9b511e33
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2

@ -5,6 +5,9 @@
-- ██ ██ ███████ ██████ ██ ███████ ██ ███████ ██ ██ -- ██ ██ ███████ ██████ ██ ███████ ██ ███████ ██ ██
-- WorldEditAdditions chat command registration -- WorldEditAdditions chat command registration
local we_c = worldeditadditions_core
local run_command = dofile(we_c.modpath.."/core/run_command.lua")
local function log_error(cmdname, error_message) local function log_error(cmdname, error_message)
minetest.log("error", "register_command("..cmdname..") error: "..error_message) minetest.log("error", "register_command("..cmdname..") error: "..error_message)
@ -30,6 +33,10 @@ local function register_command(cmdname, options)
log_error(cmdname, "The func option is not a function.") log_error(cmdname, "The func option is not a function.")
return false return false
end end
if we_c.registered_commands[cmdname] and options.override ~= true then
log_error(cmdname, "A WorldEditAdditions command with that name is registered, but the option override is not set to true.")
return false
end
--- ---
@ -37,7 +44,7 @@ local function register_command(cmdname, options)
--- ---
if not options.privs then options.privs = {} end if not options.privs then options.privs = {} end
if not options.require_pos then options.require_pos = 0 end if not options.require_pos then options.require_pos = 0 end
if not options.nodes_needed then options.nodes_needed = function() return 0 end if not options.nodes_needed then options.nodes_needed = function() return 0 end end
--- ---
-- 3: Registration -- 3: Registration
@ -47,8 +54,8 @@ local function register_command(cmdname, options)
description = options.description, description = options.description,
privs = options.privs, privs = options.privs,
func = function(player_name, paramtext) func = function(player_name, paramtext)
-- TODO: Fill this in run_command(cmdname, player_name, paramtext)
end end
}) })
we_c.registered_commands[cmdname] = options
end end