From b29523db4df4d793165672cda8adb3090d8b9ffe Mon Sep 17 00:00:00 2001 From: Uberi Date: Wed, 12 Mar 2014 16:11:00 -0400 Subject: Implement full size checking for every possible command. --- worldedit_commands/safe.lua | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 worldedit_commands/safe.lua (limited to 'worldedit_commands/safe.lua') diff --git a/worldedit_commands/safe.lua b/worldedit_commands/safe.lua new file mode 100644 index 0000000..6f83078 --- /dev/null +++ b/worldedit_commands/safe.lua @@ -0,0 +1,57 @@ +local safe_region_callback +local safe_region_name +local safe_region_param + +--`callback` is a callback to run when the user confirms +--`nodes_needed` is a function accepting `param`, `pos1`, and `pos2` to calculate the number of nodes needed +safe_region = function(callback, nodes_needed) + --default node volume calculation + nodes_needed = nodes_needed or check_region + + return function(name, param) + --check if the operation applies to a safe number of nodes + local count = nodes_needed(name, param) + if count == nil then return end --invalid command + if count < 10000 then + return callback(name, param) + end + + --save callback to call later + safe_region_callback, safe_region_name, safe_region_param = callback, name, param + worldedit.player_notify(name, "WARNING: this operation could affect up to " .. count .. " nodes; type //y to continue or //n to cancel") + end +end + +minetest.register_chatcommand("/y", { + params = "", + description = "Confirm a pending operation", + func = function() + local callback, name, param = safe_region_callback, safe_region_name, safe_region_param + if not callback then + worldedit.player_notify(name, "no operation pending") + return + end + + --obtain positions + 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 + + safe_region_callback, safe_region_name, safe_region_param = nil, nil, nil --reset pending operation + callback(name, param, pos1, pos2) + end, +}) + +minetest.register_chatcommand("/n", { + params = "", + description = "Confirm a pending operation", + func = function() + if not safe_region_callback then + worldedit.player_notify(name, "no operation pending") + return + end + safe_region_callback, safe_region_name, safe_region_param = nil, nil, nil + end, +}) -- cgit v1.2.3