#856 Handle null Location on PlayerCache object
- Location may null when read from file
This commit is contained in:
parent
160cbc6aa4
commit
10392d0d65
@ -108,22 +108,26 @@ public class TeleportationService implements Reloadable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #856: If PlayerData comes from a persisted file, the Location might be null
|
||||||
|
String worldName = (limbo.getLocation() != null)
|
||||||
|
? limbo.getLocation().getWorld().getName()
|
||||||
|
: null;
|
||||||
|
|
||||||
// The world in PlayerData is from where the player comes, before any teleportation by AuthMe
|
// The world in PlayerData is from where the player comes, before any teleportation by AuthMe
|
||||||
String worldName = limbo.getLocation().getWorld().getName();
|
|
||||||
if (mustForceSpawnAfterLogin(worldName)) {
|
if (mustForceSpawnAfterLogin(worldName)) {
|
||||||
teleportToSpawn(player, true);
|
teleportToSpawn(player, true);
|
||||||
} else if (settings.getProperty(TELEPORT_UNAUTHED_TO_SPAWN)) {
|
} else if (settings.getProperty(TELEPORT_UNAUTHED_TO_SPAWN)) {
|
||||||
if (settings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION) && auth.getQuitLocY() != 0) {
|
if (settings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION) && auth.getQuitLocY() != 0) {
|
||||||
Location location = buildLocationFromAuth(player, auth);
|
Location location = buildLocationFromAuth(player, auth);
|
||||||
teleportBackFromSpawn(player, location);
|
teleportBackFromSpawn(player, location);
|
||||||
} else {
|
} else if (limbo.getLocation() != null) {
|
||||||
teleportBackFromSpawn(player, limbo.getLocation());
|
teleportBackFromSpawn(player, limbo.getLocation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean mustForceSpawnAfterLogin(String worldName) {
|
private boolean mustForceSpawnAfterLogin(String worldName) {
|
||||||
return settings.getProperty(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN)
|
return worldName != null && settings.getProperty(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN)
|
||||||
&& spawnOnLoginWorlds.contains(worldName);
|
&& spawnOnLoginWorlds.contains(worldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -32,6 +32,7 @@ import static org.mockito.Matchers.anyString;
|
|||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||||
|
|
||||||
@ -422,6 +423,25 @@ public class TeleportationServiceTest {
|
|||||||
verify(player).teleport(location);
|
verify(player).teleport(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldNotTeleportForNullLocationInLimboPlayer() {
|
||||||
|
// given
|
||||||
|
given(settings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)).willReturn(false);
|
||||||
|
given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(true);
|
||||||
|
given(settings.getProperty(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN)).willReturn(false);
|
||||||
|
|
||||||
|
PlayerAuth auth = PlayerAuth.builder().name("bobby").build();
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
PlayerData limbo = mock(PlayerData.class);
|
||||||
|
|
||||||
|
// when
|
||||||
|
teleportationService.teleportOnLogin(player, auth, limbo);
|
||||||
|
|
||||||
|
// then
|
||||||
|
verifyZeroInteractions(player);
|
||||||
|
verify(limbo, times(2)).getLocation();
|
||||||
|
}
|
||||||
|
|
||||||
private static void assertCorrectLocation(Location location, PlayerAuth auth, World world) {
|
private static void assertCorrectLocation(Location location, PlayerAuth auth, World world) {
|
||||||
assertThat(location.getX(), equalTo(auth.getQuitLocX()));
|
assertThat(location.getX(), equalTo(auth.getQuitLocX()));
|
||||||
assertThat(location.getY(), equalTo(auth.getQuitLocY()));
|
assertThat(location.getY(), equalTo(auth.getQuitLocY()));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user