2022-05-17 00:32:40 +02:00
|
|
|
-- ██████ ███████ ██████ ██ ███████ ████████ ███████ ██████
|
|
|
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
|
|
|
-- ██████ █████ ██ ███ ██ ███████ ██ █████ ██████
|
|
|
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
|
|
|
-- ██ ██ ███████ ██████ ██ ███████ ██ ███████ ██ ██
|
|
|
|
|
|
|
|
-- WorldEditAdditions chat command registration
|
2022-05-19 03:31:01 +02:00
|
|
|
local wea_c = worldeditadditions_core
|
|
|
|
local run_command = dofile(wea_c.modpath.."/core/run_command.lua")
|
2022-05-17 00:32:40 +02:00
|
|
|
|
|
|
|
local function log_error(cmdname, error_message)
|
|
|
|
minetest.log("error", "register_command("..cmdname..") error: "..error_message)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function register_command(cmdname, options)
|
2022-05-19 02:45:36 +02:00
|
|
|
|
2022-05-17 00:32:40 +02:00
|
|
|
---
|
|
|
|
-- 1: Validation
|
|
|
|
---
|
|
|
|
if type(options.params) ~= "string" then
|
|
|
|
log_error(cmdname, "The params option is not a string.")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
if type(options.description) ~= "string" then
|
|
|
|
log_error(cmdname, "The description option is not a string.")
|
|
|
|
return false
|
|
|
|
end
|
2022-05-19 03:40:05 +02:00
|
|
|
if type(options.parse) ~= "function" then
|
2022-05-17 00:32:40 +02:00
|
|
|
log_error(cmdname, "The parse option is not a function.")
|
|
|
|
return false
|
|
|
|
end
|
2022-05-19 03:40:05 +02:00
|
|
|
if type(options.func) ~= "function" then
|
2022-05-17 00:32:40 +02:00
|
|
|
log_error(cmdname, "The func option is not a function.")
|
|
|
|
return false
|
|
|
|
end
|
2022-05-19 03:32:17 +02:00
|
|
|
if wea_c.registered_commands[cmdname] and options.override ~= true then
|
2022-05-17 00:40:03 +02:00
|
|
|
log_error(cmdname, "A WorldEditAdditions command with that name is registered, but the option override is not set to true.")
|
|
|
|
return false
|
|
|
|
end
|
2022-05-17 00:32:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
-- 2: Normalisation
|
|
|
|
---
|
|
|
|
if not options.privs then options.privs = {} end
|
|
|
|
if not options.require_pos then options.require_pos = 0 end
|
2022-05-17 00:40:03 +02:00
|
|
|
if not options.nodes_needed then options.nodes_needed = function() return 0 end end
|
2022-05-17 00:32:40 +02:00
|
|
|
|
|
|
|
---
|
|
|
|
-- 3: Registration
|
|
|
|
---
|
|
|
|
minetest.register_chatcommand("/"..cmdname, {
|
|
|
|
params = options.params,
|
|
|
|
description = options.description,
|
|
|
|
privs = options.privs,
|
|
|
|
func = function(player_name, paramtext)
|
2022-05-17 02:03:58 +02:00
|
|
|
run_command(cmdname, options, player_name, paramtext)
|
2022-05-17 00:32:40 +02:00
|
|
|
end
|
|
|
|
})
|
2022-05-19 03:32:17 +02:00
|
|
|
wea_c.registered_commands[cmdname] = options
|
2022-05-19 23:13:09 +02:00
|
|
|
if minetest.global_exists("worldedit") then
|
|
|
|
worldedit.registered_commands[cmdname] = options
|
|
|
|
end
|
2022-05-17 00:32:40 +02:00
|
|
|
end
|
2022-05-17 00:41:09 +02:00
|
|
|
|
|
|
|
return register_command
|