From 1011901938ea0b256ab5048392d56d935d152534 Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Tue, 16 Oct 2018 01:13:06 +0200 Subject: [PATCH] fix crate protection (#25) * fix crate protection all crates check area protection (minetest.is_protected) protected crates check area and owner (even if not in protected area) * separate check and action * whitespace stuff * another missing whitespace * add suggestion from T4im --- nodes/node_crate.lua | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/nodes/node_crate.lua b/nodes/node_crate.lua index ae3bffa..6484ef5 100644 --- a/nodes/node_crate.lua +++ b/nodes/node_crate.lua @@ -77,6 +77,12 @@ local store_digtron = function(pos, clicker, loaded_node_name, protected) local meta = minetest.get_meta(pos) meta:set_string("crated_layout", layout_string) + + if protected then + -- only set owner if protected + meta:set_string("owner", clicker:get_player_name() or "") + end + meta:set_string("title", S("Crated Digtron")) meta:set_string("infotext", S("Crated Digtron") .. "\n" .. protection_suffix) end @@ -98,6 +104,10 @@ minetest.register_node("digtron:empty_crate", { }, paramtype = "light", + can_dig = function(pos, player) + return player and not minetest.is_protected(pos, player:get_player_name()) + end, + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) store_digtron(pos, clicker, "digtron:loaded_crate") end @@ -130,7 +140,7 @@ minetest.register_node("digtron:empty_locked_crate", { meta:set_string("infotext", S("Digtron Crate") .. "\n" .. S("Owned by @1", placer:get_player_name() or "")) end, can_dig = function(pos,player) - return player_permitted(pos,player) + return player and not minetest.is_protected(pos, player:get_player_name()) and player_permitted(pos, player) end, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) if player_permitted(pos,clicker) then @@ -295,9 +305,11 @@ minetest.register_node("digtron:loaded_crate", { on_receive_fields = function(pos, formname, fields, sender) return loaded_on_recieve(pos, fields, sender) end, - + on_dig = function(pos, node, player) - return loaded_on_dig(pos, player, "digtron:loaded_crate") + if player and not minetest.is_protected(pos, player:get_player_name()) then + loaded_on_dig(pos, player, "digtron:loaded_crate") + end end, after_place_node = function(pos, placer, itemstack, pointed_thing) @@ -321,7 +333,7 @@ minetest.register_node("digtron:loaded_locked_crate", { end, on_dig = function(pos, node, player) - if player_permitted(pos,player) then + if player and not minetest.is_protected(pos, player:get_player_name()) and player_permitted(pos,player) then return loaded_on_dig(pos, player, "digtron:loaded_locked_crate") else return false @@ -352,4 +364,4 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) loaded_on_recieve(pos, fields, player, true) return true end -end) \ No newline at end of file +end)