Fix for NPE on safe teleport when location cannot be found.

This commit is contained in:
tastybento 2018-06-24 18:23:57 -07:00
parent eb855edfeb
commit ae1eeec7cf
1 changed files with 12 additions and 3 deletions

View File

@ -105,13 +105,22 @@ public class SafeSpotTeleport {
if (portal && bestSpot != null) {
// No portals found, teleport to the best spot we found
teleportEntity(bestSpot);
if (entity instanceof Player && ((Player)entity).getGameMode().equals(GameMode.SPECTATOR)) {
((Player)entity).setGameMode(plugin.getIWM().getDefaultGameMode(bestSpot.getWorld()));
}
} else if (entity instanceof Player && !failureMessage.isEmpty()) {
// Failed, no safe spot
entity.sendMessage(failureMessage);
if (entity instanceof Player && ((Player)entity).getGameMode().equals(GameMode.SPECTATOR)) {
if (plugin.getIWM().inWorld(entity.getLocation())) {
((Player)entity).setGameMode(plugin.getIWM().getDefaultGameMode(entity.getWorld()));
} else {
// Last resort
((Player)entity).setGameMode(GameMode.SURVIVAL);
}
}
}
if (entity instanceof Player && ((Player)entity).getGameMode().equals(GameMode.SPECTATOR)) {
((Player)entity).setGameMode(plugin.getIWM().getDefaultGameMode(bestSpot.getWorld()));
}
}
/**