diff --git a/functions.lua b/functions.lua index 1dc7ca0..6cca60e 100644 --- a/functions.lua +++ b/functions.lua @@ -21,6 +21,24 @@ local S = core.get_translator(core.get_current_modname()) +function emeraldbank.broadcast(player, msg, color, timeout) + if not player:is_player() then return end + local name = player:get_player_name() + if core.get_modpath("notifications_wrapper") then + notifications.queue({ + playerName = name, + title = S("EmeraldBank Notification"), + text = msg, + --image = "mcl_core_emerald.png", + timeout = timeout or 5 + }) + elseif core.get_modpath("mcl_title") then + mcl_title.set(player, "actionbar", {text=msg, color=color or "green"}) + else + core.chat_send_player(name, msg) + end +end + function emeraldbank.get_emeralds(name) atm.read_account(name) return atm.balance[name] @@ -46,12 +64,7 @@ function emeraldbank.set_emeralds(player, num) if num then atm.balance[name] = math.floor(num) - - -- Update actionbar only if 'player' is a player object - if type(player) ~= "string" then - mcl_title.set(player, "actionbar", {text=S("Emeralds in Bank: @1", atm.balance[name]), color="yellow"}) - end - + emeraldbank.broadcast(player, S("Emeralds in Bank: @1", atm.balance[name]), "yellow") atm.save_account(name) return true end @@ -78,12 +91,7 @@ function emeraldbank.add_emeralds(player, num) if num then atm.balance[name] = math.floor(atm.balance[name] + num) - - -- Update actionbar only if 'player' is a player object - if type(player) ~= "string" then - mcl_title.set(player, "actionbar", {text=S("Emeralds in Bank: @1", atm.balance[name]), color="yellow"}) - end - + emeraldbank.broadcast(player, S("Emeralds in Bank: @1", atm.balance[name]), "yellow") atm.save_account(name) return true end diff --git a/income.lua b/income.lua index dcbec76..8a3c001 100644 --- a/income.lua +++ b/income.lua @@ -50,9 +50,9 @@ function emeraldbank.income(dtime) local had_start_balance = meta:get_string("emeraldbank_had_start_balance") if had_start_balance == "" or had_start_balance == nil then - mcl_title.set(player, "actionbar", {text=S("You have earned your starting balance for playtime: @1", atm.startbalance), color="green"}) - emeraldbank.add_emeralds(player, atm.startbalance) - meta:set_string("emeraldbank_had_start_balance", "true") + emeraldbank.broadcast(player, S("You have earned your starting balance for playtime: @1", atm.startbalance), "green") + emeraldbank.add_emeralds(player, atm.startbalance) + meta:set_string("emeraldbank_had_start_balance", "true") end end end diff --git a/mod.conf b/mod.conf index d548da7..0aa586d 100644 --- a/mod.conf +++ b/mod.conf @@ -1,5 +1,5 @@ name = emeraldbank -depends = mcl_core, mcl_sounds, mcl_inventory, mcl_formspec, mcl_title -optional_depends = irc, yl_matterbridge, awards, mail, beerchat +depends = mcl_core, mcl_sounds, mcl_inventory, mcl_formspec +optional_depends = irc, yl_matterbridge, awards, mail, beerchat, notifications_wrapper, mcl_title description = Keep your Emeralds in a bank!. supported_games = mineclonia