Skip to content
Permalink
Browse files
Fix safe region functionality (thanks ChaosWormz).
  • Loading branch information
Uberi committed Apr 20, 2014
1 parent 2784a25 commit 4660927ca0276c099737f61e50d54a9089b003e9
Showing 1 changed file with 10 additions and 13 deletions.
@@ -1,15 +1,12 @@
local safe_region_callback
local safe_region_name
local safe_region_param
local safe_region_callback = {}
local safe_region_param = {}

check_region = function(name, param)
--obtain positions
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] --obtain positions
if pos1 == nil or pos2 == nil then
worldedit.player_notify(name, "no region selected")
return nil
end

return worldedit.volume(pos1, pos2)
end

@@ -28,16 +25,16 @@ safe_region = function(callback, nodes_needed)
end

--save callback to call later
safe_region_callback, safe_region_name, safe_region_param = callback, name, param
safe_region_callback[name], safe_region_param[name] = callback, 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
func = function(name)
local callback, param = safe_region_callback[name], safe_region_param[name]
if not callback then
worldedit.player_notify(name, "no operation pending")
return
@@ -50,19 +47,19 @@ minetest.register_chatcommand("/y", {
return
end

safe_region_callback, safe_region_name, safe_region_param = nil, nil, nil --reset pending operation
safe_region_callback[name], safe_region_param[name] = 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
func = function(name)
if not safe_region_callback[name] then
worldedit.player_notify(name, "no operation pending")
return
end
safe_region_callback, safe_region_name, safe_region_param = nil, nil, nil
safe_region_callback[name], safe_region_param[name] = nil, nil
end,
})

0 comments on commit 4660927

Please sign in to comment.