From 6fa9702a6aae45ea06924abba9ce93bfbf363ead Mon Sep 17 00:00:00 2001 From: Zeg9 Date: Fri, 7 Jun 2013 19:59:05 +0200 Subject: [PATCH] Add compatibility to protector mods --- steel/depends.txt | 2 ++ steel/init.lua | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/steel/depends.txt b/steel/depends.txt index 915c6d2..5643dca 100644 --- a/steel/depends.txt +++ b/steel/depends.txt @@ -1,3 +1,5 @@ default streets? homedecor? +protector? +node_ownership? diff --git a/steel/init.lua b/steel/init.lua index e49bc60..9eb8c71 100644 --- a/steel/init.lua +++ b/steel/init.lua @@ -6,11 +6,46 @@ else steel_expect_infinite_stacks = false end +function steel_node_is_owned(pos, placer) + local ownername = false + if type(IsPlayerNodeOwner) == "function" then -- node_ownership mod + if HasOwner(pos, placer) then -- returns true if the node is owned + if not IsPlayerNodeOwner(pos, placer:get_player_name()) then + if type(getLastOwner) == "function" then -- ...is an old version + ownername = getLastOwner(pos) + elseif type(GetNodeOwnerName) == "function" then -- ...is a recent version + ownername = GetNodeOwnerName(pos) + else + ownername = "someone" + end + end + end + + elseif type(isprotect)=="function" then -- glomie's protection mod + if not isprotect(5, pos, placer) then + ownername = "someone" + end + elseif type(protector)=="table" and type(protector.can_dig)=="function" then -- Zeg9's protection mod + if not protector.can_dig(5, pos, placer) then + ownername = "someone" + end + end + + if ownername ~= false then + minetest.chat_send_player( placer:get_player_name(), ("Sorry, %s owns that spot."):format(ownername) ) + return true + else + return false + end +end + function steel_rotate_and_place(itemstack, placer, pointed_thing) local node = minetest.env:get_node(pointed_thing.under) if not minetest.registered_nodes[node.name] or not minetest.registered_nodes[node.name].on_rightclick then - + if steel_node_is_owned(pointed_thing.above, placer) then + return itemstack + end local above = pointed_thing.above local under = pointed_thing.under local pitch = placer:get_look_pitch()