2017-06-21 12:55:25 +02:00
|
|
|
local area_protection = {}
|
|
|
|
|
|
|
|
if minetest.get_modpath(
|
|
|
|
"areas"
|
|
|
|
) then
|
|
|
|
area_protection.areas = areas
|
|
|
|
end
|
|
|
|
|
2014-04-20 05:33:20 +02:00
|
|
|
local safe_region_callback = {}
|
|
|
|
local safe_region_param = {}
|
2014-03-12 21:11:00 +01:00
|
|
|
|
2015-05-17 01:52:11 +02:00
|
|
|
local function check_region(name, param)
|
2014-04-20 05:33:20 +02:00
|
|
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] --obtain positions
|
2014-03-15 19:28:47 +01:00
|
|
|
if pos1 == nil or pos2 == nil then
|
|
|
|
worldedit.player_notify(name, "no region selected")
|
|
|
|
return nil
|
|
|
|
end
|
2017-06-21 12:55:25 +02:00
|
|
|
if nil ~= area_protection.areas then
|
|
|
|
local allowed, conflicting = area_protection.areas:canInteractInArea(
|
|
|
|
pos1,
|
|
|
|
pos2,
|
|
|
|
name,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
if false == allowed then
|
|
|
|
worldedit.player_notify(
|
|
|
|
name,
|
|
|
|
"region conflicts with non-owned region " .. conflicting
|
|
|
|
)
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
2014-03-15 19:28:47 +01:00
|
|
|
return worldedit.volume(pos1, pos2)
|
|
|
|
end
|
|
|
|
|
2014-03-12 21:11:00 +01:00
|
|
|
--`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
|
2015-05-17 01:52:11 +02:00
|
|
|
local function safe_region(callback, nodes_needed)
|
2014-03-12 21:11:00 +01:00
|
|
|
--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
|
2014-04-20 05:33:20 +02:00
|
|
|
safe_region_callback[name], safe_region_param[name] = callback, param
|
2014-10-25 07:53:20 +02:00
|
|
|
worldedit.player_notify(name, "WARNING: this operation could affect up to " .. count .. " nodes; type //y to continue or //n to cancel")
|
2014-03-12 21:11:00 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-31 19:52:54 +01:00
|
|
|
local function reset_pending(name)
|
|
|
|
safe_region_callback[name], safe_region_param[name] = nil, nil
|
|
|
|
end
|
|
|
|
|
2014-10-25 07:53:20 +02:00
|
|
|
minetest.register_chatcommand("/y", {
|
2014-03-12 21:11:00 +01:00
|
|
|
params = "",
|
|
|
|
description = "Confirm a pending operation",
|
2014-04-20 05:33:20 +02:00
|
|
|
func = function(name)
|
|
|
|
local callback, param = safe_region_callback[name], safe_region_param[name]
|
2014-03-12 21:11:00 +01:00
|
|
|
if not callback then
|
|
|
|
worldedit.player_notify(name, "no operation pending")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2014-04-20 05:33:20 +02:00
|
|
|
safe_region_callback[name], safe_region_param[name] = nil, nil --reset pending operation
|
2017-01-31 19:52:54 +01:00
|
|
|
callback(name, param)
|
2014-03-12 21:11:00 +01:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2014-10-25 07:53:20 +02:00
|
|
|
minetest.register_chatcommand("/n", {
|
2014-03-12 21:11:00 +01:00
|
|
|
params = "",
|
|
|
|
description = "Confirm a pending operation",
|
2014-04-20 05:33:20 +02:00
|
|
|
func = function(name)
|
|
|
|
if not safe_region_callback[name] then
|
2014-03-12 21:11:00 +01:00
|
|
|
worldedit.player_notify(name, "no operation pending")
|
|
|
|
return
|
|
|
|
end
|
2014-04-20 05:33:20 +02:00
|
|
|
safe_region_callback[name], safe_region_param[name] = nil, nil
|
2014-03-12 21:11:00 +01:00
|
|
|
end,
|
|
|
|
})
|
2015-05-17 01:52:11 +02:00
|
|
|
|
|
|
|
|
2017-06-21 12:55:25 +02:00
|
|
|
return safe_region, check_region, reset_pending, area_protection
|