added support for playerfactions new api (thanks louisroyer)

master
tenplus1 2020-08-20 18:52:33 +01:00
parent 0702fad2db
commit 6d09dd559c
3 changed files with 41 additions and 8 deletions

View File

@ -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

View File

@ -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"))

View File

@ -1 +1,3 @@
name = protector
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