Sons do bloco! + API de Registro de Login + Comando /president

This commit is contained in:
Lunovox 2023-07-20 22:44:51 -03:00
parent 57129a99d5
commit 023de38b03
17 changed files with 288 additions and 18 deletions

Binary file not shown.

115
api.lua Normal file
View file

@ -0,0 +1,115 @@
minetest.register_privilege("electoraljudge", {
description=modEUrn.translate("Allows you to configure the Electronic Urn."),
give_to_singleplayer=false,
})
modEUrn.handler = {
--[[ ]]
elected = {
president = {
name = "", --name of the elected candidate.
when = 0, --when the candidate was elected.
voters = { }, --names of voters who voted for this elected candidate.
},
},
candidates = {
president = { }, --modEUrn.handler.candidates.president[<candidatename>] = <when> | If the candidate has not updated his candidacy for more than 6 months, he loses his candidacy application.
},
--]]
voters = { }, --modEUrn.handler.voters[playername]
}
modEUrn.doSave = function()
local file = io.open(modEUrn.urlTabela, "w")
if file then
file:write(minetest.serialize(modEUrn.handler))
file:close()
minetest.log('action',"[E-URN] "..modEUrn.translate("Database saved in file '%s'!"):format(modEUrn.urlTabela))
else
minetest.log('error',"[E-URN:ERRO] "..modEUrn.translate("The file '%s' is not in table format!"):format(modEUrn.urlTabela))
end
end
modEUrn.doLoad = function()
local file = io.open(modEUrn.urlTabela, "r")
if file then
local handler = minetest.deserialize(file:read("*all"))
file:close()
if not handler or type(handler) ~= "table" then
minetest.log('error',"[E-URN:ERRO] "..modEUrn.translate("The file '%s' is not in table format!"):format(modEUrn.urlTabela))
return { }
else
modEUrn.handler = handler
minetest.log('action',"[E-URN] "..modEUrn.translate("Database '%s' loaded!"):format(modEUrn.urlTabela))
end
end
end
modEUrn.on_leaveplayer = function(player)
local playername = player:get_player_name()
local now = os.time() --Em milisegundos
if modEUrn.handler.voters[playername]~=nil and type(modEUrn.handler.voters[playername]) == "table" then
if modEUrn.handler.voters[playername].times.login~=nil and type(modEUrn.handler.voters[playername].times.login) == "number" and modEUrn.handler.voters[playername].times.login > 0 then
if modEUrn.handler.voters[playername].times.played~=nil and type(modEUrn.handler.voters[playername].times.played) == "number" and modEUrn.handler.voters[playername].times.played > 0 then
modEUrn.handler.voters[playername].times.played = modEUrn.handler.voters[playername].times.played + (now - modEUrn.handler.voters[playername].times.login)
else
modEUrn.handler.voters[playername].times.played = (now - modEUrn.handler.voters[playername].times.login)
end
modEUrn.handler.voters[playername].times.login = 0
modEUrn.handler.voters[playername].times.logout = now
end
else
minetest.log('error',"[E-URN:ERROR:ONLEAVEPLAYER] "..modEUrn.translate("Impossible to register logout for player '%s' !"):format(dump(player)))
end
end
minetest.register_on_leaveplayer(function(player)
modEUrn.on_leaveplayer(player)
modEUrn.doSave()
end)
--[[
minetest.register_on_newplayer(function(player)
end)
--]]
--[[
minetest.register_on_prejoinplayer(function(name, ip)
end)
--]]
minetest.register_on_joinplayer(function(player)
local playername = player:get_player_name()
local now = os.time() --Em milisegundos
if playername~=nil and type(playername)=="string" and playername~="" then
if modEUrn.handler.voters[playername]==nil then
modEUrn.handler.voters[playername] = {
times ={
register = now,
played = 0,
login = now,
logout = 0,
},
}
end
modEUrn.handler.voters[playername].times.login = now
modEUrn.handler.voters[playername].times.logout = 0
else
minetest.log('error',"[E-URN:ERROR:ONJOINPLAYER] "..modEUrn.translate("Impossible to register login for player '%s' !"):format(dump(player)))
end
end)
minetest.register_on_shutdown(function()
local players = minetest.get_connected_players()
if #players >= 1 then
for _, player in ipairs(players) do
modEUrn.on_leaveplayer(player)
end
end
modEUrn.doSave()
minetest.log('action',"[E-URN] "..modEUrn.translate("Saving strongbox from all players in the file '%s'!"):format(modEUrn.urlTabela))
end)

60
commands.lua Normal file
View file

@ -0,0 +1,60 @@
--[[
elected = {
president = {
name = "", --name of the elected candidate.
when = 0, --when the candidate was elected.
voters = { }, --names of voters who voted for this elected candidate.
},
},
candidates = {
president = { },
},
--]]
modEUrn.getPropCommPresident = function()
local now = os.time() --Em milisegundos
return {
privs = {server=true},
--params = "<".. modCorreio.translate("message")..">",
description = modEUrn.translate("Select the presidente of the server."),
func = function(playername, param)
local who = param
if modEUrn.handler.elected==nil then
modEUrn.handler.elected = { }
end
if modEUrn.handler.elected.president==nil then
modEUrn.handler.elected.president = { }
end
modEUrn.handler.elected.president.name = who
modEUrn.handler.elected.president.when = now
if modEUrn.handler.elected.president.voters==nil then
modEUrn.handler.elected.president.voters = { }
end
modEUrn.handler.elected.president.voters[playername] = now
if modEUrn.handler.candidates==nil then
modEUrn.handler.candidates = { }
end
if modEUrn.handler.candidates.president==nil then
modEUrn.handler.candidates.president = { }
end
modEUrn.handler.candidates.president[who] = now
minetest.chat_send_player(
playername,
--os.date("%Y-%m-%d %Hh:%Mm:%Ss", now) ..
"[E-URN] "..modEUrn.translate("Player '%s' has been named the president of this server!"):format(who)
)
end,
}
end
minetest.register_chatcommand(
"president",
modEUrn.getPropCommPresident()
)
minetest.register_chatcommand(
modEUrn.translate("president"),
modEUrn.getPropCommPresident()
)

View file

@ -1,8 +1,14 @@
modEUrn = {}
modEUrn.modname = minetest.get_current_modname()
modEUrn.modpath = minetest.get_modpath(modEUrn.modname)
modEUrn = {
modname = minetest.get_current_modname(),
modpath = minetest.get_modpath(minetest.get_current_modname()),
urlTabela = minetest.get_worldpath().."/e-urn.db", --Extensao '.tbl' ou '.db'
}
dofile(modEUrn.modpath.."/translate.lua") -- <== Antes de 'api.lua'!
dofile(modEUrn.modpath.."/api.lua")
dofile(modEUrn.modpath.."/commands.lua")
dofile(modEUrn.modpath.."/item_eurn.lua")
minetest.log('action',"["..modEUrn.modname:upper().."] Loaded!")
modEUrn.doLoad()
minetest.log('action',"["..modEUrn.modname:upper().."] Loaded!")

View file

@ -36,7 +36,16 @@ minetest.register_node("eurn:eurn", {
meta:set_string("infotext", modEUrn.translate("Electronic Urn"))
meta:set_string("owner",ownername)
end,
on_rightclick = function(pos, node, clicker)
local clickername = clicker:get_player_name()
local meta = minetest.get_meta(pos)
local ownername = meta:get_string("owner")
if ownername == clickername then
minetest.sound_play("sfx_eurn_button", {object=clicker, max_hear_distance=5.0,})
end
end,
--[[
on_rightclick = function(pos, node, clicker)
local clickername = clicker:get_player_name()
@ -112,3 +121,17 @@ minetest.register_node("eurn:eurn", {
end,
--]]
})
--[[
minetest.register_craft({
output = 'eurn:eurn',
recipe = {
{"default:steel_ingot" ,"default:steel_ingot" ,"default:steel_ingot"},
{"default:steel_ingot" ,"default:obsidian_glass" ,"default:steel_ingot"},
{"default:steel_ingot" ,"default:mese" ,"default:steel_ingot"},
}
})
--]]
minetest.register_alias("eurn", "eurn:eurn")

Binary file not shown.

View file

@ -1,15 +1,15 @@
# TRANSLATES
Update: 2023-03-19
version of Readme: 1.5
Update: 2023-07-20
version of Readme: 1.6
-----
To generate file [template.pot], did use terminal command:
```bash
cd soundchat
xgettext -n *.lua -L Lua --force-po --keyword=modSoundChat.translate --from-code=UTF-8 -o ./locale/template.pot
cd eurn
xgettext -n *.lua -L Lua --force-po --keyword=modEUrn.translate --from-code=UTF-8 -o ./locale/template.pot
```
-----
@ -67,12 +67,12 @@ sudo apt-get install poedit
### Convert '.po' file to '.tr' file.
Translate Sample: [locale/soundchat.pt_BR.tr]
Translate Sample: [locale/eurn.pt_BR.tr]
```bash
$ cd ./locale/
$ lua5.3 po2tr.lua "soundchat" "pt_BR.po"
$ mv "pt_BR.tr" "soundchat.pt_BR.tr"
$ cat soundchat.pt_BR.tr | less
$ lua5.3 po2tr.lua "eurn" "pt_BR.po"
$ mv "pt_BR.tr" "eurn.pt_BR.tr"
$ cat eurn.pt_BR.tr | less
```
-----
@ -80,7 +80,7 @@ $ cat soundchat.pt_BR.tr | less
### Exemple of enable the brazilian portuguese language in minetest:
Translate Sample: `locale/soundchat.pt_BR.tr`
Translate Sample: `locale/eurn.pt_BR.tr`
To enable the translate to brazilian portuguese language, write "language = pt_BR" in file "minetest.conf". Or write the command ```/set -n language pt_BR``` in game chat, and run again the minetest game.
@ -88,7 +88,7 @@ To enable the translate to brazilian portuguese language, write "language = pt_B
### PLEASE SUBMIT YOUR NEW TRANSLATION TO THE DEVELOPERS OF THIS MOD THROUGH THE GIT PROJECT BELOW:
* `https://gitlab.com/lunovox/soundchat`
* `https://gitlab.com/lunovox/eurn`
----
@ -98,8 +98,8 @@ To enable the translate to brazilian portuguese language, write "language = pt_B
* https://gist.githubusercontent.com/mamchenkov/3690981/raw/8ebd48c2af20c893c164e8d5245d9450ad682104/update_translations.sh
* https://gitlab.com/4w/xtend/-/blob/master/xtend_default/tools/convert_po_file_to_tr_file/convert_po_file_to_tr_file.lua
[locale/pt_BR.po]:https://gitlab.com/lunovox/soundchat/-/raw/master/locale/pt_BR.po
[locale/soundchat.pt_BR.tr]:https://gitlab.com/lunovox/soundchat/-/raw/master/locale/soundchat.pt_BR.tr
[locale/pt_BR.po]:https://gitlab.com/lunovox/eurn/-/raw/master/locale/pt_BR.po
[locale/eurn.pt_BR.tr]:https://gitlab.com/lunovox/eurn/-/raw/master/locale/eurn.pt_BR.tr
[PoEdit]:https://poedit.net
[template.pot]:https://gitlab.com/lunovox/soundchat/-/raw/master/locale/template.pot
[template.pot]:https://gitlab.com/lunovox/eurn/-/raw/master/locale/template.pot

4
locale/eurn.pt_BR.tr Normal file
View file

@ -0,0 +1,4 @@
# textdomain: eurn
E-URN=URNA ELETRÔNICA
Colect opinion of player with electronic urn.=Colete a opinião do jogador com uma Urna Eletrônica.
Electronic Urn=Urna Eletrônica

32
locale/pt_BR.po Normal file
View file

@ -0,0 +1,32 @@
# Portuguese translations for PACKAGE package
# Traduções em português brasileiro para o pacote PACKAGE.
# Copyright (C) 2023 THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# Automatically generated, 2023.
#
msgid ""
msgstr ""
"Project-Id-Version: pt_BR 1.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-20 19:44-0300\n"
"PO-Revision-Date: 2023-07-20 19:59-0300\n"
"Last-Translator: Lunovox Heavenfinder <lunovox@disroot.org>\n"
"Language-Team: Lunovox Heavenfinder\n"
"Language: pt_BR\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Poedit 3.3.1\n"
#: item_eurn.lua:9
msgid "E-URN"
msgstr "URNA ELETRÔNICA"
#: item_eurn.lua:10
msgid "Colect opinion of player with electronic urn."
msgstr "Colete a opinião do jogador com uma Urna Eletrônica."
#: item_eurn.lua:36
msgid "Electronic Urn"
msgstr "Urna Eletrônica"

30
locale/template.pot Normal file
View file

@ -0,0 +1,30 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-20 19:44-0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: item_eurn.lua:9
msgid "E-URN"
msgstr ""
#: item_eurn.lua:10
msgid "Colect opinion of player with electronic urn."
msgstr ""
#: item_eurn.lua:36
msgid "Electronic Urn"
msgstr ""

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
sounds/sfx_eurn_confirm.ogg Normal file

Binary file not shown.