#729 Use world from LimboPlayer for "spawn after login" feat., simplify teleport event constructors
This commit is contained in:
parent
3cdec91255
commit
5ef62784b5
@ -17,11 +17,10 @@ public class FirstSpawnTeleportEvent extends AbstractTeleportEvent {
|
||||
* Constructor.
|
||||
*
|
||||
* @param player The player
|
||||
* @param from The location the player is being teleported away from
|
||||
* @param to The teleport destination
|
||||
*/
|
||||
public FirstSpawnTeleportEvent(Player player, Location from, Location to) {
|
||||
super(true, player, from, to);
|
||||
public FirstSpawnTeleportEvent(Player player, Location to) {
|
||||
super(true, player, to);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -17,13 +17,11 @@ public class SpawnTeleportEvent extends AbstractTeleportEvent {
|
||||
* Constructor.
|
||||
*
|
||||
* @param player The player
|
||||
* @param from The location the player is being teleported away from
|
||||
* @param to The teleport destination
|
||||
* @param isAuthenticated Whether or not the player is logged in
|
||||
*/
|
||||
// TODO ljacqu 20160611: We only ever call this with from = player.getLocation() -> could be done in constructor
|
||||
public SpawnTeleportEvent(Player player, Location from, Location to, boolean isAuthenticated) {
|
||||
super(false, player, from, to);
|
||||
public SpawnTeleportEvent(Player player, Location to, boolean isAuthenticated) {
|
||||
super(false, player, to);
|
||||
this.isAuthenticated = isAuthenticated;
|
||||
}
|
||||
|
||||
|
||||
@ -62,7 +62,7 @@ public class TeleportationService implements Reloadable {
|
||||
return;
|
||||
}
|
||||
|
||||
if (settings.getProperty(TELEPORT_UNAUTHED_TO_SPAWN) || mustForceSpawnAfterLogin(player.getWorld())) {
|
||||
if (settings.getProperty(TELEPORT_UNAUTHED_TO_SPAWN) || mustForceSpawnAfterLogin(player.getWorld().getName())) {
|
||||
teleportToSpawn(player, playerCache.isAuthenticated(player.getName()));
|
||||
}
|
||||
}
|
||||
@ -72,7 +72,9 @@ public class TeleportationService implements Reloadable {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mustForceSpawnAfterLogin(player.getWorld())) {
|
||||
// The world in LimboPlayer is from where the player comes, before any teleportation by AuthMe
|
||||
String worldName = limbo.getLoc().getWorld().getName();
|
||||
if (mustForceSpawnAfterLogin(worldName)) {
|
||||
teleportToSpawn(player, true);
|
||||
} else if (settings.getProperty(TELEPORT_UNAUTHED_TO_SPAWN)) {
|
||||
if (settings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION) && auth.getQuitLocY() != 0) {
|
||||
@ -84,21 +86,9 @@ public class TeleportationService implements Reloadable {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean teleportToFirstSpawn(final Player player) {
|
||||
if (player.hasPlayedBefore()) {
|
||||
return false;
|
||||
}
|
||||
Location firstSpawn = spawnLoader.getFirstSpawn();
|
||||
if (firstSpawn == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
performTeleportation(player, new FirstSpawnTeleportEvent(player, player.getLocation(), firstSpawn));
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isEventValid(AbstractTeleportEvent event) {
|
||||
return !event.isCancelled() && event.getTo() != null && event.getTo().getWorld() != null;
|
||||
private boolean mustForceSpawnAfterLogin(String worldName) {
|
||||
return settings.getProperty(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN)
|
||||
&& spawnOnLoginWorlds.contains(worldName);
|
||||
}
|
||||
|
||||
private Location buildLocationFromAuth(Player player, PlayerAuth auth) {
|
||||
@ -109,13 +99,26 @@ public class TeleportationService implements Reloadable {
|
||||
return new Location(world, auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ());
|
||||
}
|
||||
|
||||
private boolean teleportToFirstSpawn(final Player player) {
|
||||
if (player.hasPlayedBefore()) {
|
||||
return false;
|
||||
}
|
||||
Location firstSpawn = spawnLoader.getFirstSpawn();
|
||||
if (firstSpawn == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
performTeleportation(player, new FirstSpawnTeleportEvent(player, firstSpawn));
|
||||
return true;
|
||||
}
|
||||
|
||||
private void teleportBackFromSpawn(final Player player, final Location location) {
|
||||
performTeleportation(player, new AuthMeTeleportEvent(player, location));
|
||||
}
|
||||
|
||||
private void teleportToSpawn(final Player player, final boolean isAuthenticated) {
|
||||
final Location spawnLoc = spawnLoader.getSpawnLocation(player);
|
||||
performTeleportation(player, new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, isAuthenticated));
|
||||
performTeleportation(player, new SpawnTeleportEvent(player, spawnLoc, isAuthenticated));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,8 +140,7 @@ public class TeleportationService implements Reloadable {
|
||||
});
|
||||
}
|
||||
|
||||
private boolean mustForceSpawnAfterLogin(World world) {
|
||||
return settings.getProperty(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN)
|
||||
&& spawnOnLoginWorlds.contains(world.getName());
|
||||
private static boolean isEventValid(AbstractTeleportEvent event) {
|
||||
return !event.isCancelled() && event.getTo() != null && event.getTo().getWorld() != null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,6 +133,7 @@ public class TeleportationServiceTest {
|
||||
Player player = mock(Player.class);
|
||||
given(player.hasPlayedBefore()).willReturn(false);
|
||||
given(player.isOnline()).willReturn(true);
|
||||
given(player.getWorld()).willReturn(mock(World.class));
|
||||
given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(false);
|
||||
given(settings.getProperty(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN)).willReturn(false);
|
||||
given(spawnLoader.getFirstSpawn()).willReturn(null);
|
||||
@ -250,15 +251,15 @@ public class TeleportationServiceTest {
|
||||
public void shouldTeleportPlayerToSpawnAfterLogin() {
|
||||
// given
|
||||
given(settings.getProperty(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN)).willReturn(true);
|
||||
World world = mock(World.class);
|
||||
given(world.getName()).willReturn("forced1");
|
||||
Player player = mock(Player.class);
|
||||
given(player.getWorld()).willReturn(world);
|
||||
given(player.isOnline()).willReturn(true);
|
||||
Location spawn = mockLocation();
|
||||
given(spawnLoader.getSpawnLocation(player)).willReturn(spawn);
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
LimboPlayer limbo = mock(LimboPlayer.class);
|
||||
Location limboLocation = mockLocation();
|
||||
given(limboLocation.getWorld().getName()).willReturn("forced1");
|
||||
given(limbo.getLoc()).willReturn(limboLocation);
|
||||
|
||||
// when
|
||||
teleportationService.teleportOnLogin(player, auth, limbo);
|
||||
@ -274,15 +275,15 @@ public class TeleportationServiceTest {
|
||||
// given
|
||||
given(settings.getProperty(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN)).willReturn(true);
|
||||
given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(false);
|
||||
World world = mock(World.class);
|
||||
given(world.getName()).willReturn("Forced1"); // different case
|
||||
Player player = mock(Player.class);
|
||||
given(player.getWorld()).willReturn(world);
|
||||
given(player.isOnline()).willReturn(true);
|
||||
Location spawn = mockLocation();
|
||||
given(spawnLoader.getSpawnLocation(player)).willReturn(spawn);
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
LimboPlayer limbo = mock(LimboPlayer.class);
|
||||
Location limboLocation = mockLocation();
|
||||
given(limboLocation.getWorld().getName()).willReturn("Forced1"); // different case
|
||||
given(limbo.getLoc()).willReturn(limboLocation);
|
||||
|
||||
// when
|
||||
teleportationService.teleportOnLogin(player, auth, limbo);
|
||||
@ -307,6 +308,8 @@ public class TeleportationServiceTest {
|
||||
Player player = mock(Player.class);
|
||||
given(player.isOnline()).willReturn(true);
|
||||
LimboPlayer limbo = mock(LimboPlayer.class);
|
||||
Location limboLocation = mockLocation();
|
||||
given(limbo.getLoc()).willReturn(limboLocation);
|
||||
|
||||
// when
|
||||
teleportationService.teleportOnLogin(player, auth, limbo);
|
||||
@ -334,6 +337,8 @@ public class TeleportationServiceTest {
|
||||
World world = mock(World.class);
|
||||
given(player.getWorld()).willReturn(world);
|
||||
LimboPlayer limbo = mock(LimboPlayer.class);
|
||||
Location limboLocation = mockLocation();
|
||||
given(limbo.getLoc()).willReturn(limboLocation);
|
||||
|
||||
// when
|
||||
teleportationService.teleportOnLogin(player, auth, limbo);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user