mail/onjoin.lua
Athozus 3bad371353
Add colors utilities (#121)
* Add colors utilities

Local function get_base_color(), conversions hex <=> rgb, rgb color mixer, and global function get_color()

* Round numbers to avoid eventual float in string.format

* Simplify inbox/outbox mixing of color

Use a single if statement for each property and concatenate to displayed_color then execute mail.get_color(displayed_color) instead of making many combined if statements

* Convert 3-chars hex colors to 6-chars hex colors

Could break the code, the hex convert to rgb always run on 6-chars

* Rework color utility using tables

Instead of one-letter symbols, it now supports tables of identifiers or single strings
2023-12-06 10:11:12 +01:00

24 lines
663 B
Lua

-- translation
local S = minetest.get_translator("mail")
minetest.register_on_joinplayer(function(player)
minetest.after(2, function(name)
local entry = mail.get_storage_entry(name)
local messages = entry.inbox
mail.hud_update(name, messages)
local unreadcount = 0
for _, message in pairs(messages) do
if not message.read then
unreadcount = unreadcount + 1
end
end
if unreadcount > 0 and mail.get_setting(name, "onjoin_notifications") then
minetest.chat_send_player(name,
minetest.colorize(mail.get_color("new"), "(" .. unreadcount .. ") " .. S("You have mail! Type /mail to read")))
end
end, player:get_player_name())
end)