mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2025-06-28 06:12:00 +02:00
Add nil checks around get_player_by_name()
in case someone uses the commands from ncurses
This commit is contained in:
@ -174,7 +174,12 @@ end
|
||||
|
||||
-- Determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)
|
||||
function worldedit.player_axis(name)
|
||||
local dir = minetest.get_player_by_name(name):get_look_dir()
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then
|
||||
-- we promised to return something valid...
|
||||
return "y", -1
|
||||
end
|
||||
local dir = player:get_look_dir()
|
||||
local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z)
|
||||
if x > y then
|
||||
if x > z then
|
||||
|
@ -113,9 +113,9 @@ worldedit.register_command("pos1", {
|
||||
category = S("Region operations"),
|
||||
privs = {worldedit=true},
|
||||
func = function(name)
|
||||
local pos = minetest.get_player_by_name(name):get_pos()
|
||||
pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5)
|
||||
set_pos1(name, pos)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then return end
|
||||
set_pos1(name, vector.round(player:get_pos()))
|
||||
end,
|
||||
})
|
||||
|
||||
@ -125,9 +125,9 @@ worldedit.register_command("pos2", {
|
||||
category = S("Region operations"),
|
||||
privs = {worldedit=true},
|
||||
func = function(name)
|
||||
local pos = minetest.get_player_by_name(name):get_pos()
|
||||
pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5)
|
||||
set_pos2(name, pos)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then return end
|
||||
set_pos2(name, vector.round(player:get_pos()))
|
||||
end,
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user