diff options
author | ShadowNinja <noreply@gmail.com> | 2013-09-02 19:16:14 -0400 |
---|---|---|
committer | ShadowNinja <noreply@gmail.com> | 2013-09-02 19:16:14 -0400 |
commit | 4ae050a3ae13d5fc7a01b72fe2576508916e5145 (patch) | |
tree | fe9e6bff4c88854e384fb1c26512aa8867d12f41 /interact.lua |
Initial commit
Diffstat (limited to 'interact.lua')
-rw-r--r-- | interact.lua | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/interact.lua b/interact.lua new file mode 100644 index 0000000..f6a7cb1 --- /dev/null +++ b/interact.lua @@ -0,0 +1,39 @@ + +-- Gives a player a warning message about a area being protected +local function printWarning(name, pos) + local owners = areas:getNodeOwners(pos) + minetest.chat_send_player(name, ("%s is protected by %s.") + :format(minetest.pos_to_string(pos), table.concat(owners, ", "))) +end + +if minetest.can_interact then + old_can_interact = minetest.can_interact + function minetest.can_interact(pos, name) + if not areas:canInteract(pos, name) then + printWarning(name, pos) + return false + end + return old_can_interact(pos, name) + end +else + local old_node_place = minetest.item_place_node + function minetest.item_place_node(itemstack, placer, pointed_thing) + -- XXX: buildable_to nodes can mess this up + local pos = pointed_thing.above + if not areas:canInteract(pos, placer:get_player_name()) then + printWarning(placer:get_player_name(), pos) + return itemstack -- Abort place. + end + return old_node_place(itemstack, placer, pointed_thing) + end + + local old_node_dig = minetest.node_dig + function minetest.node_dig(pos, node, digger) + if not areas:canInteract(pos, digger:get_player_name()) then + printWarning(digger:get_player_name(), pos) + return -- Abort dig. + end + return old_node_dig(pos, node, digger) + end +end + |