55local world_path = minetest .get_worldpath ()
66simple_protection = {}
77simple_protection .claims = {}
8+ simple_protection .share = {}
89simple_protection .mod_path = minetest .get_modpath (" simple_protection" )
910simple_protection .conf = world_path .. " /s_protect.conf"
1011simple_protection .file = world_path .. " /s_protect.data"
12+ simple_protection .sharefile = world_path .. " /s_protect_share.data"
1113
1214dofile (simple_protection .mod_path .. " /functions.lua" )
1315simple_protection .load_config ()
1416dofile (simple_protection .mod_path .. " /protection.lua" )
1517
16- function vector .floor (v )
17- return {
18- x = math.floor (v .x ),
19- y = math.floor (v .y ),
20- z = math.floor (v .z )
21- }
22- end
23-
2418minetest .register_on_protection_violation (function (pos , player_name )
2519 minetest .chat_send_player (player_name , " Do not try to modify this area!" )
2620 -- PUNISH HIM!!!!
@@ -80,14 +74,18 @@ simple_protection.command_show = function(name)
8074 end
8175
8276 minetest .chat_send_player (name , " Area status: Owned by " .. data .owner )
83- local shared = " "
84- for player , really in pairs (data .shared ) do
85- if really then
86- shared = shared .. player .. " , "
77+ local text = " "
78+ for i , player in ipairs (data .shared ) do
79+ text = text .. player .. " , "
80+ end
81+ local shared = simple_protection .share [name ]
82+ if shared then
83+ for i , player in ipairs (shared ) do
84+ text = text .. player .. " *, "
8785 end
8886 end
89- if shared ~= " " then
90- minetest .chat_send_player (name , " Players with access: " .. shared )
87+ if text ~= " " then
88+ minetest .chat_send_player (name , " Players with access: " .. text )
9189 end
9290end
9391
@@ -114,11 +112,17 @@ simple_protection.command_share = function(name, param)
114112 minetest .chat_send_player (name , " You do not own this area." )
115113 return
116114 end
117- if data .shared [param ] then
115+ local shared = simple_protection .share [name ]
116+ if shared and shared [param ] then
117+ minetest .chat_send_player (name , param .. " already has access to all your areas." )
118+ return
119+ end
120+
121+ if table_contains (data .shared , param ) then
118122 minetest .chat_send_player (name , param .. " already has access to this area." )
119123 return
120124 end
121- data .shared [ param ] = true
125+ table.insert ( data .shared , param )
122126 simple_protection .save ()
123127 minetest .chat_send_player (name , param .. " has now access to this area." )
124128 if minetest .get_player_by_name (param ) then
@@ -140,11 +144,11 @@ simple_protection.command_unshare = function(name, param)
140144 minetest .chat_send_player (name , " You do not own this area." )
141145 return
142146 end
143- if not data .shared [ param ] then
147+ if not table_contains ( data .shared , param ) then
144148 minetest .chat_send_player (name , " This player has no access to this area." )
145149 return
146150 end
147- data .shared [ param ] = nil
151+ table_delete ( data .shared , param )
148152 simple_protection .save ()
149153 minetest .chat_send_player (name , param .. " has no longer access to this area." )
150154 if minetest .get_player_by_name (param ) then
@@ -166,12 +170,16 @@ simple_protection.command_shareall = function(name, param)
166170 end
167171 return
168172 end
169- -- loops everywhere
170- for pos , data in pairs (simple_protection .claims ) do
171- if data .owner == name then
172- data .shared [param ] = true
173- end
173+
174+ local shared = simple_protection .share [name ]
175+ if table_contains (shared , param ) then
176+ minetest .chat_send_player (name , param .. " already has now access to all your areas." )
177+ return
178+ end
179+ if not shared then
180+ simple_protection .share [name ] = {}
174181 end
182+ table.insert (simple_protection .share [name ], param )
175183 simple_protection .save ()
176184 minetest .chat_send_player (name , param .. " has now access to all your areas." )
177185 if minetest .get_player_by_name (param ) then
@@ -181,13 +189,25 @@ end
181189
182190simple_protection .command_unshareall = function (name , param )
183191 if name == param then return end
192+ local removed = false
193+ local shared = simple_protection .share [name ]
194+ if table_delete (shared , param ) then
195+ removed = true
196+ end
197+
184198 -- loops everywhere
185199 for pos , data in pairs (simple_protection .claims ) do
186200 if data .owner == name then
187- data .shared [param ] = nil
201+ if table_delete (data .shared , param ) then
202+ removed = true
203+ end
188204 end
189205 end
190206 simple_protection .save ()
207+ if not removed then
208+ minetest .chat_send_player (name , param .. " did not have access to any of your areas." )
209+ return
210+ end
191211 minetest .chat_send_player (name , param .. " has no longer access to your areas." )
192212 if minetest .get_player_by_name (param ) then
193213 minetest .chat_send_player (param , name .. " unshared all areas with you." )
0 commit comments