Search in sources :

Example 1 with MessageTask

use of fr.xephi.authme.task.MessageTask in project AuthMeReloaded by AuthMe.

the class LimboPlayerTaskManager method registerMessageTask.

/**
     * Registers a {@link MessageTask} for the given player name.
     *
     * @param player the player
     * @param limbo the associated limbo player of the player
     * @param isRegistered whether the player is registered or not
     *                     (false shows "please register", true shows "please log in")
     */
void registerMessageTask(Player player, LimboPlayer limbo, boolean isRegistered) {
    int interval = settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
    MessageKey key = getMessageKey(isRegistered);
    if (interval > 0) {
        MessageTask messageTask = new MessageTask(player, messages.retrieve(key));
        bukkitService.runTaskTimer(messageTask, 2 * TICKS_PER_SECOND, interval * TICKS_PER_SECOND);
        limbo.setMessageTask(messageTask);
    }
}
Also used : MessageTask(fr.xephi.authme.task.MessageTask) MessageKey(fr.xephi.authme.message.MessageKey)

Example 2 with MessageTask

use of fr.xephi.authme.task.MessageTask in project AuthMeReloaded by AuthMe.

the class LimboPlayerTaskManagerTest method shouldCancelExistingMessageTask.

@Test
public void shouldCancelExistingMessageTask() {
    // given
    Player player = mock(Player.class);
    LimboPlayer limboPlayer = new LimboPlayer(null, true, "grp", false, 0.1f, 0.0f);
    MessageTask existingMessageTask = mock(MessageTask.class);
    limboPlayer.setMessageTask(existingMessageTask);
    given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(8);
    // when
    limboPlayerTaskManager.registerMessageTask(player, limboPlayer, false);
    // then
    assertThat(limboPlayer.getMessageTask(), not(nullValue()));
    assertThat(limboPlayer.getMessageTask(), not(sameInstance(existingMessageTask)));
    verify(messages).retrieve(MessageKey.REGISTER_MESSAGE);
    verify(existingMessageTask).cancel();
}
Also used : Player(org.bukkit.entity.Player) MessageTask(fr.xephi.authme.task.MessageTask) Test(org.junit.Test)

Aggregations

MessageTask (fr.xephi.authme.task.MessageTask)2 MessageKey (fr.xephi.authme.message.MessageKey)1 Player (org.bukkit.entity.Player)1 Test (org.junit.Test)1