Remove old ownership code and use Minetest's built-in ownership code instead

Some minor code rewrites here and there to accommodate this changeover.
This commit is contained in:
Vanessa Ezekowitz 2014-01-30 14:09:46 -05:00
parent b11b3a95ec
commit a6122f03d9
6 changed files with 86 additions and 148 deletions

View File

@ -424,14 +424,19 @@ function homedecor.place_door(itemstack, placer, pointed_thing, name, forceright
local pointed = pointed_thing.under local pointed = pointed_thing.under
local pnode = minetest.get_node(pointed) local pnode = minetest.get_node(pointed)
local pname = pnode.name local pname = pnode.name
local rnodedef = minetest.registered_nodes[pname]
if not minetest.registered_nodes[pname] if rnodedef then
or not minetest.registered_nodes[pname].on_rightclick then
if rnodedef.on_rightclick then
rnodedef.on_rightclick(pointed_thing.under, pnode, placer, itemstack)
return
end
local pos1 = nil local pos1 = nil
local pos2 = nil local pos2 = nil
if minetest.registered_nodes[pname]["buildable_to"] then if rnodedef["buildable_to"] then
pos1 = pointed pos1 = pointed
pos2 = {x=pointed.x, y=pointed.y+1, z=pointed.z} pos2 = {x=pointed.x, y=pointed.y+1, z=pointed.z}
else else
@ -442,8 +447,17 @@ function homedecor.place_door(itemstack, placer, pointed_thing, name, forceright
local node_bottom = minetest.get_node(pos1) local node_bottom = minetest.get_node(pos1)
local node_top = minetest.get_node(pos2) local node_top = minetest.get_node(pos2)
if not homedecor.node_is_owned(pos1, placer) if minetest.is_protected(pos1, placer:get_player_name()) then
and not homedecor.node_is_owned(pos2, placer) then minetest.record_protection_violation(pos1,
placer:get_player_name())
return
end
if minetest.is_protected(pos2, placer:get_player_name()) then
minetest.record_protection_violation(pos2,
placer:get_player_name())
return
end
if not get_nodedef_field(node_bottom.name, "buildable_to") if not get_nodedef_field(node_bottom.name, "buildable_to")
or not get_nodedef_field(node_top.name, "buildable_to") then or not get_nodedef_field(node_top.name, "buildable_to") then
@ -473,9 +487,6 @@ function homedecor.place_door(itemstack, placer, pointed_thing, name, forceright
end end
end end
end end
else
minetest.registered_nodes[pname].on_rightclick(pointed_thing.under, pnode, placer, itemstack)
end
end end
-- to open a door, you switch left for right and subtract from param2, or vice versa right for left -- to open a door, you switch left for right and subtract from param2, or vice versa right for left

View File

@ -61,8 +61,6 @@ end
-- load various other components -- 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.."/misc_nodes.lua") -- the catch-all for all misc nodes
dofile(homedecor.modpath.."/tables.lua") dofile(homedecor.modpath.."/tables.lua")
dofile(homedecor.modpath.."/electronics.lua") dofile(homedecor.modpath.."/electronics.lua")

View File

@ -90,7 +90,7 @@ minetest.register_node('homedecor:glowlight_half_yellow', {
groups = { snappy = 3 }, groups = { snappy = 3 },
light_source = LIGHT_MAX, light_source = LIGHT_MAX,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_place = homedecor.protect_and_rotate on_place = minetest.rotate_node
}) })
minetest.register_node('homedecor:glowlight_quarter_yellow', { minetest.register_node('homedecor:glowlight_quarter_yellow', {
@ -120,7 +120,7 @@ minetest.register_node('homedecor:glowlight_quarter_yellow', {
groups = { snappy = 3 }, groups = { snappy = 3 },
light_source = LIGHT_MAX-1, light_source = LIGHT_MAX-1,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_place = homedecor.protect_and_rotate on_place = minetest.rotate_node
}) })
-- White -- White
@ -152,7 +152,7 @@ minetest.register_node('homedecor:glowlight_half_white', {
groups = { snappy = 3 }, groups = { snappy = 3 },
light_source = LIGHT_MAX, light_source = LIGHT_MAX,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_place = homedecor.protect_and_rotate on_place = minetest.rotate_node
}) })
minetest.register_node('homedecor:glowlight_quarter_white', { minetest.register_node('homedecor:glowlight_quarter_white', {
@ -182,7 +182,7 @@ minetest.register_node('homedecor:glowlight_quarter_white', {
groups = { snappy = 3 }, groups = { snappy = 3 },
light_source = LIGHT_MAX-1, light_source = LIGHT_MAX-1,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_place = homedecor.protect_and_rotate on_place = minetest.rotate_node
}) })
-- Glowlight "cubes" -- Glowlight "cubes"
@ -214,8 +214,7 @@ minetest.register_node('homedecor:glowlight_small_cube_yellow', {
groups = { snappy = 3 }, groups = { snappy = 3 },
light_source = LIGHT_MAX-1, light_source = LIGHT_MAX-1,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_place = minetest.rotate_node
on_place = homedecor.protect_and_rotate
}) })
minetest.register_node('homedecor:glowlight_small_cube_white', { minetest.register_node('homedecor:glowlight_small_cube_white', {
@ -245,6 +244,6 @@ minetest.register_node('homedecor:glowlight_small_cube_white', {
groups = { snappy = 3 }, groups = { snappy = 3 },
light_source = LIGHT_MAX-1, light_source = LIGHT_MAX-1,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_place = homedecor.protect_and_rotate on_place = minetest.rotate_node
}) })

View File

@ -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

View File

@ -416,14 +416,20 @@ minetest.register_node(":default:sign_wall", {
local name local name
name = minetest.get_node(pointed_thing.under).name name = minetest.get_node(pointed_thing.under).name
if fences_with_sign[name] then 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 return itemstack
end end
else else
name = minetest.get_node(pointed_thing.above).name name = minetest.get_node(pointed_thing.above).name
local def = minetest.registered_nodes[name] local def = minetest.registered_nodes[name]
if signs_lib.node_is_owned(pointed_thing.above, placer) if not def.buildable_to then
or (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 return itemstack
end end
end end
@ -499,7 +505,11 @@ minetest.register_node(":default:sign_wall", {
minetest.pos_to_string(pos) minetest.pos_to_string(pos)
)) ))
end 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) signs_lib.update_sign(pos, fields)
end, end,
on_punch = function(pos, node, puncher) on_punch = function(pos, node, puncher)
@ -535,7 +545,11 @@ minetest.register_node(":signs:sign_yard", {
minetest.pos_to_string(pos) minetest.pos_to_string(pos)
)) ))
end 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) signs_lib.update_sign(pos, fields)
end, end,
on_punch = function(pos, node, puncher) 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_above = minetest.registered_nodes[node_above.name]
local def_under = minetest.registered_nodes[node_under.name] local def_under = minetest.registered_nodes[node_under.name]
local fdir = minetest.dir_to_facedir(placer:get_look_dir()) 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 if def_under and def_under.on_rightclick then
return def_under.on_rightclick(pointed_thing.under, node_under, placer, itemstack) or itemstack 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)) elseif def_under.buildable_to then
and def_under.buildable_to then
minetest.add_node(pointed_thing.under, {name = fencename, param2 = fdir}) minetest.add_node(pointed_thing.under, {name = fencename, param2 = fdir})
if not signs_lib.expect_infinite_stacks then if not signs_lib.expect_infinite_stacks then
itemstack:take_item() itemstack:take_item()
end end
placer:set_wielded_item(itemstack) placer:set_wielded_item(itemstack)
return itemstack return itemstack
elseif (not signs_lib.node_is_owned(pointed_thing.above, placer)) elseif def_above.buildable_to then
and def_above.buildable_to then
minetest.add_node(pointed_thing.above, {name = fencename, param2 = fdir}) minetest.add_node(pointed_thing.above, {name = fencename, param2 = fdir})
if not signs_lib.expect_infinite_stacks then if not signs_lib.expect_infinite_stacks then
itemstack:take_item() itemstack:take_item()
@ -651,7 +675,11 @@ function signs_lib.register_fence_with_sign(fencename, fencewithsignname)
minetest.pos_to_string(pos) minetest.pos_to_string(pos)
)) ))
end 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) signs_lib.update_sign(pos, fields)
end end
def_sign.on_punch = function(pos, node, puncher, ...) 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") 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 if minetest.setting_get("log_mods") then
minetest.log("action", S("signs loaded")) minetest.log("action", S("signs loaded"))
end end

View File

@ -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