Check if bed respawn location exists

This commit is contained in:
mathias 2019-06-16 04:31:07 +03:00
parent be2cc420a2
commit 6a7efad7b6

View file

@ -616,17 +616,21 @@ class Events implements Listener {
player.getLastDamageCause().getCause() != DamageCause.SUICIDE) { player.getLastDamageCause().getCause() != DamageCause.SUICIDE) {
Bukkit.getScheduler().scheduleSyncDelayedTask(main, new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(main, new Runnable() {
public void run() { public void run() {
World world = Bukkit.getWorld("world"); if (player.getBedSpawnLocation() != null) {
Location spawnLoc = world.getSpawnLocation(); player.teleport(player.getBedSpawnLocation());
} else {
World world = Bukkit.getWorld("world");
Location spawnLoc = world.getSpawnLocation();
for (double y = spawnLoc.getY(); y <= 256; y++) { for (double y = spawnLoc.getY(); y <= 256; y++) {
Location yLoc = new Location(world, spawnLoc.getX(), y, spawnLoc.getZ()); Location yLoc = new Location(world, spawnLoc.getX(), y, spawnLoc.getZ());
Block coordBlock = world.getBlockAt(yLoc); Block coordBlock = world.getBlockAt(yLoc);
if (coordBlock.getType().isTransparent() && if (coordBlock.getType().isTransparent() &&
coordBlock.getRelative(BlockFace.UP).getType().isTransparent()) { coordBlock.getRelative(BlockFace.UP).getType().isTransparent()) {
player.teleport(yLoc); player.teleport(yLoc);
break; break;
}
} }
} }
} }