From a46b1323d3e6d073828f783901470d3a78165673 Mon Sep 17 00:00:00 2001 From: shamoanjac Date: Fri, 19 Aug 2016 10:00:09 +0200 Subject: [PATCH 1/2] Fixed protection --- factions.lua | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/factions.lua b/factions.lua index 693e2f2..f932257 100644 --- a/factions.lua +++ b/factions.lua @@ -419,6 +419,14 @@ function factions.Faction.stop_attack(self, parcelpos) end end +function factions.Faction.parcel_is_attacked_by(self, parcelpos, faction) + if self.attacked_parcels[parcelpos] then + return self.attacked_parcels[parcelpos][faction.name] + else + return false + end +end + -------------------------- -- callbacks for events -- function factions.Faction.on_create(self) --! @brief called when the faction is added to the global faction list @@ -775,19 +783,13 @@ minetest.is_protected = function(pos, player) return not player_faction:has_permission(player, "claim") and player_faction.power > 0. and not parcel_faction.is_admin end -- no faction - if not parcel_faction then + if not parcel_faction or not player_faction then return default_is_protected(pos, player) else if parcel_faction.name == player_faction then return not parcel_faction:has_permission(player, "build") - elseif parcel_faction.attacked_parcels[parcelpos] then -- chunk is being attacked - if parcel_faction.attacked_parcels[parcelpos][player_faction] then -- attacked by the player's faction - return false - else - return true - end else - return true + return not parcel_faction:parcel_is_attacked_by(parcelpos, player_faction) end end end From 3e3a4c975503ea8795eaa9cd96a0fa575d2e2a88 Mon Sep 17 00:00:00 2001 From: shamoanjac Date: Fri, 19 Aug 2016 10:02:12 +0200 Subject: [PATCH 2/2] Fixed protection --- factions.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/factions.lua b/factions.lua index 693e2f2..6034486 100644 --- a/factions.lua +++ b/factions.lua @@ -419,6 +419,14 @@ function factions.Faction.stop_attack(self, parcelpos) end end +function factions.Faction.parcel_is_attacked_by(self, parcelpos, faction) + if self.attacked_parcels[parcelpos] then + return self.attacked_parcels[parcelpos][faction.name] + else + return false + end +end + -------------------------- -- callbacks for events -- function factions.Faction.on_create(self) --! @brief called when the faction is added to the global faction list @@ -777,17 +785,13 @@ minetest.is_protected = function(pos, player) -- no faction if not parcel_faction then return default_is_protected(pos, player) + elseif not player_faction then + return true else if parcel_faction.name == player_faction then return not parcel_faction:has_permission(player, "build") - elseif parcel_faction.attacked_parcels[parcelpos] then -- chunk is being attacked - if parcel_faction.attacked_parcels[parcelpos][player_faction] then -- attacked by the player's faction - return false - else - return true - end else - return true + return not parcel_faction:parcel_is_attacked_by(parcelpos, player_faction) end end end