Search in sources :

Example 1 with BukkitTask

use of org.bukkit.scheduler.BukkitTask in project AuthMeReloaded by AuthMe.

the class BukkitServiceTest method shouldRunTaskLater.

@Test
public void shouldRunTaskLater() {
    // given
    Runnable task = () -> {
    /* noop */
    };
    BukkitTask bukkitTask = mock(BukkitTask.class);
    long delay = 400;
    given(scheduler.runTaskLater(authMe, task, delay)).willReturn(bukkitTask);
    // when
    BukkitTask resultingTask = bukkitService.runTaskLater(task, delay);
    // then
    assertThat(resultingTask, equalTo(bukkitTask));
    verify(scheduler, only()).runTaskLater(authMe, task, delay);
}
Also used : BukkitTask(org.bukkit.scheduler.BukkitTask) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Test(org.junit.Test)

Example 2 with BukkitTask

use of org.bukkit.scheduler.BukkitTask in project AuthMeReloaded by AuthMe.

the class BukkitServiceTest method shouldRunTaskTimerAsynchronously.

@Test
public void shouldRunTaskTimerAsynchronously() {
    // given
    Runnable task = () -> {
    /* */
    };
    long delay = 20L;
    long period = 4000L;
    BukkitTask bukkitTask = mock(BukkitTask.class);
    given(scheduler.runTaskTimerAsynchronously(authMe, task, delay, period)).willReturn(bukkitTask);
    // when
    BukkitTask resultingTask = bukkitService.runTaskTimerAsynchronously(task, delay, period);
    // then
    assertThat(resultingTask, equalTo(bukkitTask));
    verify(scheduler).runTaskTimerAsynchronously(authMe, task, delay, period);
}
Also used : BukkitTask(org.bukkit.scheduler.BukkitTask) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Test(org.junit.Test)

Example 3 with BukkitTask

use of org.bukkit.scheduler.BukkitTask in project AuthMeReloaded by AuthMe.

the class LimboPlayerTaskManager method registerTimeoutTask.

/**
     * Registers a {@link TimeoutTask} for the given player according to the configuration.
     *
     * @param player the player to register a timeout task for
     * @param limbo the associated limbo player
     */
void registerTimeoutTask(Player player, LimboPlayer limbo) {
    final int timeout = settings.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
    if (timeout > 0) {
        String message = messages.retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR);
        BukkitTask task = bukkitService.runTaskLater(new TimeoutTask(player, message, playerCache), timeout);
        limbo.setTimeoutTask(task);
    }
}
Also used : BukkitTask(org.bukkit.scheduler.BukkitTask) TimeoutTask(fr.xephi.authme.task.TimeoutTask)

Example 4 with BukkitTask

use of org.bukkit.scheduler.BukkitTask in project AuthMeReloaded by AuthMe.

the class LimboPlayerTaskManagerTest method shouldRegisterTimeoutTask.

@Test
public void shouldRegisterTimeoutTask() {
    // given
    Player player = mock(Player.class);
    LimboPlayer limboPlayer = mock(LimboPlayer.class);
    given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(30);
    BukkitTask bukkitTask = mock(BukkitTask.class);
    given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask);
    // when
    limboPlayerTaskManager.registerTimeoutTask(player, limboPlayer);
    // then
    verify(limboPlayer).setTimeoutTask(bukkitTask);
    // 30 * TICKS_PER_SECOND
    verify(bukkitService).runTaskLater(any(TimeoutTask.class), eq(600L));
    verify(messages).retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR);
}
Also used : Player(org.bukkit.entity.Player) BukkitTask(org.bukkit.scheduler.BukkitTask) TimeoutTask(fr.xephi.authme.task.TimeoutTask) Test(org.junit.Test)

Example 5 with BukkitTask

use of org.bukkit.scheduler.BukkitTask in project AuthMeReloaded by AuthMe.

the class LimboPlayerTaskManagerTest method shouldCancelExistingTimeoutTask.

@Test
public void shouldCancelExistingTimeoutTask() {
    // given
    Player player = mock(Player.class);
    LimboPlayer limboPlayer = new LimboPlayer(null, false, "", true, 0.3f, 0.1f);
    BukkitTask existingTask = mock(BukkitTask.class);
    limboPlayer.setTimeoutTask(existingTask);
    given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(18);
    BukkitTask bukkitTask = mock(BukkitTask.class);
    given(bukkitService.runTaskLater(any(TimeoutTask.class), anyLong())).willReturn(bukkitTask);
    // when
    limboPlayerTaskManager.registerTimeoutTask(player, limboPlayer);
    // then
    verify(existingTask).cancel();
    assertThat(limboPlayer.getTimeoutTask(), equalTo(bukkitTask));
    // 18 * TICKS_PER_SECOND
    verify(bukkitService).runTaskLater(any(TimeoutTask.class), eq(360L));
    verify(messages).retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR);
}
Also used : Player(org.bukkit.entity.Player) BukkitTask(org.bukkit.scheduler.BukkitTask) TimeoutTask(fr.xephi.authme.task.TimeoutTask) Test(org.junit.Test)

Aggregations

BukkitTask (org.bukkit.scheduler.BukkitTask)9 Test (org.junit.Test)7 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)5 TimeoutTask (fr.xephi.authme.task.TimeoutTask)3 Player (org.bukkit.entity.Player)2