ctf_stats: Add ctf_stats.request_save

This functionality allows mods to request a save (not immediate) if they modify player stats.
This commit is contained in:
ANAND 2020-05-14 23:55:25 +05:30
parent f1a2006ec5
commit 181b13d1d0
4 changed files with 17 additions and 6 deletions

View file

@ -161,6 +161,7 @@ minetest.register_chatcommand("reset_rankings", {
ctf_stats.players[reset_name] = nil
ctf_stats.player(reset_name)
ctf_stats.request_save()
if reset_name == name then
minetest.log("action", name .. " reset their rankings")
@ -198,6 +199,8 @@ minetest.register_chatcommand("transfer_rankings", {
ctf_stats.players[dest] = ctf_stats.players[src]
ctf_stats.players[src] = nil
ctf_stats.request_save()
minetest.log("action", name .. " transferred stats of " .. src .. " to " .. dest)
return true, "Stats of '" .. src .. "' have been transferred to '" .. dest .. "'."
end

View file

@ -110,7 +110,10 @@ local function check_if_save_needed()
end
minetest.after(13, check_if_save_needed)
minetest.after(13, ctf_stats.save)
-- API function to allow other mods to request a save
-- TODO: This should be done automatically once a proper API is in place
function ctf_stats.request_save()
_needs_save = true
end
function ctf_stats.player_or_nil(name)