Skip to content

Commit

Permalink
Async teleport
Browse files Browse the repository at this point in the history
  • Loading branch information
cavallium committed Mar 31, 2023
1 parent 756bcdd commit bdd2bb4
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void runCommand(Player player, List<String> arguments) {
if (spawnLoader.getFirstSpawn() == null) {
player.sendMessage("[AuthMe] First spawn has failed, please try to define the first spawn");
} else {
player.teleport(spawnLoader.getFirstSpawn());
player.teleportAsync(spawnLoader.getFirstSpawn());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void runCommand(Player player, List<String> arguments) {
if (spawnLoader.getSpawn() == null) {
player.sendMessage("[AuthMe] Spawn has failed, please try to define the spawn");
} else {
player.teleport(spawnLoader.getSpawn());
player.teleportAsync(spawnLoader.getSpawn());
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/fr/xephi/authme/listener/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,9 @@ public void onPlayerMove(PlayerMoveEvent event) {
Location spawn = spawnLoader.getSpawnLocation(player);
if (spawn != null && spawn.getWorld() != null) {
if (!player.getWorld().equals(spawn.getWorld())) {
player.teleport(spawn);
player.teleportAsync(spawn);
} else if (spawn.distance(player.getLocation()) > settings.getProperty(ALLOWED_MOVEMENT_RADIUS)) {
player.teleport(spawn);
player.teleportAsync(spawn);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void shouldTeleportToFirstSpawn() {
command.executeCommand(player, Collections.emptyList());

// then
verify(player).teleport(firstSpawn);
verify(player).teleportAsync(firstSpawn);
verify(spawnLoader, atLeastOnce()).getFirstSpawn();
}

Expand All @@ -58,6 +58,6 @@ public void shouldHandleMissingFirstSpawn() {

// then
verify(player).sendMessage(argThat(containsString("spawn has failed")));
verify(player, never()).teleport(any(Location.class));
verify(player, never()).teleportAsync(any(Location.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void shouldTeleportToSpawn() {
command.executeCommand(player, Collections.emptyList());

// then
verify(player).teleport(spawn);
verify(player).teleportAsync(spawn);
verify(spawnLoader, atLeastOnce()).getSpawn();
}

Expand All @@ -59,6 +59,6 @@ public void shouldHandleMissingSpawn() {

// then
verify(player).sendMessage(argThat(containsString("Spawn has failed")));
verify(player, never()).teleport(any(Location.class));
verify(player, never()).teleportAsync(any(Location.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ public void shouldTeleportPlayerInDifferentWorldToSpawn() {

// then
verify(listenerService).shouldCancelEvent(player);
verify(player).teleport(spawn);
verify(player).teleportAsync(spawn);
verify(spawnLoader).getSpawnLocation(player);
verifyNoModifyingCalls(event);
}
Expand Down Expand Up @@ -506,7 +506,7 @@ public void shouldAllowMovementWithinRadius() {

// then
verify(listenerService).shouldCancelEvent(player);
verify(player, never()).teleport(any(Location.class));
verify(player, never()).teleportAsync(any(Location.class));
verify(spawnLoader).getSpawnLocation(player);
verifyNoModifyingCalls(event);
}
Expand Down Expand Up @@ -534,7 +534,7 @@ public void shouldRejectMovementOutsideOfRadius() {

// then
verify(listenerService).shouldCancelEvent(player);
verify(player).teleport(spawn);
verify(player).teleportAsync(spawn);
verify(spawnLoader).getSpawnLocation(player);
verifyNoModifyingCalls(event);
}
Expand Down
26 changes: 13 additions & 13 deletions src/test/java/fr/xephi/authme/service/TeleportationServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void shouldTeleportPlayerToFirstSpawn() {
teleportationService.teleportNewPlayerToFirstSpawn(player);

// then
verify(player).teleport(firstSpawn);
verify(player).teleportAsync(firstSpawn);
verify(bukkitService).callEvent(any(FirstSpawnTeleportEvent.class));
verify(spawnLoader).getFirstSpawn();
verify(spawnLoader, never()).getSpawnLocation(any(Player.class));
Expand All @@ -115,7 +115,7 @@ public void shouldTeleportPlayerToSpawn() {
teleportationService.teleportOnJoin(player);

// then
verify(player).teleport(spawn);
verify(player).teleportAsync(spawn);
verify(bukkitService).callEvent(any(SpawnTeleportEvent.class));
verify(spawnLoader).getSpawnLocation(player);
}
Expand All @@ -131,7 +131,7 @@ public void shouldNotTeleportNewPlayer() {
teleportationService.teleportNewPlayerToFirstSpawn(player);

// then
verify(player, never()).teleport(any(Location.class));
verify(player, never()).teleportAsync(any(Location.class));
verify(spawnLoader).getFirstSpawn();
verify(spawnLoader, never()).getSpawnLocation(any(Player.class));
verifyNoInteractions(bukkitService);
Expand All @@ -147,7 +147,7 @@ public void shouldNotTeleportPlayerToFirstSpawnIfNoTeleportEnabled() {
teleportationService.teleportNewPlayerToFirstSpawn(player);

// then
verify(player, never()).teleport(any(Location.class));
verify(player, never()).teleportAsync(any(Location.class));
verifyNoInteractions(bukkitService);
}

Expand All @@ -161,7 +161,7 @@ public void shouldNotTeleportNotNewPlayerToFirstSpawn() {
teleportationService.teleportNewPlayerToFirstSpawn(player);

// then
verify(player, never()).teleport(any(Location.class));
verify(player, never()).teleportAsync(any(Location.class));
verifyNoInteractions(bukkitService);
}

Expand All @@ -185,7 +185,7 @@ public void shouldNotTeleportPlayerForRemovedLocationInEvent() {

// then
verify(bukkitService).callEvent(any(SpawnTeleportEvent.class));
verify(player, never()).teleport(any(Location.class));
verify(player, never()).teleportAsync(any(Location.class));
}

@Test
Expand All @@ -208,7 +208,7 @@ public void shouldNotTeleportPlayerForCanceledEvent() {

// then
verify(bukkitService).callEvent(any(SpawnTeleportEvent.class));
verify(player, never()).teleport(any(Location.class));
verify(player, never()).teleportAsync(any(Location.class));
}

// ---------
Expand Down Expand Up @@ -248,7 +248,7 @@ public void shouldTeleportPlayerToSpawnAfterLogin() {
teleportationService.teleportOnLogin(player, auth, limbo);

// then
verify(player).teleport(spawn);
verify(player).teleportAsync(spawn);
}

@Test
Expand All @@ -269,7 +269,7 @@ public void shouldNotTeleportToSpawnForOtherCaseInWorld() {
teleportationService.teleportOnLogin(player, auth, limbo);

// then
verify(player, never()).teleport(spawn);
verify(player, never()).teleportAsync(spawn);
verifyNoInteractions(bukkitService, spawnLoader);
}

Expand All @@ -296,7 +296,7 @@ public void shouldTeleportBackToPlayerAuthLocation() {

// then
ArgumentCaptor<Location> locationCaptor = ArgumentCaptor.forClass(Location.class);
verify(player).teleport(locationCaptor.capture());
verify(player).teleportAsync(locationCaptor.capture());
assertCorrectLocation(locationCaptor.getValue(), auth, world);
}

Expand Down Expand Up @@ -324,7 +324,7 @@ public void shouldTeleportAccordingToPlayerAuthAndPlayerWorldAsFallback() {

// then
ArgumentCaptor<Location> locationCaptor = ArgumentCaptor.forClass(Location.class);
verify(player).teleport(locationCaptor.capture());
verify(player).teleportAsync(locationCaptor.capture());
assertCorrectLocation(locationCaptor.getValue(), auth, world);
}

Expand All @@ -348,7 +348,7 @@ public void shouldTeleportWithLimboPlayerIfAuthYCoordIsNotSet() {
teleportationService.teleportOnLogin(player, auth, limbo);

// then
verify(player).teleport(location);
verify(player).teleportAsync(location);
verify(bukkitService, never()).getWorld(anyString());
}

Expand All @@ -370,7 +370,7 @@ public void shouldTeleportWithLimboPlayerIfSaveQuitLocIsDisabled() {
teleportationService.teleportOnLogin(player, auth, limbo);

// then
verify(player).teleport(location);
verify(player).teleportAsync(location);
}

@Test
Expand Down

0 comments on commit bdd2bb4

Please sign in to comment.