Improves spawn choice if undefined (#1880)

* Improves spawn choice if undefined #1700

* Just a missing line <.<

* Moves the checks into the "default" case
This commit is contained in:
Hex3l 2019-08-07 01:01:55 +02:00 committed by Gabriele C
parent d87fa860e6
commit fadda43d13

View File

@ -180,6 +180,16 @@ public class SpawnLoader implements Reloadable {
switch (priority.toLowerCase().trim()) { switch (priority.toLowerCase().trim()) {
case "default": case "default":
if (world.getSpawnLocation() != null) { if (world.getSpawnLocation() != null) {
if (!isValidSpawnPoint(world.getSpawnLocation())) {
for (World spawnWorld : Bukkit.getWorlds()) {
if (isValidSpawnPoint(spawnWorld.getSpawnLocation())) {
world = spawnWorld;
break;
}
}
logger.warning("Seems like AuthMe is unable to find a proper spawn location. "
+ "Set a location with the command '/authme setspawn'");
}
spawnLoc = world.getSpawnLocation(); spawnLoc = world.getSpawnLocation();
} }
break; break;
@ -206,9 +216,24 @@ public class SpawnLoader implements Reloadable {
} }
} }
logger.debug("Fall back to default world spawn location. World: `{0}`", world.getName()); logger.debug("Fall back to default world spawn location. World: `{0}`", world.getName());
return world.getSpawnLocation(); // return default location return world.getSpawnLocation(); // return default location
} }
/**
* Checks if a given location is a valid spawn point [!= (0,0,0)].
*
* @param location The location to check
*
* @return True upon success, false otherwise
*/
private boolean isValidSpawnPoint(Location location) {
if (location.getX() == 0 && location.getY() == 0 && location.getZ() == 0) {
return false;
}
return true;
}
/** /**
* Save the location under the given prefix. * Save the location under the given prefix.
* *