_doors.registered_doors = {}
_doors.registered_trapdoors = {}
+local function replace_old_owner_information(pos)
+ local meta = minetest.get_meta(pos)
+ local owner = meta:get_string("doors_owner")
+ if owner and owner ~= "" then
+ meta:set_string("owner", owner)
+ meta:set_string("doors_owner", "")
+ end
+end
+
-- returns an object to a door object or nil
function doors.get(pos)
local node_name = minetest.get_node(pos).name
state = tonumber(state)
end
- if clicker and not minetest.check_player_privs(clicker, "protection_bypass") then
- -- is player wielding the right key?
- local item = clicker:get_wielded_item()
- local owner = meta:get_string("doors_owner")
- if item:get_name() == "default:key" then
- local key_meta = item:get_meta()
- local secret = meta:get_string("key_lock_secret")
-
- if key_meta:get_string("secret") == "" then
- key_meta:set_string("secret", minetest.parse_json(item:get_metadata()).secret)
- item:set_metadata("")
- end
+ replace_old_owner_information(pos)
- if secret ~= key_meta:get_string("secret") then
- return false
- end
-
- elseif owner ~= "" then
- if clicker:get_player_name() ~= owner then
- return false
- end
- end
+ if not default.can_interact_with_node(clicker, pos) then
+ return false
end
-- until Lua-5.2 we have no bitwise operators :(
end
local function can_dig_door(pos, digger)
- local digger_name = digger and digger:get_player_name()
- if digger_name and minetest.get_player_privs(digger_name).protection_bypass then
- return true
- end
- return minetest.get_meta(pos):get_string("doors_owner") == digger_name
+ replace_old_owner_information(pos)
+ return default.can_interact_with_node(digger, pos)
end
function doors.register(name, def)
meta:set_int("state", state)
if def.protected then
- meta:set_string("doors_owner", pn)
+ meta:set_string("owner", pn)
meta:set_string("infotext", "Owned by " .. pn)
end
door:toggle(player)
end
def.on_skeleton_key_use = function(pos, player, newsecret)
+ replace_old_owner_information(pos)
local meta = minetest.get_meta(pos)
- local owner = meta:get_string("doors_owner")
+ local owner = meta:get_string("owner")
local pname = player:get_player_name()
-- verify placer is owner of lockable door
function _doors.trapdoor_toggle(pos, node, clicker)
node = node or minetest.get_node(pos)
- if clicker and not minetest.check_player_privs(clicker, "protection_bypass") then
- -- is player wielding the right key?
- local item = clicker:get_wielded_item()
- local meta = minetest.get_meta(pos)
- local owner = meta:get_string("doors_owner")
- if item:get_name() == "default:key" then
- local key_meta = item:get_meta()
- local secret = meta:get_string("key_lock_secret")
-
- if key_meta:get_string("secret") == "" then
- key_meta:set_string("secret", minetest.parse_json(item:get_metadata()).secret)
- end
- if secret ~= key_meta:get_string("secret") then
- return false
- end
+ replace_old_owner_information(pos)
- elseif owner ~= "" then
- if clicker:get_player_name() ~= owner then
- return false
- end
- end
+ if not default.can_interact_with_node(clicker, pos) then
+ return false
end
local def = minetest.registered_nodes[node.name]
def.after_place_node = function(pos, placer, itemstack, pointed_thing)
local pn = placer:get_player_name()
local meta = minetest.get_meta(pos)
- meta:set_string("doors_owner", pn)
+ meta:set_string("owner", pn)
meta:set_string("infotext", "Owned by "..pn)
return minetest.setting_getbool("creative_mode")
door:toggle(player)
end
def.on_skeleton_key_use = function(pos, player, newsecret)
+ replace_old_owner_information(pos)
local meta = minetest.get_meta(pos)
- local owner = meta:get_string("doors_owner")
+ local owner = meta:get_string("owner")
local pname = player:get_player_name()
-- verify placer is owner of lockable door