Fix crash on exit of bed formspec if not sleeping (#2826)

This commit is contained in:
Lars Müller 2021-02-11 12:30:37 +01:00 committed by GitHub
parent 3d95fceee8
commit 624dafc12b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,18 +60,19 @@ local function lay_down(player, pos, bed_pos, state, skip)
-- stand up
if state ~= nil and not state then
local p = beds.pos[name] or nil
if not beds.player[name] then
-- player not in bed, do nothing
return false
end
beds.bed_position[name] = nil
-- skip here to prevent sending player specific changes (used for leaving players)
if skip then
return
end
if p then
player:set_pos(p)
end
player:set_pos(beds.pos[name])
-- physics, eye_offset, etc
local physics_override = assert(beds.player[name].physics_override)
local physics_override = beds.player[name].physics_override
beds.player[name] = nil
player:set_physics_override({
speed = physics_override.speed,
@ -101,6 +102,11 @@ local function lay_down(player, pos, bed_pos, state, skip)
return false
end
if beds.player[name] then
-- player already in bed, do nothing
return false
end
beds.pos[name] = pos
beds.bed_position[name] = bed_pos
beds.player[name] = {physics_override = player:get_physics_override()}