Last active
December 12, 2015 12:29
-
-
Save EdGruberman/4771996 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1: my preference | |
public Location getBedSpawnLocation() { | |
World world = getServer().getWorld(getHandle().spawnWorld); | |
if (world == null) return null; | |
ChunkCoordinates bed = getHandle().getBed(); | |
if (bed == null) return null; | |
if (world.getBlockTypeIdAt(bed.x, bed.y, bed.z) != Material.BED.getId()) return null; | |
return new Location(world, bed.x, bed.y, bed.z); | |
} | |
// 2: my preference modified to follow Bukkit conventions | |
public Location getBedSpawnLocation() { | |
World world = getServer().getWorld(getHandle().spawnWorld); | |
if (world == null) { | |
return null; | |
} | |
ChunkCoordinates bed = getHandle().getBed(); | |
if (bed == null) { | |
return null; | |
} | |
if (world.getBlockTypeIdAt(bed.x, bed.y, bed.z) != Material.BED.getId()) { | |
return null; | |
} | |
return new Location(world, bed.x, bed.y, bed.z); | |
} | |
// 3: minimal changes to existing | |
public Location getBedSpawnLocation() { | |
World world = getServer().getWorld(getHandle().spawnWorld); | |
ChunkCoordinates bed = getHandle().getBed(); | |
if (world != null && bed != null && world.getBlockTypeIdAt(bed.x, bed.y, bed.z) == Material.BED.getId()) { | |
return new Location(world, bed.x, bed.y, bed.z); | |
} | |
return null; | |
} | |
// 4: minimal changes to existing with type in local variable | |
public Location getBedSpawnLocation() { | |
World world = getServer().getWorld(getHandle().spawnWorld); | |
ChunkCoordinates bed = getHandle().getBed(); | |
if (world != null && bed != null) { | |
int type = world.getBlockTypeIdAt(bed.x, bed.y, bed.z) | |
if (type == Material.BED.getId()) { | |
return new Location(world, bed.x, bed.y, bed.z); | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment