mirror of
https://github.com/minetest-mods/teleport-request.git
synced 2024-10-04 00:33:17 +02:00
Fix tp snipe simple (#48)
* Fix indentation * Remove additions * Fix minetest.after calls * Remove chat message code duplication; Allow setting of chat color * No need to specify it's mod specific * Do not allow multiple simultaneous requests to occur
This commit is contained in:
parent
7d21dd7123
commit
868101983a
@ -56,6 +56,10 @@ local function send_message(player, message)
|
|||||||
end
|
end
|
||||||
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
|
local map_size = 30912
|
||||||
function tp.can_teleport(to)
|
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
|
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
|
||||||
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(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))
|
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
|
||||||
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(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))
|
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 protected then
|
||||||
if minetest.get_modpath("areas") then
|
if minetest.get_modpath("areas") then
|
||||||
for _, area in pairs(areas:getAreasAtPos(target_coords)) do
|
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
|
if tpc_target_coords then
|
||||||
old_tpc_target_coords = tpc_target_coords
|
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
|
else
|
||||||
tpc_target_coords = {x=posx, y=posy, z=posz}
|
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
|
end
|
||||||
|
|
||||||
send_message(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))
|
" It will timeout in @2 seconds.", table.concat(areas:getNodeOwners(tpc_target_coords[receiver]), S(", or ")), tp.timeout_delay))
|
||||||
send_message(area.owner, S("@1 is requesting to teleport to a protected area" ..
|
send_message(receiver, S("@1 is requesting to teleport to a protected area" ..
|
||||||
" of yours @2.", sender, minetest.pos_to_string(tpc_target_coords[area.owner])))
|
" of yours @2.", sender, minetest.pos_to_string(tpc_target_coords[receiver])))
|
||||||
|
|
||||||
tp.tpc_list[area.owner] = sender
|
tp.tpc_list[receiver] = sender
|
||||||
tp.tpn_list[sender] = area.owner
|
tp.tpn_list[sender] = receiver
|
||||||
|
|
||||||
minetest.after(tp.timeout_delay, function(sender_name, receiver_name)
|
minetest.after(tp.timeout_delay, function(sender_name, receiver_name)
|
||||||
if tp.tpc_list[receiver_name] and tp.tpn_list[sender_name] then
|
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."))
|
send_message(receiver_name, S("Request timed-out."))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end, sender, area.owner)
|
end, sender, receiver)
|
||||||
else
|
else
|
||||||
minetest.record_protection_violation(target_coords, sender)
|
minetest.record_protection_violation(target_coords, sender)
|
||||||
end
|
end
|
||||||
@ -476,8 +542,7 @@ function tp.tpc_send(sender, coordinates)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function tp.tpr_deny(name)
|
function tp.tpr_deny(name)
|
||||||
if not tp.tpr_list[name] and not tp.tphr_list[name]
|
if not pending_request(name) and not tp.tpn_list[name] then
|
||||||
and not tp.tpc_list[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."))
|
send_message(name, S("Usage: /tpn allows you to deny teleport/area requests sent to you by other players."))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -540,8 +605,7 @@ end
|
|||||||
-- Teleport Accept Systems
|
-- Teleport Accept Systems
|
||||||
function tp.tpr_accept(name)
|
function tp.tpr_accept(name)
|
||||||
-- Check to prevent constant teleporting
|
-- Check to prevent constant teleporting
|
||||||
if not tp.tpr_list[name] and not tp.tphr_list[name]
|
if not pending_request(name) then
|
||||||
and not tp.tpc_list[name] then
|
|
||||||
send_message(name, S("Usage: /tpy allows you to accept teleport/area requests sent to you by other players."))
|
send_message(name, S("Usage: /tpy allows you to accept teleport/area requests sent to you by other players."))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user