mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2024-09-30 00:10:35 +02:00
move logic to method
This commit is contained in:
parent
3de6cdcf84
commit
19c9ca179b
|
@ -465,9 +465,9 @@ local check_sphere = function(name, param)
|
|||
worldedit.player_notify(name, "invalid usage: " .. param)
|
||||
return nil
|
||||
end
|
||||
if nil ~= area_protection.areas then
|
||||
local pos1 = worldedit.pos1[name]
|
||||
local allowed, conflicting = area_protection.areas:canInteractInArea(
|
||||
local allowed = area_protection:interaction_allowed(
|
||||
"sphere",
|
||||
{
|
||||
x = pos1.x - radius,
|
||||
y = pos1.y - radius,
|
||||
|
@ -478,17 +478,11 @@ local check_sphere = function(name, param)
|
|||
y = pos1.y + radius,
|
||||
z = pos1.z + radius,
|
||||
},
|
||||
name,
|
||||
false
|
||||
)
|
||||
if false == allowed then
|
||||
worldedit.player_notify(
|
||||
name,
|
||||
"sphere may conflict with non-owned region " .. conflicting
|
||||
name
|
||||
)
|
||||
if not allowed then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
local node = get_node(name, nodename)
|
||||
if not node then return nil end
|
||||
return math.ceil((4 * math.pi * (tonumber(radius) ^ 3)) / 3) --volume of sphere
|
||||
|
@ -528,9 +522,9 @@ local check_dome = function(name, param)
|
|||
worldedit.player_notify(name, "invalid usage: " .. param)
|
||||
return nil
|
||||
end
|
||||
if nil ~= area_protection.areas then
|
||||
local pos1 = worldedit.pos1[name]
|
||||
local allowed, conflicting = area_protection.areas:canInteractInArea(
|
||||
local allowed = area_protection:interaction_allowed(
|
||||
"dome",
|
||||
{
|
||||
x = pos1.x - radius,
|
||||
y = pos1.y,
|
||||
|
@ -541,17 +535,11 @@ local check_dome = function(name, param)
|
|||
y = pos1.y + radius,
|
||||
z = pos1.z + radius,
|
||||
},
|
||||
name,
|
||||
false
|
||||
)
|
||||
if false == allowed then
|
||||
worldedit.player_notify(
|
||||
name,
|
||||
"dome may conflict with non-owned region " .. conflicting
|
||||
name
|
||||
)
|
||||
if not allowed then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
local node = get_node(name, nodename)
|
||||
if not node then return nil end
|
||||
return math.ceil((2 * math.pi * (tonumber(radius) ^ 3)) / 3) --volume of dome
|
||||
|
@ -591,7 +579,6 @@ local check_cylinder = function(name, param)
|
|||
worldedit.player_notify(name, "invalid usage: " .. param)
|
||||
return nil
|
||||
end
|
||||
if nil ~= area_protection.areas then
|
||||
length = tonumber(length)
|
||||
if axis == "?" then
|
||||
local sign
|
||||
|
@ -620,20 +607,15 @@ local check_cylinder = function(name, param)
|
|||
interact_pos2[other1] = interact_pos2[other1] + radius
|
||||
interact_pos2[other2] = interact_pos2[other2] + radius
|
||||
interact_pos2[axis] = interact_pos2[axis] + length
|
||||
local allowed, conflicting = area_protection.areas:canInteractInArea(
|
||||
local allowed = area_protection:interaction_allowed(
|
||||
"cylinder",
|
||||
interact_pos1,
|
||||
interact_pos2,
|
||||
name,
|
||||
false
|
||||
)
|
||||
if false == allowed then
|
||||
worldedit.player_notify(
|
||||
name,
|
||||
"cylinder may conflict with non-owned region " .. conflicting
|
||||
name
|
||||
)
|
||||
if not allowed then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
local node = get_node(name, nodename)
|
||||
if not node then return nil end
|
||||
return math.ceil(math.pi * (tonumber(radius) ^ 2) * tonumber(length))
|
||||
|
|
|
@ -4,6 +4,31 @@ if minetest.get_modpath("areas") then
|
|||
area_protection.areas = areas
|
||||
end
|
||||
|
||||
local area_protection.interaction_allowed = function(
|
||||
area_protection,
|
||||
description,
|
||||
pos1,
|
||||
pos2,
|
||||
player_name
|
||||
)
|
||||
if area_protection.areas then
|
||||
local allowed, conflicting = area_protection.areas:canInteractInArea(
|
||||
pos1,
|
||||
pos2,
|
||||
player_name,
|
||||
false
|
||||
)
|
||||
if not allowed then
|
||||
worldedit.player_notify(
|
||||
player_name,
|
||||
description .. " conflicts with non-owned region " .. conflicting
|
||||
)
|
||||
end
|
||||
return allowed
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local safe_region_callback = {}
|
||||
local safe_region_param = {}
|
||||
|
||||
|
@ -13,21 +38,15 @@ local function check_region(name, param)
|
|||
worldedit.player_notify(name, "no region selected")
|
||||
return nil
|
||||
end
|
||||
if nil ~= area_protection.areas then
|
||||
local allowed, conflicting = area_protection.areas:canInteractInArea(
|
||||
local allowed = area_protection:interaction_allowed(
|
||||
"region",
|
||||
pos1,
|
||||
pos2,
|
||||
name,
|
||||
false
|
||||
)
|
||||
if false == allowed then
|
||||
worldedit.player_notify(
|
||||
name,
|
||||
"region conflicts with non-owned region " .. conflicting
|
||||
name
|
||||
)
|
||||
if not allowed then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
return worldedit.volume(pos1, pos2)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user