From 91712209c907f2aae3ea9b701b27434934178b34 Mon Sep 17 00:00:00 2001 From: luk3yx Date: Wed, 21 Feb 2024 18:43:59 +1300 Subject: [PATCH 1/4] Add option to enable PvP by default --- chatcommands.lua | 10 +++++++--- hud.lua | 7 ++++++- interact.lua | 8 +++++--- internal.lua | 7 +++---- settings.lua | 1 + settingtypes.txt | 3 +++ 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/chatcommands.lua b/chatcommands.lua index cb07bbd..616c502 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -493,7 +493,7 @@ minetest.register_chatcommand("area_pvp", { S("Area @1 does not exist or is not owned by you.", id) end - local canPvP = areas.areas[id].canPvP + local canPvP = areas:canPvP(id) if not canPvP then local players = {} @@ -513,8 +513,12 @@ minetest.register_chatcommand("area_pvp", { end end - -- Save false as nil to avoid inflating the DB. - areas.areas[id].canPvP = not canPvP or nil + if areas.config.pvp_by_default == not canPvP then + -- Save the default value as nil to avoid inflating the DB. + areas.areas[id].canPvP = nil + else + areas.areas[id].canPvP = not canPvP + end areas:save() return true, S("PvP is @1 in area @2.", not canPvP and S("enabled") or S("disabled"), id) diff --git a/hud.lua b/hud.lua index 7047d3b..3f546d8 100644 --- a/hud.lua +++ b/hud.lua @@ -14,7 +14,12 @@ local function createAreaString(area, id) tinsert(parts, " [" .. S("Open") .. "]") end - if area.canPvP and not creative_mode then + if areas.config.pvp_by_default then + -- Compare with false as nil = default + if area.canPvP == false and not creative_mode then + tinsert(parts, " [" .. S("PvP disabled") .. "]") + end + elseif area.canPvP and not creative_mode then tinsert(parts, " [" .. S("PvP enabled") .. "]") end diff --git a/interact.lua b/interact.lua index 38af7f2..ed4ed99 100644 --- a/interact.lua +++ b/interact.lua @@ -38,14 +38,16 @@ minetest.register_on_protection_violation(function(pos, name) end) local function can_pvp_at(pos) + local default = areas.config.pvp_by_default for id in pairs(areas:getAreasAtPos(pos)) do -- This uses areas:canPvP instead of area.canPvP in case areas:canPvP -- is overridden - if areas:canPvP(id) then - return true + local value = areas:canPvP(id) + if value ~= default then + return value end end - return false + return default end minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch) diff --git a/internal.lua b/internal.lua index fad8f02..5e57156 100644 --- a/internal.lua +++ b/internal.lua @@ -167,11 +167,10 @@ end -- @returns true or false (enabled or disabled) function areas:canPvP(id) local area = self.areas[id] - if not area then - return true + if not area or area.canPvP == nil then + return areas.config.pvp_by_default end - -- canPvP is nil when false - return area.canPvP or false + return area.canPvP end -- Checks if a area between two points is entirely contained by another area. diff --git a/settings.lua b/settings.lua index e73e3be..01edc63 100644 --- a/settings.lua +++ b/settings.lua @@ -28,6 +28,7 @@ end -------------- setting("string", "filename", world_path.."/areas.dat") +setting("boolean", "pvp_by_default", false) -- Allow players with a privilege create their own areas -- within the maximum size and number. diff --git a/settingtypes.txt b/settingtypes.txt index 65eaf61..71fc827 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -3,6 +3,9 @@ # Static paths do not work well with settings #areas.filename (Configuration file path) string (world_path)/areas.dat +# When enabled, makes PvP opt-out rather than opt-in. +areas.pvp_by_default (PvP by default) bool false + # Allow players with a privilege create their own areas using /protect # within the specified size and amount limits. areas.self_protection (Self protection) bool false From 068a52829ded513db467aa217341d5a150f72e87 Mon Sep 17 00:00:00 2001 From: luk3yx Date: Tue, 5 Mar 2024 21:06:00 +1300 Subject: [PATCH 2/4] Simplify wording of setting --- settingtypes.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settingtypes.txt b/settingtypes.txt index 71fc827..cbf9b6b 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -3,7 +3,7 @@ # Static paths do not work well with settings #areas.filename (Configuration file path) string (world_path)/areas.dat -# When enabled, makes PvP opt-out rather than opt-in. +# Turn on PvP everywhere areas.pvp_by_default (PvP by default) bool false # Allow players with a privilege create their own areas using /protect From 5254e465349210f5556c475ebeae6c6e65387a9f Mon Sep 17 00:00:00 2001 From: "Maksym H." Date: Mon, 22 Apr 2024 16:26:41 +0400 Subject: [PATCH 3/4] Areas with undetermined PvP status are PvP free --- hud.lua | 14 ++++++++------ internal.lua | 4 +++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/hud.lua b/hud.lua index 3f546d8..d0e3fb0 100644 --- a/hud.lua +++ b/hud.lua @@ -14,13 +14,15 @@ local function createAreaString(area, id) tinsert(parts, " [" .. S("Open") .. "]") end - if areas.config.pvp_by_default then - -- Compare with false as nil = default - if area.canPvP == false and not creative_mode then - tinsert(parts, " [" .. S("PvP disabled") .. "]") + if not creative_mode then + if areas.config.pvp_by_default then + -- Compare with false as nil = default + if area.canPvP == nil or area.canPvP == false then + tinsert(parts, " [" .. S("PvP disabled") .. "]") + end + elseif area.canPvP then + tinsert(parts, " [" .. S("PvP enabled") .. "]") end - elseif area.canPvP and not creative_mode then - tinsert(parts, " [" .. S("PvP enabled") .. "]") end return tconcat(parts):trim() diff --git a/internal.lua b/internal.lua index 5e57156..82d8a82 100644 --- a/internal.lua +++ b/internal.lua @@ -167,8 +167,10 @@ end -- @returns true or false (enabled or disabled) function areas:canPvP(id) local area = self.areas[id] - if not area or area.canPvP == nil then + if not area then return areas.config.pvp_by_default + elseif area.canPvP == nil then + return false end return area.canPvP end From d7ebb459e3301229e87d8e086fe9359667fabdf6 Mon Sep 17 00:00:00 2001 From: "Maksym H." Date: Wed, 15 May 2024 04:16:53 +0200 Subject: [PATCH 4/4] Update translations --- locale/areas.ar.tr | 1 + locale/areas.bg.tr | 1 + locale/areas.cs.tr | 1 + locale/areas.da.tr | 1 + locale/areas.de.tr | 1 + locale/areas.el.tr | 1 + locale/areas.es.tr | 1 + locale/areas.et.tr | 1 + locale/areas.fi.tr | 1 + locale/areas.fr.tr | 1 + locale/areas.hu.tr | 1 + locale/areas.id.tr | 1 + locale/areas.it.tr | 1 + locale/areas.ja.tr | 1 + locale/areas.lt.tr | 1 + locale/areas.lv.tr | 1 + locale/areas.nb.tr | 1 + locale/areas.nl.tr | 1 + locale/areas.pl.tr | 1 + locale/areas.pt.tr | 1 + locale/areas.ro.tr | 1 + locale/areas.ru.tr | 1 + locale/areas.sk.tr | 1 + locale/areas.sv.tr | 1 + locale/areas.tr.tr | 1 + locale/areas.uk.tr | 1 + locale/areas.vi.tr | 1 + 27 files changed, 27 insertions(+) diff --git a/locale/areas.ar.tr b/locale/areas.ar.tr index ba6a9b0..bef9990 100644 --- a/locale/areas.ar.tr +++ b/locale/areas.ar.tr @@ -78,6 +78,7 @@ disabled=عاجز Areas:=المناطق: Open=يفتح PvP enabled=تمكين حماية الأصناف النباتية +PvP disabled=تم تعطيل حماية الأصناف النباتية ### interact.lua ### diff --git a/locale/areas.bg.tr b/locale/areas.bg.tr index 85a672f..8cef485 100644 --- a/locale/areas.bg.tr +++ b/locale/areas.bg.tr @@ -78,6 +78,7 @@ disabled=изключени Areas:=Области: Open=Отворете PvP enabled=Разрешен PvP +PvP disabled=PvP е изключен ### interact.lua ### diff --git a/locale/areas.cs.tr b/locale/areas.cs.tr index e99f861..ee51ae4 100644 --- a/locale/areas.cs.tr +++ b/locale/areas.cs.tr @@ -78,6 +78,7 @@ disabled=zakázané Areas:=Oblasti: Open=Otevřít PvP enabled=PvP povoleno +PvP disabled=PvP zakázán ### interact.lua ### diff --git a/locale/areas.da.tr b/locale/areas.da.tr index 5fd9ced..8c7db78 100644 --- a/locale/areas.da.tr +++ b/locale/areas.da.tr @@ -78,6 +78,7 @@ disabled=deaktiveret Areas:=Områder: Open=Åbn PvP enabled=PvP aktiveret +PvP disabled=PvP deaktiveret ### interact.lua ### diff --git a/locale/areas.de.tr b/locale/areas.de.tr index f52cf1d..8767282 100644 --- a/locale/areas.de.tr +++ b/locale/areas.de.tr @@ -78,6 +78,7 @@ disabled=Behinderte Areas:=Bereiche: Open=Offen PvP enabled=PvP aktiviert +PvP disabled=PvP deaktiviert ### interact.lua ### diff --git a/locale/areas.el.tr b/locale/areas.el.tr index b87fe09..3726825 100644 --- a/locale/areas.el.tr +++ b/locale/areas.el.tr @@ -78,6 +78,7 @@ disabled=disabled Areas:=Περιοχές: Open=Ανοίξτε το PvP enabled=Ενεργό PvP +PvP disabled=PvP απενεργοποιημένο ### interact.lua ### diff --git a/locale/areas.es.tr b/locale/areas.es.tr index 7a68c6f..46c840d 100644 --- a/locale/areas.es.tr +++ b/locale/areas.es.tr @@ -78,6 +78,7 @@ disabled=desactivado Areas:=Áreas: Open=Abierto PvP enabled=PvP habilitado +PvP disabled=PvP desactivado ### interact.lua ### diff --git a/locale/areas.et.tr b/locale/areas.et.tr index 0b02197..93a4742 100644 --- a/locale/areas.et.tr +++ b/locale/areas.et.tr @@ -78,6 +78,7 @@ disabled=puudega Areas:=Valdkonnad: Open=Avatud PvP enabled=PvP lubatud +PvP disabled=PvP keelatud ### interact.lua ### diff --git a/locale/areas.fi.tr b/locale/areas.fi.tr index fc6cf03..7a44285 100644 --- a/locale/areas.fi.tr +++ b/locale/areas.fi.tr @@ -78,6 +78,7 @@ disabled=disabled Areas:=Alueet: Open=Avaa PvP enabled=PvP käytössä +PvP disabled=PvP poistettu käytöstä ### interact.lua ### diff --git a/locale/areas.fr.tr b/locale/areas.fr.tr index d3e1273..3aae0d7 100644 --- a/locale/areas.fr.tr +++ b/locale/areas.fr.tr @@ -78,6 +78,7 @@ disabled=désactivé Areas:=Zones : Open=Ouvrir PvP enabled=JcJ activé +PvP disabled=PvP désactivé ### interact.lua ### diff --git a/locale/areas.hu.tr b/locale/areas.hu.tr index f8ebee2..35cad50 100644 --- a/locale/areas.hu.tr +++ b/locale/areas.hu.tr @@ -78,6 +78,7 @@ disabled=disabled Areas:=Területek: Open=Nyissa meg a címet. PvP enabled=PvP engedélyezve +PvP disabled=PvP letiltva ### interact.lua ### diff --git a/locale/areas.id.tr b/locale/areas.id.tr index 18121e4..318730a 100644 --- a/locale/areas.id.tr +++ b/locale/areas.id.tr @@ -78,6 +78,7 @@ disabled=dinonaktifkan Areas:=Area: Open=Terbuka PvP enabled=PvP diaktifkan +PvP disabled=PvP dinonaktifkan ### interact.lua ### diff --git a/locale/areas.it.tr b/locale/areas.it.tr index 58a9858..9927ffc 100644 --- a/locale/areas.it.tr +++ b/locale/areas.it.tr @@ -78,6 +78,7 @@ disabled=disabilitato Areas:=Aree: Open=Aperto PvP enabled=PvP abilitato +PvP disabled=PvP disattivato ### interact.lua ### diff --git a/locale/areas.ja.tr b/locale/areas.ja.tr index 8317734..8f047f5 100644 --- a/locale/areas.ja.tr +++ b/locale/areas.ja.tr @@ -78,6 +78,7 @@ disabled=使用禁止 Areas:=エリア Open=オープン PvP enabled=PvP対応 +PvP disabled=PvP無効 ### interact.lua ### diff --git a/locale/areas.lt.tr b/locale/areas.lt.tr index dc030c4..87ad8c1 100644 --- a/locale/areas.lt.tr +++ b/locale/areas.lt.tr @@ -78,6 +78,7 @@ disabled=neįgalieji Areas:=Sritys: Open=Atviras PvP enabled=Įjungtas PvP +PvP disabled=PvP išjungtas ### interact.lua ### diff --git a/locale/areas.lv.tr b/locale/areas.lv.tr index 164cea1..70f5440 100644 --- a/locale/areas.lv.tr +++ b/locale/areas.lv.tr @@ -78,6 +78,7 @@ disabled=invalīdiem Areas:=Jomas: Open=Atvērt PvP enabled=Ieslēgts PvP +PvP disabled=PvP atspējots ### interact.lua ### diff --git a/locale/areas.nb.tr b/locale/areas.nb.tr index 6d20ee9..af7490b 100644 --- a/locale/areas.nb.tr +++ b/locale/areas.nb.tr @@ -78,6 +78,7 @@ disabled=deaktivert Areas:=Områder: Open=Åpent PvP enabled=PvP aktivert +PvP disabled=PvP deaktivert ### interact.lua ### diff --git a/locale/areas.nl.tr b/locale/areas.nl.tr index 8478a4e..be5b7fe 100644 --- a/locale/areas.nl.tr +++ b/locale/areas.nl.tr @@ -78,6 +78,7 @@ disabled=uitgeschakeld Areas:=Gebieden: Open=Open PvP enabled=PvP ingeschakeld +PvP disabled=PvP uitgeschakeld ### interact.lua ### diff --git a/locale/areas.pl.tr b/locale/areas.pl.tr index 4b68287..fd28f00 100644 --- a/locale/areas.pl.tr +++ b/locale/areas.pl.tr @@ -78,6 +78,7 @@ disabled=wyłączony Areas:=Obszary: Open=Otwórz PvP enabled=Włączony PvP +PvP disabled=PvP wyłączone ### interact.lua ### diff --git a/locale/areas.pt.tr b/locale/areas.pt.tr index cecab1b..651e458 100644 --- a/locale/areas.pt.tr +++ b/locale/areas.pt.tr @@ -78,6 +78,7 @@ disabled=deficientes Areas:=Áreas: Open=Aberto PvP enabled=PvP activado +PvP disabled=PvP desativado ### interact.lua ### diff --git a/locale/areas.ro.tr b/locale/areas.ro.tr index 5fcb6be..c00d174 100644 --- a/locale/areas.ro.tr +++ b/locale/areas.ro.tr @@ -78,6 +78,7 @@ disabled=dezactivat Areas:=Domenii: Open=Deschideți PvP enabled=PvP activat +PvP disabled=PvP dezactivat ### interact.lua ### diff --git a/locale/areas.ru.tr b/locale/areas.ru.tr index 0c389f5..3abb3e8 100644 --- a/locale/areas.ru.tr +++ b/locale/areas.ru.tr @@ -78,6 +78,7 @@ disabled=выключен Areas:=Зоны: Open=Открыта PvP enabled=PvP включен +PvP disabled=PvP отключен ### interact.lua ### diff --git a/locale/areas.sk.tr b/locale/areas.sk.tr index 42e017f..049f6da 100644 --- a/locale/areas.sk.tr +++ b/locale/areas.sk.tr @@ -78,6 +78,7 @@ disabled=vypnuté Areas:=Oblasti: Open=Otvorte stránku PvP enabled=PvP povolený +PvP disabled=PvP vypnuté ### interact.lua ### diff --git a/locale/areas.sv.tr b/locale/areas.sv.tr index 949ae6d..87524fe 100644 --- a/locale/areas.sv.tr +++ b/locale/areas.sv.tr @@ -78,6 +78,7 @@ disabled=inaktiverad Areas:=Områden: Open=Öppna PvP enabled=PvP aktiverat +PvP disabled=PvP inaktiverat ### interact.lua ### diff --git a/locale/areas.tr.tr b/locale/areas.tr.tr index fd9e410..5e2ee8c 100644 --- a/locale/areas.tr.tr +++ b/locale/areas.tr.tr @@ -78,6 +78,7 @@ disabled=engelli Areas:=Alanlar: Open=Açık PvP enabled=PvP etkin +PvP disabled=PvP devre dışı ### interact.lua ### diff --git a/locale/areas.uk.tr b/locale/areas.uk.tr index d604e84..fe3eca5 100644 --- a/locale/areas.uk.tr +++ b/locale/areas.uk.tr @@ -78,6 +78,7 @@ disabled=вимкнено Areas:=Зони: Open=Відкрита PvP enabled=PvP увімкнено +PvP disabled=PvP розблоковано ### interact.lua ### diff --git a/locale/areas.vi.tr b/locale/areas.vi.tr index f50aec2..670b4fd 100644 --- a/locale/areas.vi.tr +++ b/locale/areas.vi.tr @@ -78,6 +78,7 @@ disabled=tắt Areas:=Khu vực: Open=Mở PvP enabled=PvP trên +PvP disabled=PvP bị vô hiệu hóa ### interact.lua ###