mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2024-11-18 00:18:13 +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)
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
if nil ~= area_protection.areas then
|
local pos1 = worldedit.pos1[name]
|
||||||
local pos1 = worldedit.pos1[name]
|
local allowed = area_protection:interaction_allowed(
|
||||||
local allowed, conflicting = area_protection.areas:canInteractInArea(
|
"sphere",
|
||||||
{
|
{
|
||||||
x = pos1.x - radius,
|
x = pos1.x - radius,
|
||||||
y = pos1.y - radius,
|
y = pos1.y - radius,
|
||||||
z = pos1.z - radius,
|
z = pos1.z - radius,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
x = pos1.x + radius,
|
x = pos1.x + radius,
|
||||||
y = pos1.y + radius,
|
y = pos1.y + radius,
|
||||||
z = pos1.z + radius,
|
z = pos1.z + radius,
|
||||||
},
|
},
|
||||||
name,
|
name
|
||||||
false
|
)
|
||||||
)
|
if not allowed then
|
||||||
if false == allowed then
|
return nil
|
||||||
worldedit.player_notify(
|
|
||||||
name,
|
|
||||||
"sphere may conflict with non-owned region " .. conflicting
|
|
||||||
)
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
local node = get_node(name, nodename)
|
local node = get_node(name, nodename)
|
||||||
if not node then return nil end
|
if not node then return nil end
|
||||||
@ -528,29 +522,23 @@ local check_dome = function(name, param)
|
|||||||
worldedit.player_notify(name, "invalid usage: " .. param)
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
if nil ~= area_protection.areas then
|
local pos1 = worldedit.pos1[name]
|
||||||
local pos1 = worldedit.pos1[name]
|
local allowed = area_protection:interaction_allowed(
|
||||||
local allowed, conflicting = area_protection.areas:canInteractInArea(
|
"dome",
|
||||||
{
|
{
|
||||||
x = pos1.x - radius,
|
x = pos1.x - radius,
|
||||||
y = pos1.y,
|
y = pos1.y,
|
||||||
z = pos1.z - radius,
|
z = pos1.z - radius,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
x = pos1.x + radius,
|
x = pos1.x + radius,
|
||||||
y = pos1.y + radius,
|
y = pos1.y + radius,
|
||||||
z = pos1.z + radius,
|
z = pos1.z + radius,
|
||||||
},
|
},
|
||||||
name,
|
name
|
||||||
false
|
)
|
||||||
)
|
if not allowed then
|
||||||
if false == allowed then
|
return nil
|
||||||
worldedit.player_notify(
|
|
||||||
name,
|
|
||||||
"dome may conflict with non-owned region " .. conflicting
|
|
||||||
)
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
local node = get_node(name, nodename)
|
local node = get_node(name, nodename)
|
||||||
if not node then return nil end
|
if not node then return nil end
|
||||||
@ -591,48 +579,42 @@ local check_cylinder = function(name, param)
|
|||||||
worldedit.player_notify(name, "invalid usage: " .. param)
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
if nil ~= area_protection.areas then
|
length = tonumber(length)
|
||||||
length = tonumber(length)
|
if axis == "?" then
|
||||||
if axis == "?" then
|
local sign
|
||||||
local sign
|
axis, sign = worldedit.player_axis(name)
|
||||||
axis, sign = worldedit.player_axis(name)
|
length = length * sign
|
||||||
length = length * sign
|
end
|
||||||
end
|
local pos1 = worldedit.pos1[name]
|
||||||
local pos1 = worldedit.pos1[name]
|
local current_pos = {x=pos1.x, y=pos1.y, z=pos1.z}
|
||||||
local current_pos = {x=pos1.x, y=pos1.y, z=pos1.z}
|
if length < 0 then
|
||||||
if length < 0 then
|
length = -length
|
||||||
length = -length
|
current_pos[axis] = current_pos[axis] - length
|
||||||
current_pos[axis] = current_pos[axis] - length
|
end
|
||||||
end
|
local other1, other2 = worldedit.get_axis_others(axis)
|
||||||
local other1, other2 = worldedit.get_axis_others(axis)
|
local interact_pos1 = {
|
||||||
local interact_pos1 = {
|
x = current_pos.x,
|
||||||
x = current_pos.x,
|
y = current_pos.y,
|
||||||
y = current_pos.y,
|
z = current_pos.z,
|
||||||
z = current_pos.z,
|
}
|
||||||
}
|
local interact_pos2 = {
|
||||||
local interact_pos2 = {
|
x = current_pos.x,
|
||||||
x = current_pos.x,
|
y = current_pos.y,
|
||||||
y = current_pos.y,
|
z = current_pos.z,
|
||||||
z = current_pos.z,
|
}
|
||||||
}
|
interact_pos1[other1] = interact_pos1[other1] - radius
|
||||||
interact_pos1[other1] = interact_pos1[other1] - radius
|
interact_pos1[other2] = interact_pos1[other2] - radius
|
||||||
interact_pos1[other2] = interact_pos1[other2] - radius
|
interact_pos2[other1] = interact_pos2[other1] + radius
|
||||||
interact_pos2[other1] = interact_pos2[other1] + radius
|
interact_pos2[other2] = interact_pos2[other2] + radius
|
||||||
interact_pos2[other2] = interact_pos2[other2] + radius
|
interact_pos2[axis] = interact_pos2[axis] + length
|
||||||
interact_pos2[axis] = interact_pos2[axis] + length
|
local allowed = area_protection:interaction_allowed(
|
||||||
local allowed, conflicting = area_protection.areas:canInteractInArea(
|
"cylinder",
|
||||||
interact_pos1,
|
interact_pos1,
|
||||||
interact_pos2,
|
interact_pos2,
|
||||||
name,
|
name
|
||||||
false
|
)
|
||||||
)
|
if not allowed then
|
||||||
if false == allowed then
|
return nil
|
||||||
worldedit.player_notify(
|
|
||||||
name,
|
|
||||||
"cylinder may conflict with non-owned region " .. conflicting
|
|
||||||
)
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
local node = get_node(name, nodename)
|
local node = get_node(name, nodename)
|
||||||
if not node then return nil end
|
if not node then return nil end
|
||||||
|
@ -4,6 +4,31 @@ if minetest.get_modpath("areas") then
|
|||||||
area_protection.areas = areas
|
area_protection.areas = areas
|
||||||
end
|
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_callback = {}
|
||||||
local safe_region_param = {}
|
local safe_region_param = {}
|
||||||
|
|
||||||
@ -13,20 +38,14 @@ local function check_region(name, param)
|
|||||||
worldedit.player_notify(name, "no region selected")
|
worldedit.player_notify(name, "no region selected")
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
if nil ~= area_protection.areas then
|
local allowed = area_protection:interaction_allowed(
|
||||||
local allowed, conflicting = area_protection.areas:canInteractInArea(
|
"region",
|
||||||
pos1,
|
pos1,
|
||||||
pos2,
|
pos2,
|
||||||
name,
|
name
|
||||||
false
|
)
|
||||||
)
|
if not allowed then
|
||||||
if false == allowed then
|
return nil
|
||||||
worldedit.player_notify(
|
|
||||||
name,
|
|
||||||
"region conflicts with non-owned region " .. conflicting
|
|
||||||
)
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return worldedit.volume(pos1, pos2)
|
return worldedit.volume(pos1, pos2)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user