Skip to content

Commit

Permalink
wipe old HUD waypoints when using admin commands to change or remove …
Browse files Browse the repository at this point in the history
…settlement names
  • Loading branch information
FaceDeer committed Jan 15, 2020
1 parent 97c7e9a commit febc19b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
9 changes: 5 additions & 4 deletions chatcommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ minetest.register_chatcommand("settlements_rename_nearest", {
settlements.settlements_in_world:insert_area(min_pos, min_pos, minetest.serialize(min_data), min_id)
settlements.settlements_save()
minetest.log("action", "[settlements] Renamed " .. oldname .. " to " .. param)
minetest.chat_send_player(name, S("Settlement successfully renamed from @1 to @2.", oldname, param)
.. " " .. S("Existing HUD waypoints for nearby players won't update until they go out of range and the waypoint is recreated again."))
minetest.chat_send_player(name, S("Settlement successfully renamed from @1 to @2.", oldname, param))
settlements.remove_all_hud_markers()
return
end

Expand Down Expand Up @@ -150,6 +150,7 @@ minetest.register_chatcommand("settlements_regenerate_names_for_type", {
end
end
settlements.settlements_save()
settlements.remove_all_hud_markers()
end,
})

Expand All @@ -168,8 +169,8 @@ minetest.register_chatcommand("settlements_remove_nearest", {
if result then
settlements.settlements_save()
minetest.log("action", "[settlements] Removed " .. min_data.name)
minetest.chat_send_player(name, S("Settlement @1 successfully removed.", min_data.name)
.." "..S("Existing HUD waypoints for nearby players won't update until they go out of range and the waypoint is recreated again."))
minetest.chat_send_player(name, S("Settlement @1 successfully removed.", min_data.name))
settlements.remove_all_hud_markers()
return
else
minetest.chat_send_player(name, S("Error removing settlement @1.", min_data.name))
Expand Down
13 changes: 13 additions & 0 deletions hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ local remove_distant_hud_markers = function()
end
end

-- For flushing outdated HUD markers when certain admin commands are performed.
settlements.remove_all_hud_markers = function()
for player_name, waypoints in pairs(player_huds) do
local player = minetest.get_player_by_name(player_name)
if player then
for pos_hash, hud_id in pairs(waypoints) do
player:hud_remove(hud_id)
end
end
end
player_huds = {}
end

local elapsed = 0
minetest.register_globalstep(function(dtime)
elapsed = elapsed + dtime
Expand Down
7 changes: 0 additions & 7 deletions locale/template.pot
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,6 @@ msgstr ""
msgid "Settlement successfully renamed from @1 to @2."
msgstr ""

#: chatcommands.lua:115
#: chatcommands.lua:172
msgid ""
"Existing HUD waypoints for nearby players won't update until they go out of "
"range and the waypoint is recreated again."
msgstr ""

#: chatcommands.lua:119
#: chatcommands.lua:179
msgid "No known settlements within @1m found."
Expand Down

0 comments on commit febc19b

Please sign in to comment.