From a902bfb79eb51aee9fee91bc5eefcd507f7314e3 Mon Sep 17 00:00:00 2001 From: David Leal Date: Sun, 18 Oct 2020 12:08:10 -0500 Subject: [PATCH] Allow muting other players' teleport requests (#40) * Allow muting players Allow muting other players' teleport requests. * Update translations --- commands.lua | 14 ++++++++ functions.lua | 79 +++++++++++++++++++++++++++++++++++++++++---- locale/es.po | 40 +++++++++++++++++++++++ locale/pt_BR.po | 36 +++++++++++++++++++++ locale/template.pot | 36 +++++++++++++++++++++ 5 files changed, 199 insertions(+), 6 deletions(-) diff --git a/commands.lua b/commands.lua index e222442..bd1998e 100644 --- a/commands.lua +++ b/commands.lua @@ -66,3 +66,17 @@ minetest.register_chatcommand("tpn", { privs = {interact = true, tp = true}, func = tp.tpr_deny }) + +minetest.register_chatcommand("tpr_mute", { + description = S("Mutes a player: denies them from sending you teleport requests"), + params = S(" | leave playername empty to see help message"), + privs = {interact = true, tp = true}, + func = tp.tpr_mute +}) + +minetest.register_chatcommand("tpr_unmute", { + description = S("Unmutes a player: allow them to send you teleport requests again"), + params = S(" | leave playername empty to see help message"), + privs = {interact = true, tp = true}, + func = tp.tpr_unmute +}) diff --git a/functions.lua b/functions.lua index 29aa432..838808d 100644 --- a/functions.lua +++ b/functions.lua @@ -28,6 +28,8 @@ target_coords, tpc_target_coords, old_tpc_target_coords local spam_prevention = {} local band = false +local muted_players = {} + local map_size = 30912 function tp.can_teleport(to) return to.x < map_size and to.x > -map_size and to.y < map_size and to.y > -map_size and to.z < map_size and to.z > -map_size @@ -100,8 +102,73 @@ function tp.parti2(pos) "tps_portal_parti.png") end +-- Mutes a player from sending you teleport requests +function tp.tpr_mute(player, muted_player) + if muted_player == "" then + minetest.chat_send_player(player, S("Usage: /tpr_mute ")) + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(player), S("Usage: /tpr_mute "), 0xFFFFFF) + end + return + end + + if not minetest.get_player_by_name(muted_player) then + minetest.chat_send_player(player, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online.")) + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(player), S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online."), 0xFFFFFF) + end + return + end + + if minetest.check_player_privs(muted_player, {tp_admin = true}) and not minetest.check_player_privs(player, {server = true}) then + minetest.chat_send_player(player, S("tpr_mute: Failed to mute player @1: they have the tp_admin privilege.", muted_player)) + return + end + + if muted_players[player] == muted_player then + minetest.chat_send_player(player, S("tpr_mute: Player @1 is already muted.", muted_player)) + return + end + + muted_players[player] = muted_player + minetest.chat_send_player(player, S("tpr_mute: Player @1 successfully muted.", muted_player)) +end + +-- Unmutes a player from sending you teleport requests +function tp.tpr_unmute(player, muted_player) + if muted_player == "" then + minetest.chat_send_player(player, S("Usage: /tpr_unmute ")) + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(player), S("Usage: /tpr_unmute "), 0xFFFFFF) + end + return + end + + if not minetest.get_player_by_name(muted_player) then + minetest.chat_send_player(player, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online.")) + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(player), S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online."), 0xFFFFFF) + end + return + end + + if muted_players[player] ~= muted_player then + minetest.chat_send_player(player, S("tpr_mute: Player @1 is not muted yet.", muted_player)) + return + end + + muted_players[player] = nil + minetest.chat_send_player(player, S("tpr_mute: Player @1 successfully unmuted.", muted_player)) +end + -- Teleport Request System function tp.tpr_send(sender, receiver) + -- Check if the sender is muted + if muted_players[receiver] == sender and not minetest.check_player_privs(sender, {server = true}) then + minetest.chat_send_player(sender, S("Cannot send request to @1 (you have been muted).", receiver)) + return + end + if receiver == "" then minetest.chat_send_player(sender, S("Usage: /tpr ")) if minetest.get_modpath("chat2") then @@ -246,6 +313,12 @@ function tp.tpr_send(sender, receiver) end function tp.tphr_send(sender, receiver) + -- Check if the sender is muted + if muted_players[receiver] == sender and not minetest.check_player_privs(sender, {server = true}) then + minetest.chat_send_player(sender, S("Cannot send request to @1 (you have been muted).", receiver)) + return + end + if receiver == "" then minetest.chat_send_player(sender, S("Usage: /tphr ")) if minetest.get_modpath("chat2") then @@ -390,7 +463,6 @@ function tp.tphr_send(sender, receiver) end function tp.tpc_send(sender, coordinates) - local posx,posy,posz = string.match(coordinates, "^(-?%d+), (-?%d+), (-?%d+)$") local pname = minetest.get_player_by_name(sender) @@ -503,7 +575,6 @@ function tp.tpc_send(sender, coordinates) end function tp.tpr_deny(name) - if not tp.tpr_list[name] and not tp.tphr_list[name] and not tp.tpc_list[name] and not tp.tpn_list[name] then minetest.chat_send_player(name, S("Usage: /tpn allows you to deny teleport/area requests sent to you by other players.")) @@ -586,7 +657,6 @@ end -- Teleport Accept Systems function tp.tpr_accept(name) - -- Check to prevent constant teleporting if not tp.tpr_list[name] and not tp.tphr_list[name] and not tp.tpc_list[name] then @@ -714,7 +784,6 @@ end -- Teleport Jump - Relative Position Teleportation by number of nodes function tp.tpj(player, param) - if param == "" then minetest.chat_send_player(player, S("Usage: ")) if minetest.get_modpath("chat2") then @@ -800,9 +869,7 @@ end -- Teleport To Place (TPP) system. if tp.enable_tpp_command then - function tp.tpp(player, param) - -- Show the available places to the player (taken from shivajiva101's POI mod, thanks!). if param == "" then local places = {} diff --git a/locale/es.po b/locale/es.po index f9fb08f..b9a4507 100644 --- a/locale/es.po +++ b/locale/es.po @@ -28,6 +28,14 @@ msgstr "Da acceso total de administrador a un jugador." msgid "Allow player to teleport to coordinates (if allowed by area protection)" msgstr "Permite a los jugadores teletransportarse a las coordenadas especificadas (si esta permitido por la protección de la área)" +#: init.lua +msgid "Usage: /tpr_mute " +msgstr "Uso: /tpr_mute " + +#: init.lua +msgid "tpr_mute: Failed to mute player @1: they have the tp_admin privilege." +msgstr "tpr_mute: No se pudo silenciar al jugador @1: tiene el privilegio tp_admin." + #: init.lua msgid "Wait @1 seconds before you can send teleport requests to @2 again." msgstr "Espere @1 segundos antes de que pueda mandar solicitudes de teletransporte a @2." @@ -40,6 +48,30 @@ msgstr "Ya puede mandar solicitudes de teletransporte a @1." msgid "You are not allowed to send requests because you're muted." msgstr "No tienes permiso para mandar solicitudes de teletransporte porque estás silenciado." +#: init.lua +msgid "Cannot send request to @1 (you have been muted)." +msgstr "No se puede enviar la solicitud a @1 (has sido silenciado)." + +#: init.lua +msgid "tpr_mute: Player @1 is already muted." +msgstr "tpr_mute: El jugador @1 ya esta silenciado." + +#: init.lua +msgid "tpr_mute: Player @1 successfully muted." +msgstr "tpr_mute: El jugador @1 ha sido silenciado con éxito." + +#: init.lua +msgid "Usage: /tpr_unmute " +msgstr "Uso: /tpr_unmute " + +#: init.lua +msgid "tpr_mute: Player @1 is not muted yet." +msgstr "tpr_mute: El jugador @1 aún no ha sido slienciado." + +#: init.lua +msgid "tpr_mute: Player @1 successfully unmuted." +msgstr "tpr_mute: El sonido del jugador @1 ha sido activado con éxito." + #: init.lua msgid "Usage: /tpr " msgstr "Uso: /tpr " @@ -227,6 +259,14 @@ msgstr "Aceptar solicitudes de otro jugador." msgid "Deny teleport requests from another player" msgstr "Denegar solicitudos de otro jugador." +#: init.lua +msgid "Mutes a player: denies them from sending you teleport requests" +msgstr "Silencia a un jugador: le niega el envío de solicitudes de teletransporte" + +#: init.lua +msgid "Unmutes a player: allow them to send you teleport requests again" +msgstr "Activar el sonido de un jugador: permite que te envíe solicitudes de teletransporte nuevamente" + #: init.lua msgid "[Teleport Request] TPS Teleport v@1 Loaded!" msgstr "[TPS] Solicitud de teletransporte v@1 Cargado!" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 7865686..1346233 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -28,10 +28,38 @@ msgstr "Da acesso de administrador completo a um jogador." msgid "Allow player to teleport to coordinates (if allowed by area protection)" msgstr "Permitir que o jogador se teletransporte para coordenadas (se permitido pela protecao da area)" +#: init.lua +msgid "tpr_mute: Failed to mute player @1: they have the tp_admin privilege." +msgstr "" + #: init.lua msgid "You are not allowed to send requests because you're muted." msgstr "Voce nao tem permissao para enviar solicitacoes porque esta' sem som." +#: init.lua +msgid "Cannot send request to @1 (you have been muted)." +msgstr "" + +#: init.lua +msgid "tpr_mute: Player @1 is already muted." +msgstr "" + +#: init.lua +msgid "tpr_mute: Player @1 successfully muted." +msgstr "" + +#: init.lua +msgid "Usage: /tpr_unmute " +msgstr "" + +#: init.lua +msgid "tpr_mute: Player @1 is not muted yet." +msgstr "" + +#: init.lua +msgid "tpr_mute: Player @1 successfully unmuted." +msgstr "" + #: init.lua msgid "Usage: /tpr " msgstr "Use: /tpr " @@ -204,6 +232,14 @@ msgstr "Aceitar pedidos de teleporte de outro jogador" msgid "Deny teleport requests from another player" msgstr "Negar pedidos de teleporte de outro jogador" +#: init.lua +msgid "Mutes a player: denies them from sending you teleport requests" +msgstr "" + +#: init.lua +msgid "Unmutes a player: allow them to send you teleport requests again" +msgstr "" + #: init.lua msgid "[Teleport Request] TPS Teleport v@1 Loaded!" msgstr "[Solicitacao de Teleporte] Teletransporte TPS v@1 Carregado!" diff --git a/locale/template.pot b/locale/template.pot index a899598..3f8d471 100644 --- a/locale/template.pot +++ b/locale/template.pot @@ -28,6 +28,10 @@ msgstr "" msgid "Allow player to teleport to coordinates (if allowed by area protection)" msgstr "" +#: init.lua +msgid "tpr_mute: Failed to mute player @1: they have the tp_admin privilege." +msgstr "" + #: init.lua msgid "Wait @1 seconds before you can send teleport requests to @2 again." msgstr "" @@ -40,6 +44,30 @@ msgstr "" msgid "You are not allowed to send requests because you're muted." msgstr "" +#: init.lua +msgid "Cannot send request to @1 (you have been muted)." +msgstr "" + +#: init.lua +msgid "tpr_mute: Player @1 is already muted." +msgstr "" + +#: init.lua +msgid "tpr_mute: Player @1 successfully muted." +msgstr "" + +#: init.lua +msgid "Usage: /tpr_unmute " +msgstr "" + +#: init.lua +msgid "tpr_mute: Player @1 is not muted yet." +msgstr "" + +#: init.lua +msgid "tpr_mute: Player @1 successfully unmuted." +msgstr "" + #: init.lua msgid "Usage: /tpr " msgstr "" @@ -227,6 +255,14 @@ msgstr "" msgid "Deny teleport requests from another player" msgstr "" +#: init.lua +msgid "Mutes a player: denies them from sending you teleport requests" +msgstr "" + +#: init.lua +msgid "Unmutes a player: allow them to send you teleport requests again" +msgstr "" + #: init.lua msgid "[Teleport Request] TPS Teleport v@1 Loaded!" msgstr ""