From 88935ed573a7e4beb612b788b6bec7036ca0357d Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Thu, 17 Jan 2019 01:08:15 +0200 Subject: [PATCH] prevent towns from being created/expanded into areas protections --- towny/depends.txt | 2 ++ towny/mod.conf | 1 + towny/regions.lua | 27 +++++++++++++++++++-------- towny/town.lua | 12 +++++++++++- 4 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 towny/depends.txt diff --git a/towny/depends.txt b/towny/depends.txt new file mode 100644 index 0000000..c4c0ea8 --- /dev/null +++ b/towny/depends.txt @@ -0,0 +1,2 @@ +areas? +protector? diff --git a/towny/mod.conf b/towny/mod.conf index 33cb3cc..3221210 100644 --- a/towny/mod.conf +++ b/towny/mod.conf @@ -1,2 +1,3 @@ name = towny description = A township system for Minetest servers. +optional_depends = areas,protector diff --git a/towny/regions.lua b/towny/regions.lua index 38e39e4..13b97d3 100644 --- a/towny/regions.lua +++ b/towny/regions.lua @@ -1,3 +1,6 @@ +local modareas = minetest.get_modpath("areas") ~= nil +local protprev = minetest.settings:get_bool("towny_prevent_protector", true) + local tr = towny.regions.size local th = towny.regions.height local main_is_protected = minetest.is_protected @@ -14,6 +17,21 @@ local function region_equal(v1, v2) (math.floor(v1.z) == math.floor(v2.z)) end +-- Find any conflicts with protection mods +-- Do not allow placement of towns in any areas-protected regions, no matter if the user has +-- build permission there or not. +function towny.regions.protection_mod(p1,p2) + if not protprev then return false end + if modareas then + if #areas:getAreasIntersectingArea(p1, p2) > 0 then + return true + end + end + + -- Clear of any other protections + return false +end + -- Test to see if there's already a protected node in a region function towny.regions.already_protected(p1, p2, name) local found = false @@ -162,7 +180,7 @@ function towny.regions.align_new_claim_block(pos,name) elseif (pos.x <= p1.x and pos.x >= p2.x) and (pos.z <= p1.z and pos.z >= p2.z) then if pos.y > p1.y then new_pos = vector.add(p1, {x=0,y=th,z=0}) - else + elseif pos.y < p2.y then new_pos = vector.add(p1, {x=0,y=-th,z=0}) end -- Z @@ -230,10 +248,3 @@ function minetest.is_protected(pos, name) return main_is_protected(pos, name) end - ---[[if minetest.settings:get('towny_prevent_protector') == 'true' then - minetest.register_on_placenode(function (pos, newnode, placer, oldnode, itemstack, pointed_thing) - local town = towny.regions.get_town_at(pos) - if not town return end - end) -end]] diff --git a/towny/town.lua b/towny/town.lua index fed7454..855a29b 100644 --- a/towny/town.lua +++ b/towny/town.lua @@ -108,6 +108,11 @@ function towny.create_town(pos, player, name) -- New town information local p1 = vector.add(pos, {x=tr / 2,y=th - 1,z=tr / 2}) local p2 = vector.subtract(pos, {x=tr / 2,y=1,z=tr / 2}) + + if towny.regions.protection_mod(p1,p2) then + return err_msg(player, "This area is protected by another protection mod! Please ensure that this is not the case.") + end + local id = minetest.sha1(minetest.hash_node_position(pos)) local data = { name = name, @@ -174,12 +179,17 @@ function towny.extend_town(pos,player) return err_msg(player, "Something went wrong!") end + local p1,p2 = towny.regions.ensure_range(p1) + if towny.regions.protection_mod(p1,p2) then + return err_msg(player, "This area is protected by another protection mod! Please ensure that this is not the case.") + end + table.insert(towny.regions.memloaded[town].blocks, p1) minetest.chat_send_player(player, ("Successfully claimed this block! You have %d claim blocks left!"):format(towny.get_claims_available(town))) towny.mark_dirty(town, true) - local p1,p2 = towny.regions.ensure_range(p1) towny.regions.visualize_area(p1,p2) + return true end