Skip to content

Commit 7bef611

Browse files
committed
Add player is nil checks to worldedit_commands
1 parent b664d68 commit 7bef611

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

worldedit_commands/init.lua

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,12 @@ end
218218

219219
-- Determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)
220220
function worldedit.player_axis(name)
221-
local dir = minetest.get_player_by_name(name):get_look_dir()
221+
local player = minetest.get_player_by_name(name)
222+
if not player then
223+
return "", 0 -- bad behavior
224+
end
225+
226+
local dir = player:get_look_dir()
222227
local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z)
223228
if x > y then
224229
if x > z then
@@ -442,7 +447,9 @@ worldedit.register_command("pos1", {
442447
description = S("Set WorldEdit region position @1 to the player's location", 1),
443448
privs = {worldedit=true},
444449
func = function(name)
445-
local pos = minetest.get_player_by_name(name):get_pos()
450+
local player = minetest.get_player_by_name(name)
451+
if not player then return false end
452+
local pos = player:get_pos()
446453
pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5)
447454
worldedit.pos1[name] = pos
448455
worldedit.mark_pos1(name)
@@ -455,7 +462,9 @@ worldedit.register_command("pos2", {
455462
description = S("Set WorldEdit region position @1 to the player's location", 2),
456463
privs = {worldedit=true},
457464
func = function(name)
458-
local pos = minetest.get_player_by_name(name):get_pos()
465+
local player = minetest.get_player_by_name(name)
466+
if not player then return false end
467+
local pos = player:get_pos()
459468
pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5)
460469
worldedit.pos2[name] = pos
461470
worldedit.mark_pos2(name)

0 commit comments

Comments
 (0)