mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2024-11-16 07:30:17 +01:00
move logic to method
This commit is contained in:
parent
3de6cdcf84
commit
19c9ca179b
|
@ -465,29 +465,23 @@ 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(
|
||||
{
|
||||
x = pos1.x - radius,
|
||||
y = pos1.y - radius,
|
||||
z = pos1.z - radius,
|
||||
},
|
||||
{
|
||||
x = pos1.x + radius,
|
||||
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
|
||||
)
|
||||
return nil
|
||||
end
|
||||
local pos1 = worldedit.pos1[name]
|
||||
local allowed = area_protection:interaction_allowed(
|
||||
"sphere",
|
||||
{
|
||||
x = pos1.x - radius,
|
||||
y = pos1.y - radius,
|
||||
z = pos1.z - radius,
|
||||
},
|
||||
{
|
||||
x = pos1.x + radius,
|
||||
y = pos1.y + radius,
|
||||
z = pos1.z + radius,
|
||||
},
|
||||
name
|
||||
)
|
||||
if not allowed then
|
||||
return nil
|
||||
end
|
||||
local node = get_node(name, nodename)
|
||||
if not node then return nil end
|
||||
|
@ -528,29 +522,23 @@ 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(
|
||||
{
|
||||
x = pos1.x - radius,
|
||||
y = pos1.y,
|
||||
z = pos1.z - radius,
|
||||
},
|
||||
{
|
||||
x = pos1.x + radius,
|
||||
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
|
||||
)
|
||||
return nil
|
||||
end
|
||||
local pos1 = worldedit.pos1[name]
|
||||
local allowed = area_protection:interaction_allowed(
|
||||
"dome",
|
||||
{
|
||||
x = pos1.x - radius,
|
||||
y = pos1.y,
|
||||
z = pos1.z - radius,
|
||||
},
|
||||
{
|
||||
x = pos1.x + radius,
|
||||
y = pos1.y + radius,
|
||||
z = pos1.z + radius,
|
||||
},
|
||||
name
|
||||
)
|
||||
if not allowed then
|
||||
return nil
|
||||
end
|
||||
local node = get_node(name, nodename)
|
||||
if not node then return nil end
|
||||
|
@ -591,48 +579,42 @@ 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
|
||||
axis, sign = worldedit.player_axis(name)
|
||||
length = length * sign
|
||||
end
|
||||
local pos1 = worldedit.pos1[name]
|
||||
local current_pos = {x=pos1.x, y=pos1.y, z=pos1.z}
|
||||
if length < 0 then
|
||||
length = -length
|
||||
current_pos[axis] = current_pos[axis] - length
|
||||
end
|
||||
local other1, other2 = worldedit.get_axis_others(axis)
|
||||
local interact_pos1 = {
|
||||
x = current_pos.x,
|
||||
y = current_pos.y,
|
||||
z = current_pos.z,
|
||||
}
|
||||
local interact_pos2 = {
|
||||
x = current_pos.x,
|
||||
y = current_pos.y,
|
||||
z = current_pos.z,
|
||||
}
|
||||
interact_pos1[other1] = interact_pos1[other1] - radius
|
||||
interact_pos1[other2] = interact_pos1[other2] - radius
|
||||
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(
|
||||
interact_pos1,
|
||||
interact_pos2,
|
||||
name,
|
||||
false
|
||||
)
|
||||
if false == allowed then
|
||||
worldedit.player_notify(
|
||||
name,
|
||||
"cylinder may conflict with non-owned region " .. conflicting
|
||||
)
|
||||
return nil
|
||||
end
|
||||
length = tonumber(length)
|
||||
if axis == "?" then
|
||||
local sign
|
||||
axis, sign = worldedit.player_axis(name)
|
||||
length = length * sign
|
||||
end
|
||||
local pos1 = worldedit.pos1[name]
|
||||
local current_pos = {x=pos1.x, y=pos1.y, z=pos1.z}
|
||||
if length < 0 then
|
||||
length = -length
|
||||
current_pos[axis] = current_pos[axis] - length
|
||||
end
|
||||
local other1, other2 = worldedit.get_axis_others(axis)
|
||||
local interact_pos1 = {
|
||||
x = current_pos.x,
|
||||
y = current_pos.y,
|
||||
z = current_pos.z,
|
||||
}
|
||||
local interact_pos2 = {
|
||||
x = current_pos.x,
|
||||
y = current_pos.y,
|
||||
z = current_pos.z,
|
||||
}
|
||||
interact_pos1[other1] = interact_pos1[other1] - radius
|
||||
interact_pos1[other2] = interact_pos1[other2] - radius
|
||||
interact_pos2[other1] = interact_pos2[other1] + radius
|
||||
interact_pos2[other2] = interact_pos2[other2] + radius
|
||||
interact_pos2[axis] = interact_pos2[axis] + length
|
||||
local allowed = area_protection:interaction_allowed(
|
||||
"cylinder",
|
||||
interact_pos1,
|
||||
interact_pos2,
|
||||
name
|
||||
)
|
||||
if not allowed then
|
||||
return nil
|
||||
end
|
||||
local node = get_node(name, nodename)
|
||||
if not node then return nil end
|
||||
|
|
|
@ -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,20 +38,14 @@ 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(
|
||||
pos1,
|
||||
pos2,
|
||||
name,
|
||||
false
|
||||
)
|
||||
if false == allowed then
|
||||
worldedit.player_notify(
|
||||
name,
|
||||
"region conflicts with non-owned region " .. conflicting
|
||||
)
|
||||
return nil
|
||||
end
|
||||
local allowed = area_protection:interaction_allowed(
|
||||
"region",
|
||||
pos1,
|
||||
pos2,
|
||||
name
|
||||
)
|
||||
if not allowed then
|
||||
return nil
|
||||
end
|
||||
return worldedit.volume(pos1, pos2)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user