Check for area protection in buckets.

This commit is contained in:
Novatux 2013-11-23 21:54:19 +01:00
parent 2d9f34cf29
commit 064b4510dd

View file

@ -18,6 +18,18 @@ minetest.register_craft({
bucket = {} bucket = {}
bucket.liquids = {} bucket.liquids = {}
local function check_protection(pos, name, text)
if minetest.is_protected(pos, name) then
minetest.log("action", name
.. " tried to " .. text
.. " at protected position "
.. minetest.pos_to_string(pos))
minetest.record_protection_violation(pos, name)
return true
end
return false
end
-- Register a new liquid -- Register a new liquid
-- source = name of the source node -- source = name of the source node
-- flowing = name of the flowing node -- flowing = name of the flowing node
@ -77,9 +89,19 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name
if not fullness then fullness = LIQUID_MAX end if not fullness then fullness = LIQUID_MAX end
if minetest.registered_nodes[node.name].buildable_to then if minetest.registered_nodes[node.name].buildable_to then
if check_protection(pointed_thing.under,
user:get_player_name(), "place "..itemstack:get_name()) then
return
end
-- buildable; replace the node -- buildable; replace the node
place_liquid(pointed_thing.under, node, source, flowing, fullness) place_liquid(pointed_thing.under, node, source, flowing, fullness)
else else
if check_protection(pointed_thing.above,
user:get_player_name(), "place "..itemstack:get_name()) then
return
end
-- not buildable to; place the liquid above -- not buildable to; place the liquid above
-- check if the node above can be replaced -- check if the node above can be replaced
local node = minetest.get_node(pointed_thing.above) local node = minetest.get_node(pointed_thing.above)
@ -112,6 +134,11 @@ minetest.register_craftitem("bucket:bucket_empty", {
if liquiddef ~= nil and liquiddef.itemname ~= nil and (node.name == liquiddef.source or if liquiddef ~= nil and liquiddef.itemname ~= nil and (node.name == liquiddef.source or
(node.name == liquiddef.flowing and minetest.setting_getbool("liquid_finite"))) then (node.name == liquiddef.flowing and minetest.setting_getbool("liquid_finite"))) then
if check_protection(pointed_thing.under,
user:get_player_name(), "take ".. node.name) then
return
end
minetest.add_node(pointed_thing.under, {name="air"}) minetest.add_node(pointed_thing.under, {name="air"})
if node.name == liquiddef.source then node.param2 = LIQUID_MAX end if node.name == liquiddef.source then node.param2 = LIQUID_MAX end