mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-12-24 01:30:38 +01:00
Update areas part 1
This commit is contained in:
parent
8f34a13a50
commit
21d96a9f00
@ -1,8 +1,9 @@
|
||||
--
|
||||
---
|
||||
|
||||
-- Returns a list of areas that include the provided position
|
||||
function areas:getAreasAtPos(pos)
|
||||
local a = {}
|
||||
local px, py, pz = pos.x, pos.y, pos.z
|
||||
local px, py, pz = pos.x, pos.y, pos.z
|
||||
for id, area in pairs(self.areas) do
|
||||
local ap1, ap2 = area.pos1, area.pos2
|
||||
if px >= ap1.x and px <= ap2.x and
|
||||
@ -42,17 +43,18 @@ end
|
||||
|
||||
--- Checks if the area intersects with an area that the player can't interact in.
|
||||
-- Note that this fails and returns false when the specified area is fully
|
||||
-- owned by the player, but with miltiple protection zones, none of which
|
||||
-- owned by the player, but with multiple protection zones, none of which
|
||||
-- cover the entire checked area.
|
||||
-- @param name (optional) player name. If not specified checks for any intersecting areas.
|
||||
-- @param allow_open Whether open areas should be counted as is they didn't exist.
|
||||
-- @return Boolean indicating whether the player can interact in that area.
|
||||
-- @return Un-owned intersecting area id, if found.
|
||||
function areas:canInteractInArea(pos1, pos2, name)
|
||||
function areas:canInteractInArea(pos1, pos2, name, allow_open)
|
||||
if name and minetest.check_player_privs(name, self.adminPrivs) then
|
||||
return true
|
||||
end
|
||||
areas:sortPos(pos1, pos2)
|
||||
-- First check for a fully enclosing owned area
|
||||
-- First check for a fully enclosing owned area.
|
||||
if name then
|
||||
for id, area in pairs(self.areas) do
|
||||
-- A little optimization: isAreaOwner isn't necessary
|
||||
@ -69,8 +71,11 @@ function areas:canInteractInArea(pos1, pos2, name)
|
||||
if (p1.x <= pos2.x and p2.x >= pos1.x) and
|
||||
(p1.y <= pos2.y and p2.y >= pos1.y) and
|
||||
(p1.z <= pos2.z and p2.z >= pos1.z) then
|
||||
-- Found an intersecting area
|
||||
if not name or not areas:isAreaOwner(id, name) then
|
||||
-- Found an intersecting area.
|
||||
-- Return if the area is closed or open areas aren't
|
||||
-- allowed, and the area isn't owned.
|
||||
if (not allow_open or not area.open) and
|
||||
(not name or not areas:isAreaOwner(id, name)) then
|
||||
return false, id
|
||||
end
|
||||
end
|
||||
|
@ -2,7 +2,7 @@
|
||||
minetest.register_chatcommand("protect", {
|
||||
params = "<AreaName>",
|
||||
description = "Protect your own area",
|
||||
privs = {[areas.self_protection_privilege]=true},
|
||||
privs = {[areas.config.self_protection_privilege]=true}
|
||||
func = function(name, param)
|
||||
if param == "" then
|
||||
return false, "Invalid usage, see /help protect."
|
||||
@ -143,6 +143,7 @@ minetest.register_chatcommand("rename_area", {
|
||||
minetest.register_chatcommand("find_areas", {
|
||||
params = "<regexp>",
|
||||
description = "Find areas using a Lua regular expression",
|
||||
privs = areas.adminPrivs,
|
||||
func = function(name, param)
|
||||
if param == "" then
|
||||
return false, "A regular expression is required."
|
||||
@ -156,14 +157,14 @@ minetest.register_chatcommand("find_areas", {
|
||||
return false, "Invalid regular expression."
|
||||
end
|
||||
|
||||
local matches = {}
|
||||
for id, area in pairs(areas.areas) do
|
||||
if areas:isAreaOwner(id, name) and
|
||||
areas:toString(id):find(param) then
|
||||
table.insert(matches, areas:toString(id))
|
||||
local matches = {}
|
||||
for id, area in pairs(areas.areas) do
|
||||
local str = areas:toString(id)
|
||||
if str:find(param) then
|
||||
table.insert(matches, str)
|
||||
end
|
||||
end
|
||||
if #matches > 1 then
|
||||
if #matches > 0 then
|
||||
return true, table.concat(matches, "\n")
|
||||
else
|
||||
return true, "No matches found."
|
||||
@ -238,12 +239,11 @@ minetest.register_chatcommand("change_owner", {
|
||||
description = "Change the owner of an area using it's ID",
|
||||
func = function(name, param)
|
||||
local id, newOwner = param:match("^(%d+)%s(%S+)$")
|
||||
|
||||
if not id then
|
||||
return false, "Invalid usage, see"
|
||||
.." /help change_owner."
|
||||
end
|
||||
|
||||
|
||||
if not areas:player_exists(newOwner) then
|
||||
return false, "The player \""..newOwner
|
||||
.."\" does not exist."
|
||||
@ -269,7 +269,6 @@ minetest.register_chatcommand("area_open", {
|
||||
description = "Toggle an area open (anyone can interact) or closed",
|
||||
func = function(name, param)
|
||||
local id = tonumber(param)
|
||||
|
||||
if not id then
|
||||
return false, "Invalid usage, see /help area_open."
|
||||
end
|
||||
@ -286,3 +285,29 @@ minetest.register_chatcommand("area_open", {
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("move_area", {
|
||||
params = "<ID>",
|
||||
description = "Move (or resize) an area to the current positions.",
|
||||
privs = areas.adminPrivs,
|
||||
func = function(name, param)
|
||||
local id = tonumber(param)
|
||||
if not id then
|
||||
return false, "Invalid usage, see /help move_area."
|
||||
end
|
||||
|
||||
local area = areas.areas[id]
|
||||
if not area then
|
||||
return false, "Area does not exist."
|
||||
end
|
||||
|
||||
local pos1, pos2 = areas:getPos(name)
|
||||
if not pos1 then
|
||||
return false, "You need to select an area first."
|
||||
end
|
||||
|
||||
area.pos1 = pos1
|
||||
area.pos2 = pos2
|
||||
areas:save()
|
||||
return true, "Area successfully moved."
|
||||
end,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user