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) {
Bukkit.getScheduler().scheduleSyncDelayedTask(main, new Runnable() {
public void run() {
World world = Bukkit.getWorld("world");
Location spawnLoc = world.getSpawnLocation();
if (player.getBedSpawnLocation() != null) {
player.teleport(player.getBedSpawnLocation());
} else {
World world = Bukkit.getWorld("world");
Location spawnLoc = world.getSpawnLocation();
for (double y = spawnLoc.getY(); y <= 256; y++) {
Location yLoc = new Location(world, spawnLoc.getX(), y, spawnLoc.getZ());
Block coordBlock = world.getBlockAt(yLoc);
for (double y = spawnLoc.getY(); y <= 256; y++) {
Location yLoc = new Location(world, spawnLoc.getX(), y, spawnLoc.getZ());
Block coordBlock = world.getBlockAt(yLoc);
if (coordBlock.getType().isTransparent() &&
coordBlock.getRelative(BlockFace.UP).getType().isTransparent()) {
player.teleport(yLoc);
break;
if (coordBlock.getType().isTransparent() &&
coordBlock.getRelative(BlockFace.UP).getType().isTransparent()) {
player.teleport(yLoc);
break;
}
}
}
}