From a6122f03d91cb63b120902d2fba3aab6f0f38021 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Thu, 30 Jan 2014 14:09:46 -0500 Subject: [PATCH] Remove old ownership code and use Minetest's built-in ownership code instead Some minor code rewrites here and there to accommodate this changeover. --- homedecor/doors_and_gates.lua | 73 ++++++++++++++++++++--------------- homedecor/init.lua | 2 - homedecor/lighting.lua | 13 +++---- homedecor/ownership.lua | 48 ----------------------- signs_lib/init.lua | 50 ++++++++++++++++++------ signs_lib/ownership.lua | 48 ----------------------- 6 files changed, 86 insertions(+), 148 deletions(-) delete mode 100644 homedecor/ownership.lua delete mode 100644 signs_lib/ownership.lua diff --git a/homedecor/doors_and_gates.lua b/homedecor/doors_and_gates.lua index ea5775ac..df356b1c 100644 --- a/homedecor/doors_and_gates.lua +++ b/homedecor/doors_and_gates.lua @@ -424,14 +424,19 @@ function homedecor.place_door(itemstack, placer, pointed_thing, name, forceright local pointed = pointed_thing.under local pnode = minetest.get_node(pointed) local pname = pnode.name + local rnodedef = minetest.registered_nodes[pname] - if not minetest.registered_nodes[pname] - or not minetest.registered_nodes[pname].on_rightclick then + if rnodedef then + + if rnodedef.on_rightclick then + rnodedef.on_rightclick(pointed_thing.under, pnode, placer, itemstack) + return + end local pos1 = nil local pos2 = nil - if minetest.registered_nodes[pname]["buildable_to"] then + if rnodedef["buildable_to"] then pos1 = pointed pos2 = {x=pointed.x, y=pointed.y+1, z=pointed.z} else @@ -442,39 +447,45 @@ function homedecor.place_door(itemstack, placer, pointed_thing, name, forceright local node_bottom = minetest.get_node(pos1) local node_top = minetest.get_node(pos2) - if not homedecor.node_is_owned(pos1, placer) - and not homedecor.node_is_owned(pos2, placer) then + if minetest.is_protected(pos1, placer:get_player_name()) then + minetest.record_protection_violation(pos1, + placer:get_player_name()) + return + end - if not get_nodedef_field(node_bottom.name, "buildable_to") - or not get_nodedef_field(node_top.name, "buildable_to") then - minetest.chat_send_player( placer:get_player_name(), S('Not enough space above that spot to place a door!') ) - else - local fdir = minetest.dir_to_facedir(placer:get_look_dir()) - local p_tests = { - {x=pos1.x-1, y=pos1.y, z=pos1.z}, - {x=pos1.x, y=pos1.y, z=pos1.z+1}, - {x=pos1.x+1, y=pos1.y, z=pos1.z}, - {x=pos1.x, y=pos1.y, z=pos1.z-1}, - } - print("fdir="..fdir) - local testnode = minetest.get_node(p_tests[fdir+1]) - local side = "left" + if minetest.is_protected(pos2, placer:get_player_name()) then + minetest.record_protection_violation(pos2, + placer:get_player_name()) + return + end - if string.find(testnode.name, "homedecor:door_"..name.."_bottom_left") or forceright then - side = "right" - end + if not get_nodedef_field(node_bottom.name, "buildable_to") + or not get_nodedef_field(node_top.name, "buildable_to") then + minetest.chat_send_player( placer:get_player_name(), S('Not enough space above that spot to place a door!') ) + else + local fdir = minetest.dir_to_facedir(placer:get_look_dir()) + local p_tests = { + {x=pos1.x-1, y=pos1.y, z=pos1.z}, + {x=pos1.x, y=pos1.y, z=pos1.z+1}, + {x=pos1.x+1, y=pos1.y, z=pos1.z}, + {x=pos1.x, y=pos1.y, z=pos1.z-1}, + } + print("fdir="..fdir) + local testnode = minetest.get_node(p_tests[fdir+1]) + local side = "left" - local def = { name = "homedecor:door_"..name.."_bottom_"..side, param2=fdir} - addDoorNode(pos1, def, true) - minetest.add_node(pos2, { name = "homedecor:door_"..name.."_top_"..side, param2=fdir}) - if not homedecor.expect_infinite_stacks then - itemstack:take_item() - return itemstack - end + if string.find(testnode.name, "homedecor:door_"..name.."_bottom_left") or forceright then + side = "right" + end + + local def = { name = "homedecor:door_"..name.."_bottom_"..side, param2=fdir} + addDoorNode(pos1, def, true) + minetest.add_node(pos2, { name = "homedecor:door_"..name.."_top_"..side, param2=fdir}) + if not homedecor.expect_infinite_stacks then + itemstack:take_item() + return itemstack end end - else - minetest.registered_nodes[pname].on_rightclick(pointed_thing.under, pnode, placer, itemstack) end end diff --git a/homedecor/init.lua b/homedecor/init.lua index 4638861e..d76297f0 100644 --- a/homedecor/init.lua +++ b/homedecor/init.lua @@ -61,8 +61,6 @@ end -- load various other components -dofile(homedecor.modpath.."/ownership.lua") - dofile(homedecor.modpath.."/misc_nodes.lua") -- the catch-all for all misc nodes dofile(homedecor.modpath.."/tables.lua") dofile(homedecor.modpath.."/electronics.lua") diff --git a/homedecor/lighting.lua b/homedecor/lighting.lua index 8c37907a..34d810c4 100644 --- a/homedecor/lighting.lua +++ b/homedecor/lighting.lua @@ -90,7 +90,7 @@ minetest.register_node('homedecor:glowlight_half_yellow', { groups = { snappy = 3 }, light_source = LIGHT_MAX, sounds = default.node_sound_wood_defaults(), - on_place = homedecor.protect_and_rotate + on_place = minetest.rotate_node }) minetest.register_node('homedecor:glowlight_quarter_yellow', { @@ -120,7 +120,7 @@ minetest.register_node('homedecor:glowlight_quarter_yellow', { groups = { snappy = 3 }, light_source = LIGHT_MAX-1, sounds = default.node_sound_wood_defaults(), - on_place = homedecor.protect_and_rotate + on_place = minetest.rotate_node }) -- White @@ -152,7 +152,7 @@ minetest.register_node('homedecor:glowlight_half_white', { groups = { snappy = 3 }, light_source = LIGHT_MAX, sounds = default.node_sound_wood_defaults(), - on_place = homedecor.protect_and_rotate + on_place = minetest.rotate_node }) minetest.register_node('homedecor:glowlight_quarter_white', { @@ -182,7 +182,7 @@ minetest.register_node('homedecor:glowlight_quarter_white', { groups = { snappy = 3 }, light_source = LIGHT_MAX-1, sounds = default.node_sound_wood_defaults(), - on_place = homedecor.protect_and_rotate + on_place = minetest.rotate_node }) -- Glowlight "cubes" @@ -214,8 +214,7 @@ minetest.register_node('homedecor:glowlight_small_cube_yellow', { groups = { snappy = 3 }, light_source = LIGHT_MAX-1, sounds = default.node_sound_wood_defaults(), - - on_place = homedecor.protect_and_rotate + on_place = minetest.rotate_node }) minetest.register_node('homedecor:glowlight_small_cube_white', { @@ -245,6 +244,6 @@ minetest.register_node('homedecor:glowlight_small_cube_white', { groups = { snappy = 3 }, light_source = LIGHT_MAX-1, sounds = default.node_sound_wood_defaults(), - on_place = homedecor.protect_and_rotate + on_place = minetest.rotate_node }) diff --git a/homedecor/ownership.lua b/homedecor/ownership.lua deleted file mode 100644 index f7987d27..00000000 --- a/homedecor/ownership.lua +++ /dev/null @@ -1,48 +0,0 @@ - -local S = homedecor.gettext - -function homedecor.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 = S("someone") - end - end - end - - elseif type(isprotect)=="function" then -- glomie's protection mod - if not isprotect(5, pos, placer) then - ownername = S("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 = S("someone") - end - end - - if ownername ~= false then - minetest.chat_send_player( placer:get_player_name(), S("Sorry, %s owns that spot."):format(ownername) ) - return true - else - return false - end -end - --- protection wrapper for 6d stuff - -function homedecor.protect_and_rotate(itemstack, placer, pointed_thing) - if not homedecor.node_is_owned(pointed_thing.under, placer) - and not homedecor.node_is_owned(pointed_thing.above, placer) then - local keys=placer:get_player_control() - minetest.rotate_and_place(itemstack, placer, pointed_thing, - homedecor.expect_infinite_stacks, {invert_wall = keys.sneak}) - end - return itemstack -end - diff --git a/signs_lib/init.lua b/signs_lib/init.lua index 712361c7..d18d52dd 100644 --- a/signs_lib/init.lua +++ b/signs_lib/init.lua @@ -416,14 +416,20 @@ minetest.register_node(":default:sign_wall", { local name name = minetest.get_node(pointed_thing.under).name if fences_with_sign[name] then - if signs_lib.node_is_owned(pointed_thing.under, placer) then + if minetest.is_protected(pointed_thing.under, placer:get_player_name()) then + minetest.record_protection_violation(pointed_thing.under, + placer:get_player_name()) return itemstack end else name = minetest.get_node(pointed_thing.above).name local def = minetest.registered_nodes[name] - if signs_lib.node_is_owned(pointed_thing.above, placer) - or (not def.buildable_to) then + if not def.buildable_to then + return itemstack + end + if minetest.is_protected(pointed_thing.above, placer:get_player_name()) then + minetest.record_protection_violation(pointed_thing.above, + placer:get_player_name()) return itemstack end end @@ -499,7 +505,11 @@ minetest.register_node(":default:sign_wall", { minetest.pos_to_string(pos) )) end - if signs_lib.node_is_owned(pos, sender) then return end + if minetest.is_protected(pos, sender:get_player_name()) then + minetest.record_protection_violation(pos, + sender:get_player_name()) + return + end signs_lib.update_sign(pos, fields) end, on_punch = function(pos, node, puncher) @@ -535,7 +545,11 @@ minetest.register_node(":signs:sign_yard", { minetest.pos_to_string(pos) )) end - if signs_lib.node_is_owned(pos, sender) then return end + if minetest.is_protected(pos, sender:get_player_name()) then + minetest.record_protection_violation(pos, + sender:get_player_name()) + return + end signs_lib.update_sign(pos, fields) end, on_punch = function(pos, node, puncher) @@ -617,18 +631,28 @@ function signs_lib.register_fence_with_sign(fencename, fencewithsignname) local def_above = minetest.registered_nodes[node_above.name] local def_under = minetest.registered_nodes[node_under.name] local fdir = minetest.dir_to_facedir(placer:get_look_dir()) + local playername = placer:get_player_name() + + if minetest.is_protected(pointed_thing.under, playername) then + minetest.record_protection_violation(pointed_thing.under, playername) + return + end + + if minetest.is_protected(pointed_thing.above, playername) then + minetest.record_protection_violation(pointed_thing.above, playername) + return + end + if def_under and def_under.on_rightclick then return def_under.on_rightclick(pointed_thing.under, node_under, placer, itemstack) or itemstack - elseif (not signs_lib.node_is_owned(pointed_thing.under, placer)) - and def_under.buildable_to then + elseif def_under.buildable_to then minetest.add_node(pointed_thing.under, {name = fencename, param2 = fdir}) if not signs_lib.expect_infinite_stacks then itemstack:take_item() end placer:set_wielded_item(itemstack) return itemstack - elseif (not signs_lib.node_is_owned(pointed_thing.above, placer)) - and def_above.buildable_to then + elseif def_above.buildable_to then minetest.add_node(pointed_thing.above, {name = fencename, param2 = fdir}) if not signs_lib.expect_infinite_stacks then itemstack:take_item() @@ -651,7 +675,11 @@ function signs_lib.register_fence_with_sign(fencename, fencewithsignname) minetest.pos_to_string(pos) )) end - if signs_lib.node_is_owned(pos, sender) then return end + if minetest.is_protected(pos, sender:get_player_name()) then + minetest.record_protection_violation(pos, + sender:get_player_name()) + return + end signs_lib.update_sign(pos, fields) end def_sign.on_punch = function(pos, node, puncher, ...) @@ -674,8 +702,6 @@ minetest.register_alias("homedecor:fence_wood_with_sign", "signs:sign_post") signs_lib.register_fence_with_sign("default:fence_wood", "signs:sign_post") -dofile(signs_lib.modpath.."/ownership.lua") - if minetest.setting_get("log_mods") then minetest.log("action", S("signs loaded")) end diff --git a/signs_lib/ownership.lua b/signs_lib/ownership.lua deleted file mode 100644 index dd012a5b..00000000 --- a/signs_lib/ownership.lua +++ /dev/null @@ -1,48 +0,0 @@ - -local S = signs_lib.gettext - -function signs_lib.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 = S("someone") - end - end - end - - elseif type(isprotect)=="function" then -- glomie's protection mod - if not isprotect(5, pos, placer) then - ownername = S("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 = S("someone") - end - end - - if ownername ~= false then - minetest.chat_send_player( placer:get_player_name(), S("Sorry, %s owns that spot."):format(ownername) ) - return true - else - return false - end -end - --- protection wrapper for 6d stuff - -function signs_lib.protect_and_rotate(itemstack, placer, pointed_thing) - if not signs_lib.node_is_owned(pointed_thing.under, placer) - and not signs_lib.node_is_owned(pointed_thing.above, placer) then - local keys=placer:get_player_control() - minetest.rotate_and_place(itemstack, placer, pointed_thing, - signs_lib.expect_infinite_stacks, {invert_wall = keys.sneak}) - end - return itemstack -end -