From bf9989beb91a01b3a4ffb4f4c0d917c1bd9554b1 Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Sun, 9 Apr 2023 19:51:55 +0200 Subject: [PATCH] add default message button --- mods/ITEMS/mcl_beds/functions.lua | 38 ++++++++++++++--------- mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr | 3 +- mods/ITEMS/mcl_beds/locale/template.txt | 3 +- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index ea77d9571..56e4a232b 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -211,8 +211,9 @@ local function update_formspecs(finished, ges) local button_abort = "button_exit[4,3;4,0.75;leave;"..F(S("Abort sleep")).."]" local bg_presleep = "bgcolor[#00000080;true]" local bg_sleep = "bgcolor[#000000FF;true]" - local chatbox = "field[1,4.5;9,1;chatmessage;"..F(S("Chat:"))..";]" - local chatsubmit = "button[10,3.75;1,2;chatsubmit;"..F(S("send!")).."]" + local chatbox = "field[0.2,4.5;9,1;chatmessage;"..F(S("Chat:"))..";]" + local chatsubmit = "button[9.2,3.75;1,2;chatsubmit;"..F(S("send!")).."]" + local defaultmessagebutton = "button[10.2,3.75;1,2;defaultmessage;zzZzzZ]" form_n = form_n .. chatbox .. chatsubmit --because these should be in the formspec in ANY case, they might as well be added here already @@ -241,6 +242,7 @@ local function update_formspecs(finished, ges) text = text .. "\n" .. comment form_n = form_n .. bg_presleep form_n = form_n .. button_leave + form_n = form_n .. defaultmessagebutton --Players should only be able to see that button when: -Skipping the night is possible -There aren't enoght players sleeping yet end form_n = form_n .. "label[0.5,1;"..F(text).."]" else @@ -429,7 +431,6 @@ minetest.register_on_leaveplayer(function(player) update_formspecs(false, #players) end) - local message_rate_limit = tonumber(minetest.settings:get("chat_message_limit_per_10sec")) or 8 --NEVER change this! if this was java, i would've declared it as final local playermessagecounter = {} --[[ @@ -446,16 +447,25 @@ minetest.register_globalstep(function(dtime) end end) -local function exceeded_rate_limit(playername) --Note: will also take care of increasing value +local function exceeded_rate_limit(playername) --Note: will also take care of increasing value and sending feedback message if needed if playermessagecounter[playername] == nil then playermessagecounter[playername] = 0 end if playermessagecounter[playername] >= message_rate_limit then -- == should do as well + minetest.chat_send_player(playername,S("You exceeded the maximum number of messages per 10 seconds!") .. " (" .. tostring(message_rate_limit) .. ")") return true end playermessagecounter[playername] = playermessagecounter[playername] + 1 return false -end +end + +local function shout_priv_check(player) + if not minetest.check_player_privs(player,"shout") then + minetest.chat_send_player(player:get_player_name(),S("You are missing the 'shout' privilege! It's required in order to talk in chat...")) + return false + end + return true +end minetest.register_on_player_receive_fields(function(player, formname, fields) if formname ~= "mcl_beds_form" then @@ -463,18 +473,18 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end if fields.chatsubmit and fields.chatmessage ~= "" then - if not minetest.check_player_privs(player,"shout") then - minetest.chat_send_player(player:get_player_name(),S("You are missing the 'shout' privilege! It's required in order to talk in chat...")) - return + if (not exceeded_rate_limit(player:get_player_name())) and shout_priv_check(player) then + minetest.chat_send_all(minetest.format_chat_message(player:get_player_name(), fields.chatmessage)) end + return + end - if exceeded_rate_limit(player:get_player_name()) then - minetest.chat_send_player(player:get_player_name(),S("You exceeded the maximum number of messages per 10 seconds!") .. " (" .. tostring(message_rate_limit) .. ")") - return + if fields.defaultmessage then + if (not exceeded_rate_limit(player:get_player_name())) and shout_priv_check(player) then + minetest.chat_send_all(minetest.format_chat_message(player:get_player_name(), S("Hey! Would you guys mind sleeping?"))) end - - minetest.chat_send_all(minetest.format_chat_message(player:get_player_name(), fields.chatmessage)) - end + return + end if fields.quit or fields.leave then lay_down(player, nil, nil, false) diff --git a/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr b/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr index e0d00f62a..ae035f3bb 100644 --- a/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr +++ b/mods/ITEMS/mcl_beds/locale/mcl_beds.de.tr @@ -44,4 +44,5 @@ Respawn Anchor=Seelenanker Chat:=Chat: send!=senden! You are missing the 'shout' privilege! It's required in order to talk in chat...=Ihnen fehlt das 'shout' Privileg! Es wird benötigt, um im Chat reden zu können... -You exceeded the maximum number of messages per 10 seconds!=Sie haben die maximale Anzahl an Chatnachrichten pro 10 Sekunden überschritten! \ No newline at end of file +You exceeded the maximum number of messages per 10 seconds!=Sie haben die maximale Anzahl an Chatnachrichten pro 10 Sekunden überschritten! +Hey! Would you guys mind sleeping?=Hey, würdet Ihr bitte zu Bett gehen? \ No newline at end of file diff --git a/mods/ITEMS/mcl_beds/locale/template.txt b/mods/ITEMS/mcl_beds/locale/template.txt index a3b635675..7d1f378c0 100644 --- a/mods/ITEMS/mcl_beds/locale/template.txt +++ b/mods/ITEMS/mcl_beds/locale/template.txt @@ -44,4 +44,5 @@ Respawn Anchor= Chat:= send!= You are missing the 'shout' privilege! It's required in order to talk in chat...= -You exceeded the maximum number of messages per 10 seconds!= \ No newline at end of file +You exceeded the maximum number of messages per 10 seconds!= +Hey! Would you guys mind sleeping? \ No newline at end of file