mirror of
https://github.com/minetest-mods/teleport-request.git
synced 2024-08-20 21:34:06 +02:00
Minimize unnecessary closures
A closure is previously created and allocated every time tpr_send or tphr_send is called. Instead, we define the function once and reuse it.
This commit is contained in:
parent
5d56e134d2
commit
d7ef3bf706
36
init.lua
36
init.lua
@ -77,16 +77,24 @@ local function parti2(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Teleport Request System
|
-- Teleport Request System
|
||||||
|
function clear_tpr_list(name)
|
||||||
|
if tpr_list[name] then
|
||||||
|
tpr_list[name] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function clear_tphr_list(name)
|
||||||
|
if tphr_list[name] then
|
||||||
|
tphr_list[name] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function tpr_send(sender, receiver)
|
function tpr_send(sender, receiver)
|
||||||
if minetest.check_player_privs(sender, {tp_admin = true}) then
|
if minetest.check_player_privs(sender, {tp_admin = true}) then
|
||||||
-- Write name values to list and clear old values.
|
-- Write name values to list and clear old values.
|
||||||
tpr_list[receiver] = sender
|
tpr_list[receiver] = sender
|
||||||
-- Teleport timeout delay
|
-- Teleport timeout delay
|
||||||
minetest.after(timeout_delay, function(name)
|
minetest.after(timeout_delay, clear_tpr_list, receiver)
|
||||||
if tpr_list[name] then
|
|
||||||
tpr_list[name] = nil
|
|
||||||
end
|
|
||||||
end, receiver)
|
|
||||||
if receiver == "" then
|
if receiver == "" then
|
||||||
minetest.chat_send_player(sender, S("Usage: /tpr <Player name>"))
|
minetest.chat_send_player(sender, S("Usage: /tpr <Player name>"))
|
||||||
return
|
return
|
||||||
@ -117,11 +125,7 @@ function tpr_send(sender, receiver)
|
|||||||
if not minetest.check_player_privs(sender, {tp_admin = true}) then
|
if not minetest.check_player_privs(sender, {tp_admin = true}) then
|
||||||
tpr_list[receiver] = sender
|
tpr_list[receiver] = sender
|
||||||
-- Teleport timeout delay
|
-- Teleport timeout delay
|
||||||
minetest.after(timeout_delay, function(name)
|
minetest.after(timeout_delay, clear_tpr_list, receiver)
|
||||||
if tpr_list[name] then
|
|
||||||
tpr_list[name] = nil
|
|
||||||
end
|
|
||||||
end, receiver)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -130,11 +134,7 @@ function tphr_send(sender, receiver)
|
|||||||
-- Write name values to list and clear old values.
|
-- Write name values to list and clear old values.
|
||||||
tphr_list[receiver] = sender
|
tphr_list[receiver] = sender
|
||||||
-- Teleport timeout delay
|
-- Teleport timeout delay
|
||||||
minetest.after(timeout_delay, function(name)
|
minetest.after(timeout_delay, clear_tphr_list, receiver)
|
||||||
if tphr_list[name] then
|
|
||||||
tphr_list[name] = nil
|
|
||||||
end
|
|
||||||
end, receiver)
|
|
||||||
if receiver == "" then
|
if receiver == "" then
|
||||||
minetest.chat_send_player(sender, S("Usage: /tphr <Player name>"))
|
minetest.chat_send_player(sender, S("Usage: /tphr <Player name>"))
|
||||||
return
|
return
|
||||||
@ -164,11 +164,7 @@ function tphr_send(sender, receiver)
|
|||||||
if not minetest.check_player_privs(sender, {tp_admin = true}) then
|
if not minetest.check_player_privs(sender, {tp_admin = true}) then
|
||||||
tphr_list[receiver] = sender
|
tphr_list[receiver] = sender
|
||||||
-- Teleport timeout delay
|
-- Teleport timeout delay
|
||||||
minetest.after(timeout_delay, function(name)
|
minetest.after(timeout_delay, clear_tphr_list, receiver)
|
||||||
if tphr_list[name] then
|
|
||||||
tphr_list[name] = nil
|
|
||||||
end
|
|
||||||
end, receiver)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user