Reduce awards.player() calls

This commit is contained in:
rubenwardy 2018-04-04 17:32:37 +01:00
parent eeee4a8398
commit c579f862b6

11
api.lua
View File

@ -278,10 +278,10 @@ function awards.unlock(name, award)
-- Do Notification -- Do Notification
if sound then if sound then
-- Enforce sound delay to prevent sound spamming -- Enforce sound delay to prevent sound spamming
local lastsound = awards.player(name).lastsound local lastsound = data.lastsound
if lastsound == nil or os.difftime(os.time(), lastsound) >= 1 then if lastsound == nil or os.difftime(os.time(), lastsound) >= 1 then
minetest.sound_play(sound, {to_player=name}) minetest.sound_play(sound, {to_player=name})
awards.player(name).lastsound = os.time() data.lastsound = os.time()
end end
end end
@ -459,7 +459,8 @@ function awards.show_to(name, to, sid, text)
if name == "" or name == nil then if name == "" or name == nil then
name = to name = to
end end
if name == to and awards.player(to).disabled then local data = awards.player(to)
if name == to and data.disabled then
minetest.chat_send_player(S("You've disabled awards. Type /awards enable to reenable.")) minetest.chat_send_player(S("You've disabled awards. Type /awards enable to reenable."))
return return
end end
@ -468,13 +469,13 @@ function awards.show_to(name, to, sid, text)
if #listofawards == 0 then if #listofawards == 0 then
minetest.chat_send_player(to, S("Error: No awards available.")) minetest.chat_send_player(to, S("Error: No awards available."))
return return
elseif not awards.player(name) or not awards.player(name).unlocked then elseif not data or not data.unlocked then
minetest.chat_send_player(to, S("You have not unlocked any awards.")) minetest.chat_send_player(to, S("You have not unlocked any awards."))
return return
end end
minetest.chat_send_player(to, string.format(S("%ss awards:"), name)) minetest.chat_send_player(to, string.format(S("%ss awards:"), name))
for _, str in pairs(awards.player(name).unlocked) do for _, str in pairs(data.unlocked) do
local def = awards.def[str] local def = awards.def[str]
if def then if def then
if def.title then if def.title then