1 local safe_region_callback = {}
\r
2 local safe_region_param = {}
\r
4 worldedit._override_safe_regions = false -- internal use ONLY!
\r
6 local function check_region(name, param)
\r
7 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] --obtain positions
\r
8 if pos1 == nil or pos2 == nil then
\r
9 worldedit.player_notify(name, "no region selected")
\r
12 return worldedit.volume(pos1, pos2)
\r
15 --`callback` is a callback to run when the user confirms
\r
16 --`nodes_needed` is a function accepting `param`, `pos1`, and `pos2` to calculate the number of nodes needed
\r
17 local function safe_region(callback, nodes_needed)
\r
18 --default node volume calculation
\r
19 nodes_needed = nodes_needed or check_region
\r
21 return function(name, param)
\r
22 --check if the operation applies to a safe number of nodes
\r
23 local count = nodes_needed(name, param)
\r
24 if count == nil then return end --invalid command
\r
25 if worldedit._override_safe_regions or count < 10000 then
\r
26 return callback(name, param)
\r
29 --save callback to call later
\r
30 safe_region_callback[name], safe_region_param[name] = callback, param
\r
31 worldedit.player_notify(name, "WARNING: this operation could affect up to " .. count .. " nodes; type //y to continue or //n to cancel")
\r
35 local function reset_pending(name)
\r
36 safe_region_callback[name], safe_region_param[name] = nil, nil
\r
39 minetest.register_chatcommand("/y", {
\r
41 description = "Confirm a pending operation",
\r
42 func = function(name)
\r
43 local callback, param = safe_region_callback[name], safe_region_param[name]
\r
44 if not callback then
\r
45 worldedit.player_notify(name, "no operation pending")
\r
50 callback(name, param)
\r
54 minetest.register_chatcommand("/n", {
\r
56 description = "Abort a pending operation",
\r
57 func = function(name)
\r
58 if not safe_region_callback[name] then
\r
59 worldedit.player_notify(name, "no operation pending")
\r
68 return safe_region, check_region, reset_pending
\r