Teleportation needs to be scheduled in sync

- Revert removal of sync scheduled task for teleportation
- Add back listener properties from 5d6f3e1 since they don't interfere
This commit is contained in:
ljacqu 2016-08-04 19:08:05 +02:00
parent 306160e675
commit 8002ef45fd
3 changed files with 21 additions and 6 deletions

View File

@ -193,7 +193,7 @@ public class PlayerListener implements Listener {
} }
} }
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
teleportationService.teleportNewPlayerToFirstSpawn(player); teleportationService.teleportNewPlayerToFirstSpawn(player);
@ -206,7 +206,7 @@ public class PlayerListener implements Listener {
// event caused by "logged in from another location". The nicer way, but only for Spigot, would be // event caused by "logged in from another location". The nicer way, but only for Spigot, would be
// to check in the AsyncPlayerPreLoginEvent. To support all servers, we use the less nice way. // to check in the AsyncPlayerPreLoginEvent. To support all servers, we use the less nice way.
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.LOW)
public void onPlayerLogin(PlayerLoginEvent event) { public void onPlayerLogin(PlayerLoginEvent event) {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final String name = player.getName(); final String name = player.getName();

View File

@ -158,10 +158,15 @@ public class TeleportationService implements Reloadable {
* @param event the event to emit and according to which to teleport * @param event the event to emit and according to which to teleport
*/ */
private void performTeleportation(final Player player, final AbstractTeleportEvent event) { private void performTeleportation(final Player player, final AbstractTeleportEvent event) {
bukkitService.callEvent(event); bukkitService.scheduleSyncDelayedTask(new Runnable() {
if (player.isOnline() && isEventValid(event)) { @Override
player.teleport(event.getTo()); public void run() {
} bukkitService.callEvent(event);
if (player.isOnline() && isEventValid(event)) {
player.teleport(event.getTo());
}
}
});
} }
private static boolean isEventValid(AbstractTeleportEvent event) { private static boolean isEventValid(AbstractTeleportEvent event) {

View File

@ -23,6 +23,7 @@ import org.mockito.stubbing.Answer;
import java.util.Arrays; import java.util.Arrays;
import static fr.xephi.authme.TestHelper.runSyncDelayedTask;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
@ -93,6 +94,7 @@ public class TeleportationServiceTest {
// when // when
teleportationService.teleportNewPlayerToFirstSpawn(player); teleportationService.teleportNewPlayerToFirstSpawn(player);
runSyncDelayedTask(bukkitService);
// then // then
verify(player).teleport(firstSpawn); verify(player).teleport(firstSpawn);
@ -112,6 +114,7 @@ public class TeleportationServiceTest {
// when // when
teleportationService.teleportOnJoin(player); teleportationService.teleportOnJoin(player);
runSyncDelayedTask(bukkitService);
// then // then
verify(player).teleport(spawn); verify(player).teleport(spawn);
@ -190,6 +193,7 @@ public class TeleportationServiceTest {
// when // when
teleportationService.teleportOnJoin(player); teleportationService.teleportOnJoin(player);
runSyncDelayedTask(bukkitService);
// then // then
verify(bukkitService).callEvent(any(SpawnTeleportEvent.class)); verify(bukkitService).callEvent(any(SpawnTeleportEvent.class));
@ -215,6 +219,7 @@ public class TeleportationServiceTest {
// when // when
teleportationService.teleportOnJoin(player); teleportationService.teleportOnJoin(player);
runSyncDelayedTask(bukkitService);
// then // then
verify(bukkitService).callEvent(any(SpawnTeleportEvent.class)); verify(bukkitService).callEvent(any(SpawnTeleportEvent.class));
@ -255,6 +260,7 @@ public class TeleportationServiceTest {
// when // when
teleportationService.teleportOnLogin(player, auth, limbo); teleportationService.teleportOnLogin(player, auth, limbo);
runSyncDelayedTask(bukkitService);
// then // then
verify(player).teleport(spawn); verify(player).teleport(spawn);
@ -304,6 +310,7 @@ public class TeleportationServiceTest {
// when // when
teleportationService.teleportOnLogin(player, auth, limbo); teleportationService.teleportOnLogin(player, auth, limbo);
runSyncDelayedTask(bukkitService);
// then // then
ArgumentCaptor<Location> locationCaptor = ArgumentCaptor.forClass(Location.class); ArgumentCaptor<Location> locationCaptor = ArgumentCaptor.forClass(Location.class);
@ -332,6 +339,7 @@ public class TeleportationServiceTest {
// when // when
teleportationService.teleportOnLogin(player, auth, limbo); teleportationService.teleportOnLogin(player, auth, limbo);
runSyncDelayedTask(bukkitService);
// then // then
ArgumentCaptor<Location> locationCaptor = ArgumentCaptor.forClass(Location.class); ArgumentCaptor<Location> locationCaptor = ArgumentCaptor.forClass(Location.class);
@ -359,6 +367,7 @@ public class TeleportationServiceTest {
// when // when
teleportationService.teleportOnLogin(player, auth, limbo); teleportationService.teleportOnLogin(player, auth, limbo);
runSyncDelayedTask(bukkitService);
// then // then
verify(player).teleport(location); verify(player).teleport(location);
@ -383,6 +392,7 @@ public class TeleportationServiceTest {
// when // when
teleportationService.teleportOnLogin(player, auth, limbo); teleportationService.teleportOnLogin(player, auth, limbo);
runSyncDelayedTask(bukkitService);
// then // then
verify(player).teleport(location); verify(player).teleport(location);