emeraldbank.broadcast() func optional notifications_wrapper mod

This commit is contained in:
Freeman 2024-10-12 23:47:37 +02:00
parent 6a4f98a137
commit 1263a9fee3
3 changed files with 25 additions and 17 deletions

@ -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

@ -50,7 +50,7 @@ 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.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

@ -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