1
0
mirror of https://github.com/Sokomine/cottages.git synced 2024-11-14 22:40:31 +01:00
cottages/util.lua

72 lines
1.6 KiB
Lua
Raw Normal View History

2022-10-09 23:13:47 +02:00
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")
2022-10-10 23:35:32 +02:00
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
2022-10-09 23:13:47 +02:00
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")
2022-10-10 23:22:02 +02:00
if (owner == "" or owner == " ") and not minetest.is_protected(pos, sender_name) then
owner = sender_name
2022-10-11 00:09:31 +02:00
meta:set_string("owner", sender_name)
2022-10-09 23:13:47 +02:00
end
2022-10-10 23:35:32 +02:00
if meta:get_string("public") == "public" then
meta:set_int("public", 2)
end
local public = meta:get_int("public")
2022-10-09 23:13:47 +02:00
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