Skip to content

Commit

Permalink
Fix call on nil player error in /tpf (#58)
Browse files Browse the repository at this point in the history
Bug introduced in #55
  • Loading branch information
Panquesito7 authored Nov 12, 2023
1 parent cf6a550 commit ee4954b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
6 changes: 2 additions & 4 deletions commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ minetest.register_chatcommand("tpf", {
description = S("Show all teleport requests, made by you or to you, that are still active"),
privs = {interact = true, tp = true},
func = function(player)
local playername = minetest.get_player_by_name(player)

tp.tpf_update_time[playername] = true
tp.list_requests(playername)
tp.tpf_update_time[player] = true
tp.list_requests(player)
end
})

Expand Down
23 changes: 9 additions & 14 deletions functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ function tp.deny_request(id, own)
end
end

function tp.list_requests(player)
local playername = player:get_player_name()

function tp.list_requests(playername)
local sent_requests = tp.get_requests(playername, "sender")
local received_requests = tp.get_requests(playername, "receiver")
local area_requests = tp.get_requests(playername, "area")
Expand Down Expand Up @@ -284,14 +282,14 @@ function tp.list_requests(player)

local function update_time()
if formspec == "" or string.find(formspec, S("You have no requests.")) then
tp.tpf_update_time[player] = false
tp.tpf_update_time[playername] = false
return
end

if tp.tpf_update_time[player] then
if tp.tpf_update_time[playername] then
-- TODO: find a way to edit the text only and update
-- the formspec without re-calling the function.
tp.list_requests(player)
tp.list_requests(playername)
end
end

Expand Down Expand Up @@ -327,14 +325,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end

if changes and not fields.quit then
tp.tpf_update_time[player] = true
tp.list_requests(player)
tp.tpf_update_time[playername] = true
tp.list_requests(playername)
elseif fields.quit then
tp.tpf_update_time[player] = false
tp.tpf_update_time[playername] = false
end
end)


function tp.get_requests(playername, party)
local list
if party == "sender" then
Expand Down Expand Up @@ -519,9 +516,7 @@ function tp.tpr_send(sender, receiver)
band = true
end
end, sender, receiver)

else

-- Compatibility with beerchat
if minetest.get_modpath("beerchat") and not minetest.check_player_privs(sender, {tp_admin = true}) then
if receiver == "" then
Expand Down Expand Up @@ -622,9 +617,7 @@ function tp.tphr_send(sender, receiver)
band = true
end
end, sender, receiver)

else

-- Compatibility with beerchat
if minetest.get_modpath("beerchat") and not minetest.check_player_privs(sender, {tp_admin = true}) then
if receiver == "" then
Expand Down Expand Up @@ -787,6 +780,7 @@ function tp.tpr_deny(name)
if (tp.count_requests(name, "sender") + tp.count_requests(name, "receiver")) > 1 then
-- Show formspec for decision
tp.list_requests(name)
tp.tpf_update_time[name] = true
return
end

Expand Down Expand Up @@ -814,6 +808,7 @@ function tp.tpr_accept(name)
if tp.count_requests(name, "receiver") > 1 then
-- Show formspec for decision
tp.list_requests(name)
tp.tpf_update_time[name] = true
return
end

Expand Down

0 comments on commit ee4954b

Please sign in to comment.