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);
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations