diff --git a/README.md b/README.md index 7ec814a..e353550 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ Change log: - 3.0 - Added PlayerFactions support, 'protector_hud_interval' setting and listing in advanced settings for mod values. - 3.1 - Ability to hide protection blocks using /protector_hide and /protector_show , italian local added (thanks Hamlet) - 3.2 - Defaults to Minetest translation if found, otherwise intllib fallback if loaded, locale files updated for both. Added 'protector_msg' setting for player text. +- 3.3 - Added support for playerfactions new api (thanks louisroyer) Lucky Blocks: 10 diff --git a/init.lua b/init.lua index 17bc416..3cb1ca3 100644 --- a/init.lua +++ b/init.lua @@ -64,12 +64,27 @@ end local is_member = function (meta, name) if factions_available - and meta:get_int("faction_members") == 1 - and factions.get_player_faction(name) ~= nil - and factions.get_player_faction(meta:get_string("owner")) == - factions.get_player_faction(name) then + and meta:get_int("faction_members") == 1 then - return true + if factions.version == nil then + + -- backward compatibility + if factions.get_player_faction(name) ~= nil + and factions.get_player_faction(meta:get_string("owner")) == + factions.get_player_faction(name) then + return true + end + else + -- is member if player and owner share at least one faction + local owner_factions = factions.get_player_factions(name) + + for _, f in ipairs(owner_factions) do + + if factions.player_is_in_faction(f, owner) then + return true + end + end + end end for _, n in pairs(get_member_list(meta)) do @@ -142,9 +157,24 @@ local protector_formspec = function(meta) local members = get_member_list(meta) local npp = protector_max_share_count -- max users added to protector list local i = 0 + local checkbox_faction = false - if factions_available - and factions.get_player_faction(meta:get_string("owner")) then + -- Display the checkbox only if the owner is member of at least 1 faction + if factions_available then + + if factions.version == nil then + + -- backward compatibility + if factions.get_player_faction(meta:get_string("owner")) then + checkbox_faction = true + end + else + if next(factions.get_player_faction(meta:get_string("owner"))) then + checkbox_faction = true + end + end + end + if checkbox_faction then formspec = formspec .. "checkbox[0,5;faction_members;" .. F(S("Allow faction access")) diff --git a/mod.conf b/mod.conf index 8eb0aa8..774f1a1 100644 --- a/mod.conf +++ b/mod.conf @@ -1 +1,3 @@ -name = protector \ No newline at end of file +name = protector +description = Lets players craft special blocks to protect their builds or disable PVP in areas. +optional_depends = default, intllib, lucky_block, mesecons_mvps, playerfactions