1717import org .bukkit .potion .PotionEffect ;
1818import org .mvplugins .multiverse .core .economy .MVEconomist ;
1919
20+ import javax .annotation .Nullable ;
2021import java .util .Arrays ;
2122import java .util .Collection ;
2223import java .util .HashMap ;
@@ -492,19 +493,7 @@ public void updateProfile(PlayerProfile profile, Player player) {
492493 Location bedSpawnLocation = null ;
493494 try {
494495 Logging .finer ("profile bed: " + player .getBedSpawnLocation ());
495- bedSpawnLocation = player .getBedSpawnLocation ();
496-
497- var blockBedSpawnLocation = bedSpawnLocation .getBlock ().getLocation ();
498- for (int x = -1 ; x <= 1 ; x ++) {
499- for (int z = -1 ; z <= 1 ; z ++) {
500- var newBedLoc = blockBedSpawnLocation .clone ().add (x , 0 , z );
501- Logging .finest ("new bed: " + newBedLoc );
502- if (newBedLoc .getBlock ().getBlockData () instanceof Bed ) {
503- bedSpawnLocation = newBedLoc ;
504- break ;
505- }
506- }
507- }
496+ bedSpawnLocation = findBedFromRespawnLocation (player .getBedSpawnLocation ());
508497 } catch (NullPointerException e ) {
509498 // TODO this is a temporary fix for the bug occurring in 1.16.X CB/Spigot/Paper
510499 StackTraceElement [] stackTrace = e .getStackTrace ();
@@ -527,12 +516,29 @@ public boolean updatePlayer(Player player, PlayerProfile profile) {
527516 return false ;
528517 }
529518 player .setBedSpawnLocation (loc , true );
530- Logging .finer ("update bed: " + player .getBedSpawnLocation ());
519+ Logging .finer ("updating bed: " + player .getBedSpawnLocation ());
531520 return true ;
532521 }
533522 }).serializer (new ProfileEntry (false , DataStrings .PLAYER_BED_SPAWN_LOCATION ), new LocationSerializer ())
534523 .altName ("bedspawn" ).altName ("bed" ).altName ("beds" ).altName ("bedspawns" ).build ();
535524
525+ private static @ Nullable Location findBedFromRespawnLocation (@ Nullable Location respawnLocation ) {
526+ if (respawnLocation == null ) {
527+ return null ;
528+ }
529+ var blockBedSpawnLocation = respawnLocation .getBlock ().getLocation ();
530+ for (int x = -1 ; x <= 1 ; x ++) {
531+ for (int z = -1 ; z <= 1 ; z ++) {
532+ var newBedLoc = blockBedSpawnLocation .clone ().add (x , 0 , z );
533+ Logging .finest ("Finding bed at: " + newBedLoc );
534+ if (newBedLoc .getBlock ().getBlockData () instanceof Bed ) {
535+ return newBedLoc ;
536+ }
537+ }
538+ }
539+ return respawnLocation ;
540+ }
541+
536542 /**
537543 * Sharing Last Location.
538544 */
0 commit comments