1 local safe_region_callback
\r
2 local safe_region_name
\r
3 local safe_region_param
\r
5 check_region = function(name, param)
\r
7 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
8 if pos1 == nil or pos2 == nil then
\r
9 worldedit.player_notify(name, "no region selected")
\r
13 return worldedit.volume(pos1, pos2)
\r
16 --`callback` is a callback to run when the user confirms
\r
17 --`nodes_needed` is a function accepting `param`, `pos1`, and `pos2` to calculate the number of nodes needed
\r
18 safe_region = function(callback, nodes_needed)
\r
19 --default node volume calculation
\r
20 nodes_needed = nodes_needed or check_region
\r
22 return function(name, param)
\r
23 --check if the operation applies to a safe number of nodes
\r
24 local count = nodes_needed(name, param)
\r
25 if count == nil then return end --invalid command
\r
26 if count < 10000 then
\r
27 return callback(name, param)
\r
30 --save callback to call later
\r
31 safe_region_callback, safe_region_name, safe_region_param = callback, name, param
\r
32 worldedit.player_notify(name, "WARNING: this operation could affect up to " .. count .. " nodes; type //y to continue or //n to cancel")
\r
36 minetest.register_chatcommand("/y", {
\r
38 description = "Confirm a pending operation",
\r
40 local callback, name, param = safe_region_callback, safe_region_name, safe_region_param
\r
41 if not callback then
\r
42 worldedit.player_notify(name, "no operation pending")
\r
47 local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
\r
48 if pos1 == nil or pos2 == nil then
\r
49 worldedit.player_notify(name, "no region selected")
\r
53 safe_region_callback, safe_region_name, safe_region_param = nil, nil, nil --reset pending operation
\r
54 callback(name, param, pos1, pos2)
\r
58 minetest.register_chatcommand("/n", {
\r
60 description = "Confirm a pending operation",
\r
62 if not safe_region_callback then
\r
63 worldedit.player_notify(name, "no operation pending")
\r
66 safe_region_callback, safe_region_name, safe_region_param = nil, nil, nil
\r