Skip to content

Instantly share code, notes, and snippets.

@EdGruberman
Last active December 12, 2015 12:29
Show Gist options
  • Save EdGruberman/4771996 to your computer and use it in GitHub Desktop.
Save EdGruberman/4771996 to your computer and use it in GitHub Desktop.
// 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