Remove factions.version check if it is not necessary to allow opening for multiple factions to every version of playerfactions

This commit is contained in:
Supergoat666 2020-08-25 13:15:52 +02:00
parent f2ae0a6874
commit e2bd0e9e55
4 changed files with 23 additions and 38 deletions

View File

@ -113,7 +113,7 @@ Commands
* `/area_open <ID>` -- Toggle open/closed the specified area for everyone. * `/area_open <ID>` -- Toggle open/closed the specified area for everyone.
* `/area_faction_open <ID> [faction]` -- Toggle open/closed the specified * `/area_faction_open <ID> <faction>` -- Toggle open/closed the specified
area for members of the faction. Factions are created and managed by area for members of the faction. Factions are created and managed by
playerfactions mod. playerfactions mod.

View File

@ -93,10 +93,14 @@ function areas:canInteract(pos, name)
return true return true
elseif areas.factions_available and area.faction_open then elseif areas.factions_available and area.faction_open then
if (factions.version or 0) < 2 then if (factions.version or 0) < 2 then
local faction_name = factions.get_player_faction(area.owner) local faction_name = factions.get_player_faction(name)
if faction_name ~= nil and faction_name == factions.get_player_faction(name) then if faction_name then
for _, fname in ipairs(area.faction_open or {}) do
if faction_name == fname then
return true return true
end end
end
end
else else
for _, fname in ipairs(area.faction_open or {}) do for _, fname in ipairs(area.faction_open or {}) do
if factions.player_is_in_faction(fname, name) then if factions.player_is_in_faction(fname, name) then

View File

@ -301,21 +301,7 @@ if areas.factions_available then
return false, S("Area @1 does not exist" return false, S("Area @1 does not exist"
.." or is not owned by you.", id) .." or is not owned by you.", id)
end 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] local faction_name = params[2]
if not factions.get_owner(faction_name) then if not factions.get_owner(faction_name) then
return false, S("Faction doesn't exists") return false, S("Faction doesn't exists")

View File

@ -23,10 +23,6 @@ minetest.register_globalstep(function(dtime)
local faction_info local faction_info
if area.faction_open and areas.factions_available then if area.faction_open and areas.factions_available then
-- Gather and clean up disbanded factions -- Gather and clean up disbanded factions
if (factions.version or 0) < 2 then
faction_info = factions.get_player_faction(area.owner)
else
-- Verify that every displayed faction still exists
local changed = false local changed = false
for i, fac_name in ipairs(area.faction_open) do for i, fac_name in ipairs(area.faction_open) do
if not factions.get_owner(fac_name) then if not factions.get_owner(fac_name) then
@ -45,7 +41,6 @@ minetest.register_globalstep(function(dtime)
areas:save() areas:save()
end end
end end
end
table.insert(areaStrings, ("%s [%u] (%s%s%s)") table.insert(areaStrings, ("%s [%u] (%s%s%s)")
:format(area.name, id, area.owner, :format(area.name, id, area.owner,