[SPIGOT-6834] Don't require player to be sleeping to obtain bed location Created: 05/Dec/21  Updated: 05/Dec/21

Status: Reopened
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: Matthew McCune Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: spigot

Version: This server is running CraftBukkit version 3353-Spigot-dbf4938-f49e9d1 (MC: 1.18) (Implementing API version 1.18-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

Currently, the getBedLocation method on Player will throw an IllegalStateException if the player is not currently sleeping in a bed. This behavior seems strange to me because the bed location is accessible even when the player is not sleeping.

For example, the getBedSpawnLocation method will successfully return a spawn location based on the Player's bed location. 

The reason for this behavior is probably because a HumanEntity doesn't track a bed location, which means calling it on one that is not sleeping doesn't work. I think a better solution for this may be to return null if a HumanEntity isn't sleeping and to return the bed location if a Player isn't sleeping.



 Comments   
Comment by md_5 [ 05/Dec/21 ]

Your title says 'bed spawn location'.

Comment by Matthew McCune [ 05/Dec/21 ]

I did read the docs, I think the behavior of the API could be improved. getBedSpawnLocation returns the location where the player would spawn if they were to respawn at their bed, which is not necessarily the location of the bed, but a "valid" spawn location near the player's bed. Apologies if this wasn't clear in the original description.

Comment by md_5 [ 05/Dec/21 ]

Suggest you read the docs:

getBedLocation: 'Gets the location of the bed the player is currently sleeping in"

getBedSpawnLocation: 'Gets the Location where the player will spawn at their bed, null if they have not slept in one or their current bed spawn is invalid.'

The methods do different things, the second one returns the 'stored' location you mention.

Generated at Tue Apr 08 01:38:26 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.