diff --git a/README.md b/README.md index 5a88623..bcc77ca 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ Commands * `/area_open ` -- Toggle open/closed the specified area for everyone. - * `/area_faction_open [faction]` -- Toggle open/closed the specified + * `/area_faction_open ` -- Toggle open/closed the specified area for members of the faction. Factions are created and managed by playerfactions mod. diff --git a/api.lua b/api.lua index ffd8be1..e6fe90e 100644 --- a/api.lua +++ b/api.lua @@ -93,9 +93,13 @@ function areas:canInteract(pos, name) return true elseif areas.factions_available and area.faction_open then if (factions.version or 0) < 2 then - local faction_name = factions.get_player_faction(area.owner) - if faction_name ~= nil and faction_name == factions.get_player_faction(name) then - return true + local faction_name = factions.get_player_faction(name) + if faction_name then + for _, fname in ipairs(area.faction_open or {}) do + if faction_name == fname then + return true + end + end end else for _, fname in ipairs(area.faction_open or {}) do diff --git a/chatcommands.lua b/chatcommands.lua index 6589152..1ff0241 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -301,21 +301,7 @@ if areas.factions_available then return false, S("Area @1 does not exist" .." or is not owned by you.", id) end - if (factions.version or 0) < 2 or (factions.mode_unique_faction and not params[2]) then - -- Single faction mode - local open - if (factions.version or 0) < 2 then - open = not areas.areas[id].faction_open and {factions.get_player_faction(name)} - else - open = not areas.areas[id].faction_open and factions.get_player_factions(name) - end - -- Save false as nil to avoid inflating the DB. - areas.areas[id].faction_open = open or nil - areas:save() - return true, open and S("Area opened for faction members.") - or S("Area closed for faction members.") - end - -- Multiple factions support + local faction_name = params[2] if not factions.get_owner(faction_name) then return false, S("Faction doesn't exists") diff --git a/hud.lua b/hud.lua index 0bfd1ca..ef0e182 100644 --- a/hud.lua +++ b/hud.lua @@ -23,27 +23,22 @@ minetest.register_globalstep(function(dtime) local faction_info if area.faction_open and areas.factions_available then -- Gather and clean up disbanded factions - if (factions.version or 0) < 2 then - faction_info = factions.get_player_faction(area.owner) + local changed = false + for i, fac_name in ipairs(area.faction_open) do + if not factions.get_owner(fac_name) then + table.remove(area.faction_open, i) + changed = true + end + end + if #area.faction_open == 0 then + -- Prevent DB clutter, remove value + area.faction_open = nil else - -- Verify that every displayed faction still exists - local changed = false - for i, fac_name in ipairs(area.faction_open) do - if not factions.get_owner(fac_name) then - table.remove(area.faction_open, i) - changed = true - end - end - if #area.faction_open == 0 then - -- Prevent DB clutter, remove value - area.faction_open = nil - else - faction_info = table.concat(area.faction_open, ", ") - end + faction_info = table.concat(area.faction_open, ", ") + end - if changed then - areas:save() - end + if changed then + areas:save() end end