From 7f4aac280beefecd836f458595588c065583449a Mon Sep 17 00:00:00 2001 From: Oversword Date: Sun, 8 Aug 2021 20:55:25 +0100 Subject: [PATCH 1/6] Fix indentation --- functions.lua | 200 +++++++++++++++++++++++++------------------------- 1 file changed, 101 insertions(+), 99 deletions(-) diff --git a/functions.lua b/functions.lua index 40a3bf2..615b22b 100644 --- a/functions.lua +++ b/functions.lua @@ -225,24 +225,24 @@ function tp.tpr_send(sender, receiver) if minetest.get_modpath("chat2") then chat2.send_message(minetest.get_player_by_name(sender), S("You are not allowed to send requests because you're muted."), 0xFFFFFF) end - return + return + end end - end if minetest.check_player_privs(sender, {tp_admin = true}) and tp.enable_immediate_teleport then if receiver == "" then minetest.chat_send_player(sender, S("Usage: /tpr ")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Usage: /tpr "), 0xFFFFFF) - end + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(sender), S("Usage: /tpr "), 0xFFFFFF) + end return end if not minetest.get_player_by_name(receiver) then minetest.chat_send_player(sender, 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(sender), S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online"), 0xFFFFFF) - end + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(sender), 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 @@ -255,57 +255,57 @@ function tp.tpr_send(sender, receiver) return end - if receiver == "" then - minetest.chat_send_player(sender, S("Usage: /tpr ")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Usage: /tpr "), 0xFFFFFF) - end - return + if receiver == "" then + minetest.chat_send_player(sender, S("Usage: /tpr ")) + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(sender), S("Usage: /tpr "), 0xFFFFFF) end + return + end - if not minetest.get_player_by_name(receiver) then - minetest.chat_send_player(sender, 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(sender), S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online"), 0xFFFFFF) - end - return + if not minetest.get_player_by_name(receiver) then + minetest.chat_send_player(sender, 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(sender), 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.get_modpath("gamehub") then -- Compatibility with gamehub (UNTESTED) - if gamehub.players[receiver] then - minetest.chat_send_player(sender, S("Teleport request denied, player is in the gamehub!")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request denied, player is in the gamehub!"), 0xFFFFFF) - end - return + if minetest.get_modpath("gamehub") then -- Compatibility with gamehub (UNTESTED) + if gamehub.players[receiver] then + minetest.chat_send_player(sender, S("Teleport request denied, player is in the gamehub!")) + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request denied, player is in the gamehub!"), 0xFFFFFF) end + return end + end - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(receiver), S("@1 is requesting to teleport to you. /tpy to accept.", sender), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay), 0xFFFFFF) - end + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(receiver), S("@1 is requesting to teleport to you. /tpy to accept.", sender), 0xFFFFFF) + chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay), 0xFFFFFF) + end - minetest.chat_send_player(receiver, S("@1 is requesting to teleport to you. /tpy to accept.", sender)) - minetest.chat_send_player(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) + minetest.chat_send_player(receiver, S("@1 is requesting to teleport to you. /tpy to accept.", sender)) + minetest.chat_send_player(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) - -- Write name values to list and clear old values. - tp.tpr_list[receiver] = sender - tp.tpn_list[sender] = receiver + -- Write name values to list and clear old values. + tp.tpr_list[receiver] = sender + tp.tpn_list[sender] = receiver - -- Teleport timeout delay - minetest.after(tp.timeout_delay, function(name) - if tp.tpr_list[name] and tp.tpn_list[sender] then - tp.tpr_list[name] = nil - tp.tpn_list[sender] = nil + -- Teleport timeout delay + minetest.after(tp.timeout_delay, function(name) + if tp.tpr_list[name] and tp.tpn_list[sender] then + tp.tpr_list[name] = nil + tp.tpn_list[sender] = nil - minetest.chat_send_player(sender, S("Request timed-out.")) - minetest.chat_send_player(receiver, S("Request timed-out.")) + minetest.chat_send_player(sender, S("Request timed-out.")) + minetest.chat_send_player(receiver, S("Request timed-out.")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Request timed-out."), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(receiver), S("Request timed-out."), 0xFFFFFF) - end + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(sender), S("Request timed-out."), 0xFFFFFF) + chat2.send_message(minetest.get_player_by_name(receiver), S("Request timed-out."), 0xFFFFFF) + end return end end, receiver) @@ -375,24 +375,24 @@ function tp.tphr_send(sender, receiver) if minetest.get_modpath("chat2") then chat2.send_message(minetest.get_player_by_name(sender), S("You are not allowed to send requests because you're muted."), 0xFFFFFF) end - return + return + end end - end if minetest.check_player_privs(sender, {tp_admin = true}) and tp.enable_immediate_teleport then if receiver == "" then minetest.chat_send_player(sender, S("Usage: /tphr ")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Usage. /tphr "), 0xFFFFFF) - end + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(sender), S("Usage. /tphr "), 0xFFFFFF) + end return end if not minetest.get_player_by_name(receiver) then minetest.chat_send_player(sender, 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(sender), S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online."), 0xFFFFFF) - end + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(sender), 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 @@ -405,52 +405,54 @@ function tp.tphr_send(sender, receiver) return end - if receiver == "" then - minetest.chat_send_player(sender, S("Usage: /tphr ")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Usage. /tphr "), 0xFFFFFF) - end - return + if receiver == "" then + minetest.chat_send_player(sender, S("Usage: /tphr ")) + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(sender), S("Usage. /tphr "), 0xFFFFFF) end + return + end - if not minetest.get_player_by_name(receiver) then - minetest.chat_send_player(sender, 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(sender), S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online."), 0xFFFFFF) - end - return + if not minetest.get_player_by_name(receiver) then + minetest.chat_send_player(sender, 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(sender), 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.get_modpath("gamehub") then -- Compatibility with gamehub (UNTESTED) - if gamehub.players[receiver] then - minetest.chat_send_player(sender, S("Teleport request denied, player is in the gamehub!")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request denied, player is in the gamehub!"), 0xFFFFFF) - end - return + if minetest.get_modpath("gamehub") then -- Compatibility with gamehub (UNTESTED) + if gamehub.players[receiver] then + minetest.chat_send_player(sender, S("Teleport request denied, player is in the gamehub!")) + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request denied, player is in the gamehub!"), 0xFFFFFF) end + return end + end - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(receiver), S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay), 0xFFFFFF) - end + - minetest.chat_send_player(receiver, S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender)) - minetest.chat_send_player(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(receiver), S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender), 0xFFFFFF) + chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay), 0xFFFFFF) + end - -- Write name values to list and clear old values. - tp.tphr_list[receiver] = sender - tp.tpn_list[sender] = receiver + minetest.chat_send_player(receiver, S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender)) + minetest.chat_send_player(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) - -- Teleport timeout delay - minetest.after(tp.timeout_delay, function(name) - if tp.tphr_list[name] and tp.tpn_list[sender] then - tp.tphr_list[name] = nil - tp.tpn_list[sender] = nil + -- Write name values to list and clear old values. + tp.tphr_list[receiver] = sender + tp.tpn_list[sender] = receiver - minetest.chat_send_player(sender, S("Request timed-out.")) - minetest.chat_send_player(receiver, S("Request timed-out.")) + -- Teleport timeout delay + minetest.after(tp.timeout_delay, function(name) + if tp.tphr_list[name] and tp.tpn_list[sender] then + tp.tphr_list[name] = nil + tp.tpn_list[sender] = nil + + minetest.chat_send_player(sender, S("Request timed-out.")) + minetest.chat_send_player(receiver, S("Request timed-out.")) if minetest.get_modpath("chat2") then chat2.send_message(minetest.get_player_by_name(sender), S("Request timed-out"), 0xFFFFFF) @@ -467,9 +469,9 @@ function tp.tpc_send(sender, coordinates) local pname = minetest.get_player_by_name(sender) if posx ~= nil or posy ~= nil or posz ~= nil then - posx = tonumber(posx) + 0.0 - posy = tonumber(posy) + 0.0 - posz = tonumber(posz) + 0.0 + posx = tonumber(posx) + 0.0 + posy = tonumber(posy) + 0.0 + posz = tonumber(posz) + 0.0 end if posx==nil or posy==nil or posz==nil or string.len(posx) > 6 or string.len(posy) > 6 or string.len(posz) > 6 then @@ -548,15 +550,15 @@ function tp.tpc_send(sender, coordinates) return end end, area.owner) - else - minetest.record_protection_violation(target_coords, sender) + else + minetest.record_protection_violation(target_coords, sender) end end - else - minetest.record_protection_violation(target_coords, sender) - end - return + else + minetest.record_protection_violation(target_coords, sender) end + return + end tp.tpc_teleport_player(sender) target_coords = nil From 3894f8c7baf85bd794b7c1f09d13750c075d4272 Mon Sep 17 00:00:00 2001 From: Oversword Date: Sun, 8 Aug 2021 20:58:04 +0100 Subject: [PATCH 2/6] Remove additions --- functions.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/functions.lua b/functions.lua index 615b22b..7f5c1a3 100644 --- a/functions.lua +++ b/functions.lua @@ -431,8 +431,6 @@ function tp.tphr_send(sender, receiver) end end - - if minetest.get_modpath("chat2") then chat2.send_message(minetest.get_player_by_name(receiver), S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender), 0xFFFFFF) chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay), 0xFFFFFF) From dfd22811ab097808cae6b4d6aa83529acd477055 Mon Sep 17 00:00:00 2001 From: Oversword Date: Sun, 8 Aug 2021 21:12:38 +0100 Subject: [PATCH 3/6] Fix minetest.after calls --- functions.lua | 75 ++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/functions.lua b/functions.lua index 7f5c1a3..1f2a802 100644 --- a/functions.lua +++ b/functions.lua @@ -189,15 +189,15 @@ function tp.tpr_send(sender, receiver) if spam_prevention[receiver] == sender and not minetest.check_player_privs(sender, {tp_admin = true}) then minetest.chat_send_player(sender, S("Wait @1 seconds before you can send teleport requests to @2 again.", tp.timeout_delay, receiver)) - minetest.after(tp.timeout_delay, function(name) - spam_prevention[name] = nil + minetest.after(tp.timeout_delay, function(sender_name, receiver_name) + spam_prevention[receiver_name] = nil if band == true then return end - if spam_prevention[receiver] == nil then - minetest.chat_send_player(sender, S("You can now send teleport requests to @1.", receiver)) + if spam_prevention[receiver_name] == nil then + minetest.chat_send_player(sender_name, S("You can now send teleport requests to @1.", receiver_name)) band = true end - end, receiver) + end, sender, receiver) else @@ -294,21 +294,21 @@ function tp.tpr_send(sender, receiver) tp.tpn_list[sender] = receiver -- Teleport timeout delay - minetest.after(tp.timeout_delay, function(name) - if tp.tpr_list[name] and tp.tpn_list[sender] then - tp.tpr_list[name] = nil - tp.tpn_list[sender] = nil + minetest.after(tp.timeout_delay, function(sender_name, receiver_name) + if tp.tpr_list[receiver_name] and tp.tpn_list[sender_name] then + tp.tpr_list[receiver_name] = nil + tp.tpn_list[sender_name] = nil - minetest.chat_send_player(sender, S("Request timed-out.")) - minetest.chat_send_player(receiver, S("Request timed-out.")) + minetest.chat_send_player(sender_name, S("Request timed-out.")) + minetest.chat_send_player(receiver_name, S("Request timed-out.")) if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Request timed-out."), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(receiver), S("Request timed-out."), 0xFFFFFF) + chat2.send_message(minetest.get_player_by_name(sender_name), S("Request timed-out."), 0xFFFFFF) + chat2.send_message(minetest.get_player_by_name(receiver_name), S("Request timed-out."), 0xFFFFFF) end return end - end, receiver) + end, sender, receiver) end end @@ -339,15 +339,15 @@ function tp.tphr_send(sender, receiver) if spam_prevention[receiver] == sender and not minetest.check_player_privs(sender, {tp_admin = true}) then minetest.chat_send_player(sender, S("Wait @1 seconds before you can send teleport requests to @2 again.", tp.timeout_delay, receiver)) - minetest.after(tp.timeout_delay, function(name) - spam_prevention[name] = nil + minetest.after(tp.timeout_delay, function(sender_name, receiver_name) + spam_prevention[receiver_name] = nil if band == true then return end - if spam_prevention[receiver] == nil then - minetest.chat_send_player(sender, S("You can now send teleport requests to @1.", receiver)) + if spam_prevention[receiver_name] == nil then + minetest.chat_send_player(sender_name, S("You can now send teleport requests to @1.", receiver_name)) band = true end - end, receiver) + end, sender, receiver) else @@ -444,21 +444,22 @@ function tp.tphr_send(sender, receiver) tp.tpn_list[sender] = receiver -- Teleport timeout delay - minetest.after(tp.timeout_delay, function(name) - if tp.tphr_list[name] and tp.tpn_list[sender] then - tp.tphr_list[name] = nil - tp.tpn_list[sender] = nil - minetest.chat_send_player(sender, S("Request timed-out.")) - minetest.chat_send_player(receiver, S("Request timed-out.")) + minetest.after(tp.timeout_delay, function(sender_name, receiver_name) + if tp.tphr_list[receiver_name] and tp.tpn_list[sender_name] then + tp.tphr_list[receiver_name] = nil + tp.tpn_list[sender_name] = nil + + minetest.chat_send_player(sender_name, S("Request timed-out.")) + minetest.chat_send_player(receiver_name, S("Request timed-out.")) if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Request timed-out"), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(receiver), S("Request timed-out"), 0xFFFFFF) + chat2.send_message(minetest.get_player_by_name(sender_name), S("Request timed-out"), 0xFFFFFF) + chat2.send_message(minetest.get_player_by_name(receiver_name), S("Request timed-out"), 0xFFFFFF) end return end - end, receiver) + end, sender, receiver) end end @@ -533,21 +534,21 @@ function tp.tpc_send(sender, coordinates) tp.tpc_list[area.owner] = sender tp.tpn_list[sender] = area.owner - minetest.after(tp.timeout_delay, function(name) - if tp.tpc_list[name] and tp.tpn_list[sender] then - tp.tpc_list[name] = nil - tp.tpn_list[sender] = nil + minetest.after(tp.timeout_delay, function(sender_name, receiver_name) + if tp.tpc_list[receiver_name] and tp.tpn_list[sender_name] then + tp.tpc_list[receiver_name] = nil + tp.tpn_list[sender_name] = nil - minetest.chat_send_player(sender, S("Request timed-out.")) - minetest.chat_send_player(area.owner, S("Request timed-out.")) + minetest.chat_send_player(sender_name, S("Request timed-out.")) + minetest.chat_send_player(receiver_name, S("Request timed-out.")) if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Request timed-out."), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(area.owner), S("Request timed-out."), 0xFFFFFF) + chat2.send_message(minetest.get_player_by_name(sender_name), S("Request timed-out."), 0xFFFFFF) + chat2.send_message(minetest.get_player_by_name(receiver_name), S("Request timed-out."), 0xFFFFFF) end return end - end, area.owner) + end, sender, area.owner) else minetest.record_protection_violation(target_coords, sender) end From a5a805aa90ded48d6701c9cec1ae9ed486ec3d8b Mon Sep 17 00:00:00 2001 From: Oversword Date: Sun, 8 Aug 2021 21:38:13 +0100 Subject: [PATCH 4/6] Remove chat message code duplication; Allow setting of chat color --- config.lua | 3 + functions.lua | 389 +++++++++++++---------------------------------- settingtypes.txt | 3 + 3 files changed, 114 insertions(+), 281 deletions(-) diff --git a/config.lua b/config.lua index bcfae82..df6108d 100644 --- a/config.lua +++ b/config.lua @@ -22,6 +22,9 @@ USA tp.timeout_delay = tonumber(minetest.settings:get("tp.timeout_delay")) or 60 tp.version = "1.5" +-- Message color +tp.message_color = minetest.settings:get("tp.message_color") or "#FFFFFF" + -- Enable teleporting immediately to the specified player for those with "tp_admin" privilege. tp.enable_immediate_teleport = minetest.settings:get_bool("tp.enable_immediate_teleport") diff --git a/functions.lua b/functions.lua index 1f2a802..624919b 100644 --- a/functions.lua +++ b/functions.lua @@ -30,6 +30,32 @@ local band = false local muted_players = {} +local message_color = tp.message_color + +local function color_string_to_number(color) + if string.sub(color,1,1) == '#' then + color = string.sub(color, 2) + end + if #color < 6 then + local r = string.sub(color,1,1) + local g = string.sub(color,2,2) + local b = string.sub(color,3,3) + color = r..r .. g..g .. b..b + elseif #color > 6 then + color = string.sub(color, 1, 6) + end + return tonumber(color, 16) +end + +local message_color_number = color_string_to_number(message_color) + +local function send_message(player, message) + minetest.chat_send_player(player, minetest.colorize(message_color, message)) + if minetest.get_modpath("chat2") then + chat2.send_message(minetest.get_player_by_name(player), message, message_color_number) + end +end + 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 @@ -105,96 +131,78 @@ 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 + send_message(player, S("Usage: /tpr_mute ")) 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 + send_message(player, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online.")) 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)) + send_message(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)) + send_message(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)) + send_message(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 + send_message(player, S("Usage: /tpr_unmute ")) 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 + send_message(player, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online.")) 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)) + send_message(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)) + send_message(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)) + send_message(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 - chat2.send_message(minetest.get_player_by_name(sender), S("Usage: /tpr "), 0xFFFFFF) - end + send_message(sender, S("Usage: /tpr ")) return end if not minetest.get_player_by_name(receiver) then - minetest.chat_send_player(sender, 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(sender), S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online"), 0xFFFFFF) - end + send_message(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online")) return end -- Spam prevention if spam_prevention[receiver] == sender and not minetest.check_player_privs(sender, {tp_admin = true}) then - minetest.chat_send_player(sender, S("Wait @1 seconds before you can send teleport requests to @2 again.", tp.timeout_delay, receiver)) + send_message(sender, S("Wait @1 seconds before you can send teleport requests to @2 again.", tp.timeout_delay, receiver)) minetest.after(tp.timeout_delay, function(sender_name, receiver_name) spam_prevention[receiver_name] = nil if band == true then return end if spam_prevention[receiver_name] == nil then - minetest.chat_send_player(sender_name, S("You can now send teleport requests to @1.", receiver_name)) + send_message(sender_name, S("You can now send teleport requests to @1.", receiver_name)) band = true end end, sender, receiver) @@ -204,90 +212,58 @@ function tp.tpr_send(sender, receiver) -- Compatibility with beerchat if minetest.get_modpath("beerchat") and not minetest.check_player_privs(sender, {tp_admin = true}) then if receiver == "" then - minetest.chat_send_player(sender, S("Usage: /tpr ")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Usage: /tpr "), 0xFFFFFF) - end + send_message(sender, S("Usage: /tpr ")) return end if not minetest.get_player_by_name(receiver) then - minetest.chat_send_player(sender, 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(sender), S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online"), 0xFFFFFF) - end + send_message(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online")) return end local player_receiver = minetest.get_player_by_name(receiver) if player_receiver:get_meta():get_string("beerchat:muted:" .. sender) == "true" then - minetest.chat_send_player(sender, S("You are not allowed to send requests because you're muted.")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("You are not allowed to send requests because you're muted."), 0xFFFFFF) - end + send_message(sender, S("You are not allowed to send requests because you're muted.")) return end end if minetest.check_player_privs(sender, {tp_admin = true}) and tp.enable_immediate_teleport then if receiver == "" then - minetest.chat_send_player(sender, S("Usage: /tpr ")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Usage: /tpr "), 0xFFFFFF) - end + send_message(sender, S("Usage: /tpr ")) return end if not minetest.get_player_by_name(receiver) then - minetest.chat_send_player(sender, 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(sender), S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online"), 0xFFFFFF) - end + send_message(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online")) return end tp.tpr_list[receiver] = sender tp.tpr_accept(receiver) - minetest.chat_send_player(sender, S("You are teleporting to @1.", receiver)) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("You are teleporting to @1.", receiver), 0xFFFFFF) - end + send_message(sender, S("You are teleporting to @1.", receiver)) return end if receiver == "" then - minetest.chat_send_player(sender, S("Usage: /tpr ")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Usage: /tpr "), 0xFFFFFF) - end + send_message(sender, S("Usage: /tpr ")) return end if not minetest.get_player_by_name(receiver) then - minetest.chat_send_player(sender, 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(sender), S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online"), 0xFFFFFF) - end + send_message(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online")) return end if minetest.get_modpath("gamehub") then -- Compatibility with gamehub (UNTESTED) if gamehub.players[receiver] then - minetest.chat_send_player(sender, S("Teleport request denied, player is in the gamehub!")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request denied, player is in the gamehub!"), 0xFFFFFF) - end + send_message(sender, S("Teleport request denied, player is in the gamehub!")) return end end - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(receiver), S("@1 is requesting to teleport to you. /tpy to accept.", sender), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay), 0xFFFFFF) - end - - minetest.chat_send_player(receiver, S("@1 is requesting to teleport to you. /tpy to accept.", sender)) - minetest.chat_send_player(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) + send_message(receiver, S("@1 is requesting to teleport to you. /tpy to accept.", sender)) + send_message(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) -- Write name values to list and clear old values. tp.tpr_list[receiver] = sender @@ -299,13 +275,8 @@ function tp.tpr_send(sender, receiver) tp.tpr_list[receiver_name] = nil tp.tpn_list[sender_name] = nil - minetest.chat_send_player(sender_name, S("Request timed-out.")) - minetest.chat_send_player(receiver_name, S("Request timed-out.")) - - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender_name), S("Request timed-out."), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(receiver_name), S("Request timed-out."), 0xFFFFFF) - end + send_message(sender_name, S("Request timed-out.")) + send_message(receiver_name, S("Request timed-out.")) return end end, sender, receiver) @@ -315,36 +286,30 @@ 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)) + send_message(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 - chat2.send_message(minetest.get_player_by_name(sender), S("Usage. /tphr "), 0xFFFFFF) - end + send_message(sender, S("Usage: /tphr ")) return end if not minetest.get_player_by_name(receiver) then - minetest.chat_send_player(sender, 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(sender), S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online."), 0xFFFFFF) - end + send_message(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online.")) return end -- Spam prevention if spam_prevention[receiver] == sender and not minetest.check_player_privs(sender, {tp_admin = true}) then - minetest.chat_send_player(sender, S("Wait @1 seconds before you can send teleport requests to @2 again.", tp.timeout_delay, receiver)) + send_message(sender, S("Wait @1 seconds before you can send teleport requests to @2 again.", tp.timeout_delay, receiver)) minetest.after(tp.timeout_delay, function(sender_name, receiver_name) spam_prevention[receiver_name] = nil if band == true then return end if spam_prevention[receiver_name] == nil then - minetest.chat_send_player(sender_name, S("You can now send teleport requests to @1.", receiver_name)) + send_message(sender_name, S("You can now send teleport requests to @1.", receiver_name)) band = true end end, sender, receiver) @@ -354,90 +319,58 @@ function tp.tphr_send(sender, receiver) -- Compatibility with beerchat if minetest.get_modpath("beerchat") and not minetest.check_player_privs(sender, {tp_admin = true}) then if receiver == "" then - minetest.chat_send_player(sender, S("Usage: /tphr ")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Usage. /tphr "), 0xFFFFFF) - end + send_message(sender, S("Usage: /tphr ")) return end if not minetest.get_player_by_name(receiver) then - minetest.chat_send_player(sender, 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(sender), S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online."), 0xFFFFFF) - end + send_message(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online.")) return end local player_receiver = minetest.get_player_by_name(receiver) if player_receiver:get_meta():get_string("beerchat:muted:" .. sender) == "true" then - minetest.chat_send_player(sender, S("You are not allowed to send requests because you're muted.")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("You are not allowed to send requests because you're muted."), 0xFFFFFF) - end + send_message(sender, S("You are not allowed to send requests because you're muted.")) return end end if minetest.check_player_privs(sender, {tp_admin = true}) and tp.enable_immediate_teleport then if receiver == "" then - minetest.chat_send_player(sender, S("Usage: /tphr ")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Usage. /tphr "), 0xFFFFFF) - end + send_message(sender, S("Usage: /tphr ")) return end if not minetest.get_player_by_name(receiver) then - minetest.chat_send_player(sender, 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(sender), S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online."), 0xFFFFFF) - end + send_message(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online.")) return end tp.tphr_list[receiver] = sender tp.tpr_accept(receiver) - minetest.chat_send_player(sender, S("@1 is teleporting to you.", receiver)) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("@1 is teleporting to you.", receiver), 0xFFFFFF) - end + send_message(sender, S("@1 is teleporting to you.", receiver)) return end if receiver == "" then - minetest.chat_send_player(sender, S("Usage: /tphr ")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Usage. /tphr "), 0xFFFFFF) - end + send_message(sender, S("Usage: /tphr ")) return end if not minetest.get_player_by_name(receiver) then - minetest.chat_send_player(sender, 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(sender), S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online."), 0xFFFFFF) - end + send_message(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online.")) return end if minetest.get_modpath("gamehub") then -- Compatibility with gamehub (UNTESTED) if gamehub.players[receiver] then - minetest.chat_send_player(sender, S("Teleport request denied, player is in the gamehub!")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request denied, player is in the gamehub!"), 0xFFFFFF) - end + send_message(sender, S("Teleport request denied, player is in the gamehub!")) return end end - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(receiver), S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(sender), S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay), 0xFFFFFF) - end - - minetest.chat_send_player(receiver, S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender)) - minetest.chat_send_player(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) + send_message(receiver, S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender)) + send_message(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) -- Write name values to list and clear old values. tp.tphr_list[receiver] = sender @@ -450,13 +383,8 @@ function tp.tphr_send(sender, receiver) tp.tphr_list[receiver_name] = nil tp.tpn_list[sender_name] = nil - minetest.chat_send_player(sender_name, S("Request timed-out.")) - minetest.chat_send_player(receiver_name, S("Request timed-out.")) - - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender_name), S("Request timed-out"), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(receiver_name), S("Request timed-out"), 0xFFFFFF) - end + send_message(sender_name, S("Request timed-out.")) + send_message(receiver_name, S("Request timed-out.")) return end end, sender, receiver) @@ -474,20 +402,14 @@ function tp.tpc_send(sender, coordinates) end if posx==nil or posy==nil or posz==nil or string.len(posx) > 6 or string.len(posy) > 6 or string.len(posz) > 6 then - minetest.chat_send_player(sender, S("Usage: /tpc ")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Usage: /tpc "), 0xFFFFFF) - end + send_message(sender, S("Usage: /tpc ")) return nil end target_coords = {x=posx, y=posy, z=posz} if tp.can_teleport(target_coords) == false then - minetest.chat_send_player(sender, S("You cannot teleport to a location outside the map!")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("You cannot teleport to a location outside the map!"), 0xFFFFFF) - end + send_message(sender, S("You cannot teleport to a location outside the map!")) return nil end @@ -496,10 +418,7 @@ function tp.tpc_send(sender, coordinates) if minetest.check_player_privs(pname, {tp_admin = true}) then tp.tpc_teleport_player(sender) target_coords = nil - minetest.chat_send_player(sender, S("Teleporting to: @1, @2, @3", posx, posy, posz)) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Teleporting to: @1, @2, @3", posx, posy, posz), 0xFFFFFF) - end + send_message(sender, S("Teleporting to: @1, @2, @3", posx, posy, posz)) else if minetest.check_player_privs(pname, {tp_tpc = true}) then local protected = minetest.is_protected(target_coords, sender) @@ -518,19 +437,11 @@ function tp.tpc_send(sender, coordinates) tpc_target_coords[area.owner] = {x=posx, y=posy, z=posz} end - minetest.chat_send_player(sender, S("Area request sent! Waiting for @1 to accept your request." .. + send_message(sender, S("Area request sent! Waiting for @1 to accept your request." .. " It will timeout in @2 seconds.", table.concat(areas:getNodeOwners(tpc_target_coords[area.owner]), S(", or ")), tp.timeout_delay)) - minetest.chat_send_player(area.owner, S("@1 is requesting to teleport to a protected area" .. + send_message(area.owner, S("@1 is requesting to teleport to a protected area" .. " of yours @2.", sender, minetest.pos_to_string(tpc_target_coords[area.owner]))) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Area request sent! Waiting for @1 to accept your request." .. - " It will timeout in @2 seconds.", table.concat(areas:getNodeOwners(tpc_target_coords[area.owner]), S(", or ")), tp.timeout_delay), 0xFFFFFF) - - chat2.send_message(minetest.get_player_by_name(area.owner), S("@1 is requesting to teleport to a protected area" .. - " of yours @2.", sender, minetest.pos_to_string(tpc_target_coords[area.owner])), 0xFFFFFF) - end - tp.tpc_list[area.owner] = sender tp.tpn_list[sender] = area.owner @@ -539,13 +450,8 @@ function tp.tpc_send(sender, coordinates) tp.tpc_list[receiver_name] = nil tp.tpn_list[sender_name] = nil - minetest.chat_send_player(sender_name, S("Request timed-out.")) - minetest.chat_send_player(receiver_name, S("Request timed-out.")) - - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender_name), S("Request timed-out."), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(receiver_name), S("Request timed-out."), 0xFFFFFF) - end + send_message(sender_name, S("Request timed-out.")) + send_message(receiver_name, S("Request timed-out.")) return end end, sender, area.owner) @@ -561,15 +467,9 @@ function tp.tpc_send(sender, coordinates) tp.tpc_teleport_player(sender) target_coords = nil - minetest.chat_send_player(sender, S("Teleporting to: @1, @2, @3", posx, posy, posz)) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Teleporting to: @1, @2, @3", posx, posy, posz), 0xFFFFFF) - end + send_message(sender, S("Teleporting to: @1, @2, @3", posx, posy, posz)) else - minetest.chat_send_player(sender, S("Error: You do not have permission to teleport to those coordinates.")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(sender), S("Error: You do not have permission to teleport to those coordinates."), 0xFFFFFF) - end + send_message(sender, S("Error: You do not have permission to teleport to those coordinates.")) return end end @@ -578,22 +478,15 @@ 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.")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name), S("Usage: /tpn allows you to deny teleport/area requests sent to you by other players."), 0xFFFFFF) - end + send_message(name, S("Usage: /tpn allows you to deny teleport/area requests sent to you by other players.")) return end -- Area requests if tp.tpc_list[name] then name2 = tp.tpc_list[name] - minetest.chat_send_player(name2, S("Area request denied.")) - minetest.chat_send_player(name, S("You denied the request @1 sent you.", name2)) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name2), S("Area request denied."), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(name), S("You denied the request @1 sent you.", name2), 0xFFFFFF) - end + send_message(name2, S("Area request denied.")) + send_message(name, S("You denied the request @1 sent you.", name2)) tp.tpc_list[name] = nil -- Don't allow re-denying requests. @@ -604,12 +497,8 @@ function tp.tpr_deny(name) -- Teleport requests if tp.tpr_list[name] then name2 = tp.tpr_list[name] - minetest.chat_send_player(name2, S("Teleport request denied.")) - minetest.chat_send_player(name, S("You denied the request @1 sent you.", name2)) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name2), S("Teleport request denied."), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(name), S("You denied the request @1 sent you.", name2), 0xFFFFFF) - end + send_message(name2, S("Teleport request denied.")) + send_message(name, S("You denied the request @1 sent you.", name2)) tp.tpr_list[name] = nil spam_prevention[name] = name2 @@ -619,12 +508,8 @@ function tp.tpr_deny(name) elseif tp.tphr_list[name] then name2 = tp.tphr_list[name] - minetest.chat_send_player(name2, S("Teleport request denied.")) - minetest.chat_send_player(name, S("You denied the request @1 sent you.", name2)) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name2), S("Teleport request denied."), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(name), S("You denied the request @1 sent you.", name2), 0xFFFFFF) - end + send_message(name2, S("Teleport request denied.")) + send_message(name, S("You denied the request @1 sent you.", name2)) tp.tphr_list[name] = nil spam_prevention[name] = name2 @@ -634,12 +519,8 @@ function tp.tpr_deny(name) elseif tp.tpn_list[name] then name2 = tp.tpn_list[name] - minetest.chat_send_player(name, S("You denied your request sent to @1.", name2)) - minetest.chat_send_player(name2, S("@1 denied their request sent to you.", name)) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name), S("You denied your request sent to @1.", name2), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(name2), S("@1 denied their request sent to you.", name), 0xFFFFFF) - end + send_message(name, S("You denied your request sent to @1.", name2)) + send_message(name2, S("@1 denied their request sent to you.", name)) if tp.tpr_list[name2] then tp.tpr_list[name2] = nil @@ -661,10 +542,7 @@ 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 - minetest.chat_send_player(name, S("Usage: /tpy allows you to accept teleport/area requests sent to you by other players.")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name), S("Usage: /tpy allows you to accept teleport/area requests sent to you by other players."), 0xFFFFFF) - end + send_message(name, S("Usage: /tpy allows you to accept teleport/area requests sent to you by other players.")) return end @@ -683,11 +561,8 @@ function tp.tpr_accept(name) -- If source or target are not present, abort request. if not source or not target then - minetest.chat_send_player(name, S("@1 is not online right now.", name2)) + send_message(name, S("@1 is not online right now.", name2)) tp.tpc_list[name] = nil - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name), S("@1 is not online right now.", name2), 0xFFFFFF) - end return end @@ -707,17 +582,11 @@ function tp.tpr_accept(name) tp.tpn_list[name2] = nil end - minetest.chat_send_player(name, chatmsg) - minetest.chat_send_player(name2, S("Request Accepted!")) + send_message(name, chatmsg) + send_message(name2, S("Request Accepted!")) -- Avoid abusing with area requests target_coords = nil - - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name2), S("Request Accepted!"), 0xFFFFFF) - chat2.send_message(minetest.get_player_by_name(name), chatmsg, 0xFFFFFF) - return - end end -- Teleport requests. @@ -741,12 +610,9 @@ function tp.tpr_accept(name) -- Could happen if either player disconnects (or timeout); if so just abort if not source or not target then - minetest.chat_send_player(name, S("@1 is not online right now.", name2)) + send_message(name, S("@1 is not online right now.", name2)) tp.tpr_list[name] = nil tp.tphr_list[name] = nil - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name), S("@1 is not online right now.", name2), 0xFFFFFF) - end return end @@ -761,24 +627,14 @@ function tp.tpr_accept(name) tp.tpn_list[name2] = nil end - minetest.chat_send_player(name, chatmsg) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name), chatmsg, 0xFFFFFF) - end + send_message(name, chatmsg) if minetest.check_player_privs(name2, {tp_admin = true}) == false then - minetest.chat_send_player(name2, S("Request Accepted!")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name2), S("Request Accepted!"), 0xFFFFFF) - end - + send_message(name2, S("Request Accepted!")) else if tp.enable_immediate_teleport then return end - minetest.chat_send_player(name2, S("Request Accepted!")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(name2), S("Request Accepted!"), 0xFFFFFF) - end + send_message(name2, S("Request Accepted!")) return end end @@ -786,26 +642,18 @@ 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 - chat2.send_message(minetest.get_player_by_name(player), S("Usage: "), 0xFFFFFF) - end + send_message(player, S("Usage: ")) return false end local args = param:split(" ") -- look into this. Can it crash if the player does not have two parameters? if #args < 2 then - minetest.chat_send_player(player, S("Usage: ")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("Usage: "), 0xFFFFFF) - end + send_message(player, S("Usage: ")) return false end if not tonumber(args[2]) then - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("Not a number!"), 0xFFFFFF) - end + send_message(player, S("Not a number!")) return false, S("Not a number!") end @@ -818,18 +666,12 @@ function tp.tpj(player, param) elseif args[1] == "z" then target_coords["z"] = target_coords["z"] + tonumber(args[2]) else - minetest.chat_send_player(player, S("Not a valid axis. Valid options are X, Y or Z")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("Not a valid axis. Valid options are X, Y or Z"), 0xFFFFFF) - end + send_message(player, S("Not a valid axis. Valid options are X, Y or Z")) return end if tp.can_teleport(target_coords) == false then - minetest.chat_send_player(player, S("You cannot teleport to a location outside the map!")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("You cannot teleport to a location outside the map!"), 0xFFFFFF) - end + send_message(player, S("You cannot teleport to a location outside the map!")) return end tp.tpc_teleport_player(player) @@ -840,10 +682,7 @@ end -- Evade function tp.tpe(player) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("EVADE!"), 0xFFFFFF) - end - minetest.chat_send_player(player, S("EVADE!")) + send_message(player, S("EVADE!")) local mindistance = 15 local maxdistance = 50 local times = math.random(6,20) -- how many times to jump - minimum,maximum @@ -876,20 +715,14 @@ if tp.enable_tpp_command then local places = {} if not tp.available_places then tp.available_places = {} end for key, value in pairs(tp.available_places) do - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), key, 0xFFFFFF) - end + send_message(player, key) table.insert(places, key) end if #places == 0 then - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("There are no places yet."), 0xFFFFFF) - end + send_message(player, S("There are no places yet.")) return true, S("There are no places yet.") end - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("Usage: /tpp "), 0xFFFFFF) - end + send_message(player, S("Usage: /tpp ")) table.insert(places, S("Usage: /tpp ")) return true, table.concat(places, "\n") @@ -897,17 +730,11 @@ if tp.enable_tpp_command then elseif tp.available_places[param] then local pos = {x = tp.available_places[param].x, y = tp.available_places[param].y, z = tp.available_places[param].z} tp.tpp_teleport_player(player, pos) - minetest.chat_send_player(player, S("Teleporting to @1.", param)) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("Teleporting to @1.", param), 0xFFFFFF) - end + send_message(player, S("Teleporting to @1.", param)) -- Check if the place exists. elseif not tp.available_places[param] then - minetest.chat_send_player(player, S("There is no place by that name. Keep in mind this is case-sensitive.")) - if minetest.get_modpath("chat2") then - chat2.send_message(minetest.get_player_by_name(player), S("There is no place by that name. Keep in mind this is case-sensitive."), 0xFFFFFF) - end + send_message(player, S("There is no place by that name. Keep in mind this is case-sensitive.")) return end end diff --git a/settingtypes.txt b/settingtypes.txt index f133649..4cbdd5d 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -1,6 +1,9 @@ # Timeout delay (default is 60) tp.timeout_delay (Timeout delay after a request is sent) int 60 +# Message color (default is #FFFFFF) +tp.message_color (The color of the messages sent to players by this mod) string #FFFFFF + # Enables immediate teleport to players for those who have tp_admin privilege (enabled by default) tp.enable_immediate_teleport (Immediate teleport for those with tp_admin privilege) bool true From 18cba12412f2dc6fbeb29615f2ba161c7c2c369d Mon Sep 17 00:00:00 2001 From: Oversword Date: Sun, 8 Aug 2021 22:01:18 +0100 Subject: [PATCH 5/6] No need to specify it's mod specific --- settingtypes.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settingtypes.txt b/settingtypes.txt index 4cbdd5d..754f505 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -2,7 +2,7 @@ tp.timeout_delay (Timeout delay after a request is sent) int 60 # Message color (default is #FFFFFF) -tp.message_color (The color of the messages sent to players by this mod) string #FFFFFF +tp.message_color (The color of the messages sent to players) string #FFFFFF # Enables immediate teleport to players for those who have tp_admin privilege (enabled by default) tp.enable_immediate_teleport (Immediate teleport for those with tp_admin privilege) bool true From 69c087bdddc1a575e3af8548a2f9b2d564fba08a Mon Sep 17 00:00:00 2001 From: Oversword Date: Sun, 8 Aug 2021 22:27:42 +0100 Subject: [PATCH 6/6] Do not allow multiple simultaneous requests to occur --- functions.lua | 92 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 78 insertions(+), 14 deletions(-) diff --git a/functions.lua b/functions.lua index 624919b..5d33c77 100644 --- a/functions.lua +++ b/functions.lua @@ -56,6 +56,10 @@ local function send_message(player, message) end end +local function pending_request(name) + return tp.tpr_list[name] or tp.tphr_list[name] or tp.tpc_list[name] +end + 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 @@ -262,6 +266,26 @@ function tp.tpr_send(sender, receiver) end end + local receiver_request = pending_request(receiver) + if receiver_request or tp.tpn_list[receiver] then + if receiver_request == sender then + send_message(sender, S("You have already sent a request to @1, wait for them to respond before sending another.", receiver)) + else + send_message(sender, S("@1 is dealing with another request right now, try again later.", receiver)) + end + return + end + + local sender_request = pending_request(sender) + if sender_request or tp.tpn_list[sender] then + if sender_request == receiver then + send_message(sender, S("@1 has already sent a request to you, cancel it with /tpn before sending a request to them.", receiver)) + else + send_message(sender, S("You are dealing with another request right now, cancel it with /tpn before sending another request.", receiver)) + end + return + end + send_message(receiver, S("@1 is requesting to teleport to you. /tpy to accept.", sender)) send_message(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) @@ -369,6 +393,26 @@ function tp.tphr_send(sender, receiver) end end + local receiver_request = pending_request(receiver) + if receiver_request or tp.tpn_list[receiver] then + if receiver_request == sender then + send_message(sender, S("You have already sent a request to @1, wait for them to respond before sending another.", receiver)) + else + send_message(sender, S("@1 is dealing with another request right now, try again later.", receiver)) + end + return + end + + local sender_request = pending_request(sender) + if sender_request or tp.tpn_list[sender] then + if sender_request == receiver then + send_message(sender, S("@1 has already sent a request to you, cancel it with /tpn before sending a request to them.", receiver)) + else + send_message(sender, S("You are dealing with another request right now, cancel it with /tpn before sending another request.", receiver)) + end + return + end + send_message(receiver, S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender)) send_message(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay)) @@ -425,25 +469,47 @@ function tp.tpc_send(sender, coordinates) if protected then if minetest.get_modpath("areas") then for _, area in pairs(areas:getAreasAtPos(target_coords)) do - if minetest.get_player_by_name(area.owner) then -- Check if area owners are online + local receiver = area.owner + + if minetest.get_player_by_name(receiver) then -- Check if area owners are online + + local receiver_request = pending_request(receiver) + if receiver_request or tp.tpn_list[receiver] then + if receiver_request == sender then + send_message(sender, S("You have already sent a request to @1, wait for them to respond before sending another.", receiver)) + else + send_message(sender, S("@1 is dealing with another request right now, try again later.", receiver)) + end + return + end + + local sender_request = pending_request(sender) + if sender_request or tp.tpn_list[sender] then + if sender_request == receiver then + send_message(sender, S("@1 has already sent a request to you, cancel it with /tpn before sending a request to them.", receiver)) + else + send_message(sender, S("You are dealing with another request right now, cancel it with /tpn before sending another request.", receiver)) + end + return + end if tpc_target_coords then old_tpc_target_coords = tpc_target_coords - old_tpc_target_coords[area.owner] = tpc_target_coords[area.owner] + old_tpc_target_coords[receiver] = tpc_target_coords[receiver] - tpc_target_coords[area.owner] = {x=posx, y=posy, z=posz} + tpc_target_coords[receiver] = {x=posx, y=posy, z=posz} else tpc_target_coords = {x=posx, y=posy, z=posz} - tpc_target_coords[area.owner] = {x=posx, y=posy, z=posz} + tpc_target_coords[receiver] = {x=posx, y=posy, z=posz} end send_message(sender, S("Area request sent! Waiting for @1 to accept your request." .. - " It will timeout in @2 seconds.", table.concat(areas:getNodeOwners(tpc_target_coords[area.owner]), S(", or ")), tp.timeout_delay)) - send_message(area.owner, S("@1 is requesting to teleport to a protected area" .. - " of yours @2.", sender, minetest.pos_to_string(tpc_target_coords[area.owner]))) + " It will timeout in @2 seconds.", table.concat(areas:getNodeOwners(tpc_target_coords[receiver]), S(", or ")), tp.timeout_delay)) + send_message(receiver, S("@1 is requesting to teleport to a protected area" .. + " of yours @2.", sender, minetest.pos_to_string(tpc_target_coords[receiver]))) - tp.tpc_list[area.owner] = sender - tp.tpn_list[sender] = area.owner + tp.tpc_list[receiver] = sender + tp.tpn_list[sender] = receiver minetest.after(tp.timeout_delay, function(sender_name, receiver_name) if tp.tpc_list[receiver_name] and tp.tpn_list[sender_name] then @@ -454,7 +520,7 @@ function tp.tpc_send(sender, coordinates) send_message(receiver_name, S("Request timed-out.")) return end - end, sender, area.owner) + end, sender, receiver) else minetest.record_protection_violation(target_coords, sender) end @@ -476,8 +542,7 @@ 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 + if not pending_request(name) and not tp.tpn_list[name] then send_message(name, S("Usage: /tpn allows you to deny teleport/area requests sent to you by other players.")) return end @@ -540,8 +605,7 @@ 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 + if not pending_request(name) then send_message(name, S("Usage: /tpy allows you to accept teleport/area requests sent to you by other players.")) return end