diff --git a/chatcommands.lua b/chatcommands.lua index fc3ae6d..d7485ab 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -304,7 +304,7 @@ if areas.factions_available then .." or is not owned by you.", id) end if factions.version == nil or factions.version < 2 or factions.mode_unique_faction then - local open = not areas.areas[id].faction_open and factions.get_player_faction(name) + local open = not areas.areas[id].faction_open and {factions.get_player_faction(name)} -- Save false as nil to avoid inflating the DB. areas.areas[id].faction_open = open or nil areas:save() @@ -322,8 +322,8 @@ if areas.factions_available then local removed = false for i, fac_name in ipairs(fnames) do if faction_name == fac_name then - removed = true table.remove(fnames,i) + removed = true end end if not removed then @@ -332,7 +332,7 @@ if areas.factions_available then if #fnames == 0 then fnames = nil end - -- Save false as nil to avoid inflating the DB. + -- Save {} as nil to avoid inflating the DB. areas.areas[id].faction_open = fnames areas:save() return true, fnames and S("Area is open for members of: @1",table.concat(fnames,", ")) diff --git a/hud.lua b/hud.lua index c2274c8..39b8837 100644 --- a/hud.lua +++ b/hud.lua @@ -25,17 +25,23 @@ minetest.register_globalstep(function(dtime) if factions.version == nil or factions.version < 2 then faction_info = factions.get_player_faction(area.owner) else + -- Verify that every displayed faction still exists + local faction_open_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) + faction_open_changed = true end end if #area.faction_open == 0 then area.faction_open = nil faction_info = nil + faction_open_changed = true else faction_info = table.concat(area.faction_open, ", ") end + -- Save areas if a faction was disband + if faction_open_changed then areas:save() end end end