Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ function areas:canInteract(pos, name)
end
local owned = false
for _, area in pairs(areas_list) do
-- Player owns the area or area is open
if area.owner == name or area.open then
-- Player owns the area, area is open, or player is a co-owner
if area.owner == name
or area.open
or (area.co_owners and area.co_owners[name]) then
return true
elseif areas.factions_available and area.faction_open then
if (factions.version or 0) < 2 then
Expand Down
85 changes: 85 additions & 0 deletions chatcommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ minetest.register_chatcommand("change_owner", {
.." or is not owned by you.", id)
end
areas.areas[id].owner = newOwner
areas:removeCoOwner(id, newOwner)
areas:save()
minetest.chat_send_player(newOwner,
S("@1 has given you control over the area \"@2\" (ID @3).",
Expand All @@ -294,6 +295,90 @@ minetest.register_chatcommand("change_owner", {
end
})

minetest.register_chatcommand("add_co_owner", {
params = S("<ID>").." "..S("<CoOwner>"),
description = S("Add a co-owner to an area"),
func = function(name, param)
local id, coOwner = param:match("^(%d+)%s(%S+)$")
if not id then
return false, S("Invalid usage, see"
.." /help @1.", "add_co_owner")
end

if not areas:player_exists(coOwner) then
return false, S("The player \"@1\" does not exist.", coOwner)
end

id = tonumber(id)
if not areas:isAreaOwner(id, name) then
return false, S("Area @1 does not exist"
.." or is not owned by you.", id)
end
areas:addCoOwner(id, coOwner)
areas:save()
minetest.chat_send_player(coOwner,
S("@1 has added you as a co-owner of the area \"@2\" (ID @3).",
name, areas.areas[id].name, id))
return true, S("Co-owner added.")
end
})

minetest.register_chatcommand("remove_co_owner", {
params = S("<ID>").." "..S("<CoOwner>"),
description = S("Remove a co-owner from an area"),
func = function(name, param)
local id, coOwner = param:match("^(%d+)%s(%S+)$")
if not id then
return false, S("Invalid usage, see"
.." /help @1.", "remove_co_owner")
end

if not areas:player_exists(coOwner) then
return false, S("The player \"@1\" does not exist.", coOwner)
end

id = tonumber(id)
if not areas:isAreaOwner(id, name) then
return false, S("Area @1 does not exist"
.." or is not owned by you.", id)
end
areas:removeCoOwner(id, coOwner)
areas:save()
minetest.chat_send_player(coOwner,
S("@1 has removed you from the list of co-owners of the area \"@2\" (ID @3).",
name, areas.areas[id].name, id))
return true, S("Co-owner removed.")
end
})

minetest.register_chatcommand("list_co_owners", {
params = S("<ID>"),
description = S("List co-owners of an area"),
func = function(name, param)
local id = tonumber(param)
if not id then
return false, S("Invalid usage, see /help @1.", "area_open")
end

local entry = areas.areas[id]
if not entry then
return false, S("The area @1 does not exist.", id)
end

local coOwners = {}
for coOwner in pairs(areas:listCoOwners(id)) do
coOwners[#coOwners+1] = coOwner
end

if #coOwners == 0 then
return true, S("The area \"@1\" (ID @2) have no co-owners.", entry.name, id)
end

return true, S("Co-owners of area \"@1\" (ID @2): @3",
entry.name, id, table.concat(coOwners, ", "))
end
})


minetest.register_chatcommand("area_open", {
params = S("<ID>"),
Expand Down
10 changes: 8 additions & 2 deletions hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ minetest.register_globalstep(function(dtime)
end
end

table.insert(areaStrings, ("%s [%u] (%s%s%s)")
local coOwnersCount = 0
for _ in pairs(areas:listCoOwners(id)) do
coOwnersCount = coOwnersCount + 1
end

table.insert(areaStrings, ("%s [%u] (%s%s%s)%s")
:format(area.name, id, area.owner,
area.open and S(":open") or "",
faction_info and ": "..faction_info or ""))
faction_info and ": "..faction_info or "",
coOwnersCount ~= 0 and " +" .. coOwnersCount or ""))
end

for i, area in pairs(areas:getExternalHudEntries(pos)) do
Expand Down
24 changes: 24 additions & 0 deletions internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,30 @@ function areas:getChildren(id)
return children
end

-- Add a co-owner to an area
function areas:addCoOwner(id, name)
local entry = self.areas[id]
entry.co_owners = entry.co_owners or {}
entry.co_owners[name] = true
end

-- Remove a co-owner from an area
function areas:removeCoOwner(id, name)
local entry = self.areas[id]
if entry.co_owners then
entry.co_owners[name] = nil
if next(entry.co_owners) == nil then
entry.co_owners = nil
end
end
end

-- Return the list of co-owners
function areas:listCoOwners(id)
local entry = self.areas[id]
return entry.co_owners and table.copy(entry.co_owners) or {}
end

-- checks all possible restrictions registered with
-- areas:registerProtectionCondition
-- builtin callbacks below
Expand Down