mirror of
https://github.com/Sokomine/cottages.git
synced 2024-11-14 14:30:33 +01:00
72 lines
1.6 KiB
Lua
72 lines
1.6 KiB
Lua
local util = {}
|
|
|
|
function util.player_can_use(pos, player)
|
|
if not (pos and minetest.is_player(player)) then
|
|
return false
|
|
end
|
|
|
|
local player_name = player:get_player_name()
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if meta:get_string("public") == "public" then
|
|
meta:set_int("public", 2)
|
|
end
|
|
|
|
local owner = meta:get_string("owner")
|
|
local public = meta:get_int("public")
|
|
|
|
if owner == player_name then
|
|
return true
|
|
|
|
elseif owner == "" or owner == " " or public == 1 then
|
|
return not minetest.is_protected(pos, player_name)
|
|
|
|
else
|
|
return true
|
|
end
|
|
end
|
|
|
|
function util.toggle_public(pos, sender)
|
|
local sender_name = sender:get_player_name()
|
|
local meta = minetest.get_meta(pos)
|
|
local owner = meta:get_string("owner")
|
|
|
|
if (owner == "" or owner == " ") and not minetest.is_protected(pos, sender_name) then
|
|
owner = sender_name
|
|
meta:set_string("owner", sender_name)
|
|
end
|
|
|
|
if meta:get_string("public") == "public" then
|
|
meta:set_int("public", 2)
|
|
end
|
|
|
|
local public = meta:get_int("public")
|
|
|
|
if public == 0 and owner == sender_name then
|
|
-- owner can switch private to protected
|
|
meta:set_int("public", 1)
|
|
return true
|
|
|
|
elseif public == 1 and not minetest.is_protected(pos, sender_name) then
|
|
-- player of area can switch protected to public
|
|
meta:set_int("public", 2)
|
|
return true
|
|
|
|
elseif public == 2 then
|
|
if owner == sender_name then
|
|
-- owner can switch public to private
|
|
meta:set_int("public", 0)
|
|
return true
|
|
|
|
elseif not minetest.is_protected(pos, sender_name) then
|
|
-- player of area can switch public to protected
|
|
meta:set_int("public", 1)
|
|
return true
|
|
end
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
cottages.util = util
|