prevent towns from being created/expanded into areas protections
This commit is contained in:
parent
d467d8cd61
commit
88935ed573
2
towny/depends.txt
Normal file
2
towny/depends.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
areas?
|
||||||
|
protector?
|
@ -1,2 +1,3 @@
|
|||||||
name = towny
|
name = towny
|
||||||
description = A township system for Minetest servers.
|
description = A township system for Minetest servers.
|
||||||
|
optional_depends = areas,protector
|
||||||
|
@ -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 tr = towny.regions.size
|
||||||
local th = towny.regions.height
|
local th = towny.regions.height
|
||||||
local main_is_protected = minetest.is_protected
|
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))
|
(math.floor(v1.z) == math.floor(v2.z))
|
||||||
end
|
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
|
-- Test to see if there's already a protected node in a region
|
||||||
function towny.regions.already_protected(p1, p2, name)
|
function towny.regions.already_protected(p1, p2, name)
|
||||||
local found = false
|
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
|
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
|
if pos.y > p1.y then
|
||||||
new_pos = vector.add(p1, {x=0,y=th,z=0})
|
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})
|
new_pos = vector.add(p1, {x=0,y=-th,z=0})
|
||||||
end
|
end
|
||||||
-- Z
|
-- Z
|
||||||
@ -230,10 +248,3 @@ function minetest.is_protected(pos, name)
|
|||||||
|
|
||||||
return main_is_protected(pos, name)
|
return main_is_protected(pos, name)
|
||||||
end
|
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]]
|
|
||||||
|
@ -108,6 +108,11 @@ function towny.create_town(pos, player, name)
|
|||||||
-- New town information
|
-- New town information
|
||||||
local p1 = vector.add(pos, {x=tr / 2,y=th - 1,z=tr / 2})
|
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})
|
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 id = minetest.sha1(minetest.hash_node_position(pos))
|
||||||
local data = {
|
local data = {
|
||||||
name = name,
|
name = name,
|
||||||
@ -174,12 +179,17 @@ function towny.extend_town(pos,player)
|
|||||||
return err_msg(player, "Something went wrong!")
|
return err_msg(player, "Something went wrong!")
|
||||||
end
|
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)
|
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)))
|
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)
|
towny.mark_dirty(town, true)
|
||||||
|
|
||||||
local p1,p2 = towny.regions.ensure_range(p1)
|
|
||||||
towny.regions.visualize_area(p1,p2)
|
towny.regions.visualize_area(p1,p2)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user