Skip to content

Commit 76ca70c

Browse files
committed
Localize the hud table and tidy up the chat commands
1 parent 8df7cf4 commit 76ca70c

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

init.lua

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ s_protect.command_show = function(name)
5959
local player_pos = vector.round(player:getpos())
6060
local data = s_protect.get_data(player_pos)
6161

62-
minetest.add_entity(s_protect.get_center(player_pos), "s_protect:marker")
62+
minetest.add_entity(s_protect.get_center(player_pos), "simple_protection:marker")
6363
local axis = s_protect.get_y_axis(player_pos.y)
6464
local y_end = axis + s_protect.claim_height
6565
minetest.chat_send_player(name, "Vertical area limit from Y "..axis.." to "..y_end)
@@ -180,23 +180,22 @@ s_protect.command_unshareall = function(name, param)
180180
removed = true
181181
end
182182

183-
--loops everywhere
183+
-- Unshare each single claim
184184
for pos, data in pairs(s_protect.claims) do
185185
if data.owner == name then
186186
if table_delete(data.shared, param) then
187187
removed = true
188188
end
189189
end
190190
end
191-
s_protect.save()
192191
if not removed then
193-
minetest.chat_send_player(name, param.." did not have access to any of your areas.")
194-
return
192+
return false, param.." did not have access to any of your areas."
195193
end
196-
minetest.chat_send_player(name, param.." has no longer access to your areas.")
194+
s_protect.save()
197195
if minetest.get_player_by_name(param) then
198196
minetest.chat_send_player(param, name.." unshared all areas with you.")
199197
end
198+
return true, param.." has no longer access to your areas."
200199
end
201200

202201
s_protect.command_unclaim = function(name)
@@ -205,13 +204,11 @@ s_protect.command_unclaim = function(name)
205204
local pos = s_protect.get_location(player_pos)
206205
local data = s_protect.claims[pos]
207206
if not data then
208-
minetest.chat_send_player(name, "You do not own this area.")
209-
return
207+
return false, "You do not own this area."
210208
end
211-
local priv = minetest.check_player_privs(name, {simple_protection=true})
209+
local privs = minetest.check_player_privs(name, {simple_protection=true})
212210
if name ~= data.owner and not priv then
213-
minetest.chat_send_player(name, "You do not own this area.")
214-
return
211+
return false, "You do not own this area."
215212
end
216213
if not priv and s_protect.claim_return then
217214
local inv = player:get_inventory()
@@ -221,5 +218,5 @@ s_protect.command_unclaim = function(name)
221218
end
222219
s_protect.claims[pos] = nil
223220
s_protect.save()
224-
minetest.chat_send_player(name, "This area is unowned now.")
221+
return true, "This area is unowned now."
225222
end

protection.lua

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,19 @@ minetest.item_place = function(itemstack, placer, pointed_thing)
3333
end
3434
end
3535

36-
s_protect.hud_time = 0
36+
local hud_time = 0
3737
s_protect.player_huds = {}
3838

3939
minetest.register_globalstep(function(dtime)
40-
s_protect.hud_time = s_protect.hud_time + dtime
41-
if s_protect.hud_time < 3 then
40+
hud_time = hud_time + dtime
41+
if hud_time < 3 then
4242
return
4343
end
44-
s_protect.hud_time = 0
45-
-- get players
44+
hud_time = 0
45+
46+
4647
local shared = s_protect.share
47-
for _,player in ipairs(minetest.get_connected_players()) do
48+
for _, player in ipairs(minetest.get_connected_players()) do
4849
local pos = vector.round(player:getpos())
4950
local player_name = player:get_player_name()
5051

@@ -56,23 +57,24 @@ minetest.register_globalstep(function(dtime)
5657

5758
local has_access = (current_owner == player_name)
5859
if not has_access and data then
60+
-- Check if this area is shared with this player
5961
has_access = table_contains(data.shared, player_name)
6062
end
6163
if not has_access then
64+
-- Check if all areas are shared with this player
6265
has_access = table_contains(shared[current_owner], player_name)
6366
end
6467
local changed = true
6568

66-
if s_protect.player_huds[player_name] then
67-
if s_protect.player_huds[player_name].owner == current_owner and
68-
s_protect.player_huds[player_name].had_access == has_access then
69-
-- still the same hud
70-
changed = false
71-
end
69+
local hud_table = s_protect.player_huds[player_name]
70+
if hud_table and hud_table.owner == current_owner
71+
and hud_table.had_access == has_access then
72+
-- still the same hud
73+
changed = false
7274
end
7375

74-
if s_protect.player_huds[player_name] and changed then
75-
player:hud_remove(s_protect.player_huds[player_name].hudID)
76+
if hud_table and changed then
77+
player:hud_remove(hud_table.hudID)
7678
s_protect.player_huds[player_name] = nil
7779
end
7880

settings.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-- Size of claims in nodes, must be an even number <[16]>
55
s_protect.claim_size = 16
66

7-
-- High of claims in nodes <[80]>
7+
-- Height of claims in nodes <[80]>
88
s_protect.claim_height = 80
99

1010
-- Nodes to start in underground, 80 - 20 = 60 nodes above ground <[20]>

0 commit comments

Comments
 (0)