forked from nalc/areas
Actually fix buildable_to nodes and update for protection support pull
This commit is contained in:
parent
b1a4f878ef
commit
e86c760c78
41
interact.lua
41
interact.lua
@ -1,42 +1,51 @@
|
|||||||
|
|
||||||
-- Gives a player a warning message about a area being protected
|
-- Gives a player a warning message about a area being protected
|
||||||
local function printWarning(name, pos)
|
local function printWarning(pos, name)
|
||||||
local owners = areas:getNodeOwners(pos)
|
local owners = areas:getNodeOwners(pos)
|
||||||
minetest.chat_send_player(name, ("%s is protected by %s.")
|
minetest.chat_send_player(name, ("%s is protected by %s.")
|
||||||
:format(minetest.pos_to_string(pos), table.concat(owners, ", ")))
|
:format(minetest.pos_to_string(pos), table.concat(owners, ", ")))
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.can_interact then
|
if minetest.is_protected then
|
||||||
old_can_interact = minetest.can_interact
|
old_is_protected = minetest.is_protected
|
||||||
function minetest.can_interact(pos, name)
|
function minetest.is_protected(pos, name)
|
||||||
if not areas:canInteract(pos, name) then
|
if not areas:canInteract(pos, name) then
|
||||||
return false
|
return true
|
||||||
end
|
end
|
||||||
return old_can_interact(pos, name)
|
return old_is_protected(pos, name)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
local old_node_place = minetest.item_place_node
|
minetest.register_on_protection_violation(function(pos, name)
|
||||||
function minetest.item_place_node(itemstack, placer, pointed_thing)
|
if not areas:canInteract(pos, name) then
|
||||||
|
printWarning(pos, name)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
else
|
||||||
|
local old_node_place = minetest.item_place_node
|
||||||
|
function minetest.item_place_node(itemstack, placer, pointed_thing)
|
||||||
local pos = pointed_thing.above
|
local pos = pointed_thing.above
|
||||||
local ndef = minetest.registered_nodes[pointed_thing.under]
|
local under_node = minetest.get_node(pointed_thing.under)
|
||||||
if ndef and ndef.buildable_to then
|
local under_def = minetest.registered_nodes[under_node.name]
|
||||||
|
|
||||||
|
if under_def and under_def.buildable_to then
|
||||||
pos = pointed_thing.under
|
pos = pointed_thing.under
|
||||||
end
|
end
|
||||||
|
|
||||||
if not areas:canInteract(pos, placer:get_player_name()) then
|
if not areas:canInteract(pos, placer:get_player_name()) then
|
||||||
printWarning(placer:get_player_name(), pos)
|
printWarning(pos, placer:get_player_name())
|
||||||
return itemstack -- Abort place.
|
return itemstack -- Abort place.
|
||||||
end
|
end
|
||||||
return old_node_place(itemstack, placer, pointed_thing)
|
return old_node_place(itemstack, placer, pointed_thing)
|
||||||
end
|
end
|
||||||
|
|
||||||
local old_node_dig = minetest.node_dig
|
local old_node_dig = minetest.node_dig
|
||||||
function minetest.node_dig(pos, node, digger)
|
function minetest.node_dig(pos, node, digger)
|
||||||
if not areas:canInteract(pos, digger:get_player_name()) then
|
if not areas:canInteract(pos, digger:get_player_name()) then
|
||||||
printWarning(digger:get_player_name(), pos)
|
printWarning(pos, digger:get_player_name())
|
||||||
return -- Abort dig.
|
return -- Abort dig.
|
||||||
end
|
end
|
||||||
return old_node_dig(pos, node, digger)
|
return old_node_dig(pos, node, digger)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user