Search in sources :

Example 1 with PlayerJoinEvent

use of org.bukkit.event.player.PlayerJoinEvent in project AuthMeReloaded by AuthMe.

the class PlayerListenerTest method shouldNotModifyJoinMessage.

@Test
public void shouldNotModifyJoinMessage() {
    // given
    Player player = mock(Player.class);
    String joinMsg = "The player joined";
    PlayerJoinEvent event = new PlayerJoinEvent(player, joinMsg);
    given(settings.getProperty(RegistrationSettings.REMOVE_JOIN_MESSAGE)).willReturn(false);
    given(settings.getProperty(RegistrationSettings.CUSTOM_JOIN_MESSAGE)).willReturn("");
    given(settings.getProperty(RegistrationSettings.DELAY_JOIN_MESSAGE)).willReturn(false);
    // when
    listener.onJoinMessage(event);
    // then
    assertThat(event.getJoinMessage(), equalTo(joinMsg));
    verifyZeroInteractions(joinMessageService);
}
Also used : PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) Player(org.bukkit.entity.Player) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 2 with PlayerJoinEvent

use of org.bukkit.event.player.PlayerJoinEvent in project AuthMeReloaded by AuthMe.

the class PlayerListenerTest method shouldDelayJoinMessage.

@Test
public void shouldDelayJoinMessage() {
    // given
    Player player = mock(Player.class);
    given(player.getName()).willReturn("thename0");
    given(player.getDisplayName()).willReturn("(not used)");
    String joinMsg = "The player joined";
    PlayerJoinEvent event = new PlayerJoinEvent(player, joinMsg);
    given(settings.getProperty(RegistrationSettings.REMOVE_JOIN_MESSAGE)).willReturn(false);
    given(settings.getProperty(RegistrationSettings.CUSTOM_JOIN_MESSAGE)).willReturn("{PLAYERNAME} is joining us");
    given(settings.getProperty(RegistrationSettings.DELAY_JOIN_MESSAGE)).willReturn(true);
    // when
    listener.onJoinMessage(event);
    // then
    assertThat(event.getJoinMessage(), nullValue());
    verify(joinMessageService).putMessage("thename0", "thename0 is joining us");
}
Also used : PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) Player(org.bukkit.entity.Player) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 3 with PlayerJoinEvent

use of org.bukkit.event.player.PlayerJoinEvent in project AuthMeReloaded by AuthMe.

the class PlayerListenerTest method shouldHandlePlayerJoining.

@Test
public void shouldHandlePlayerJoining() {
    // given
    Player player = mock(Player.class);
    PlayerJoinEvent event = new PlayerJoinEvent(player, "join message");
    // when
    listener.onPlayerJoin(event);
    // then
    verify(teleportationService).teleportNewPlayerToFirstSpawn(player);
    verify(management).performJoin(player);
}
Also used : PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) Player(org.bukkit.entity.Player) Test(org.junit.Test)

Example 4 with PlayerJoinEvent

use of org.bukkit.event.player.PlayerJoinEvent in project Essentials by drtshock.

the class EssentialsSpawn method onEnable.

@Override
public void onEnable() {
    final PluginManager pluginManager = getServer().getPluginManager();
    ess = (IEssentials) pluginManager.getPlugin("Essentials");
    if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) {
        LOGGER.log(Level.WARNING, tl("versionMismatchAll"));
    }
    if (!ess.isEnabled()) {
        this.setEnabled(false);
        return;
    }
    spawns = new SpawnStorage(ess);
    ess.addReloadListener(spawns);
    final EssentialsSpawnPlayerListener playerListener = new EssentialsSpawnPlayerListener(ess, spawns);
    pluginManager.registerEvent(PlayerRespawnEvent.class, playerListener, ess.getSettings().getRespawnPriority(), new EventExecutor() {

        @Override
        public void execute(final Listener ll, final Event event) throws EventException {
            ((EssentialsSpawnPlayerListener) ll).onPlayerRespawn((PlayerRespawnEvent) event);
        }
    }, this);
    pluginManager.registerEvent(PlayerJoinEvent.class, playerListener, ess.getSettings().getRespawnPriority(), new EventExecutor() {

        @Override
        public void execute(final Listener ll, final Event event) throws EventException {
            ((EssentialsSpawnPlayerListener) ll).onPlayerJoin((PlayerJoinEvent) event);
        }
    }, this);
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) EventExecutor(org.bukkit.plugin.EventExecutor) Listener(org.bukkit.event.Listener) EventException(org.bukkit.event.EventException) PlayerRespawnEvent(org.bukkit.event.player.PlayerRespawnEvent) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) Event(org.bukkit.event.Event) PlayerRespawnEvent(org.bukkit.event.player.PlayerRespawnEvent)

Example 5 with PlayerJoinEvent

use of org.bukkit.event.player.PlayerJoinEvent in project AuthMeReloaded by AuthMe.

the class PlayerListenerTest method shouldRemoveJoinMessage.

@Test
public void shouldRemoveJoinMessage() {
    // given
    Player player = mock(Player.class);
    String joinMsg = "The player joined";
    PlayerJoinEvent event = new PlayerJoinEvent(player, joinMsg);
    given(settings.getProperty(RegistrationSettings.REMOVE_JOIN_MESSAGE)).willReturn(true);
    // when
    listener.onJoinMessage(event);
    // then
    assertThat(event.getJoinMessage(), nullValue());
    verifyZeroInteractions(joinMessageService);
}
Also used : PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) Player(org.bukkit.entity.Player) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

PlayerJoinEvent (org.bukkit.event.player.PlayerJoinEvent)8 Player (org.bukkit.entity.Player)6 Test (org.junit.Test)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Listener (org.bukkit.event.Listener)2 PluginManager (org.bukkit.plugin.PluginManager)2 SignBlockListener (com.earth2me.essentials.signs.SignBlockListener)1 SignEntityListener (com.earth2me.essentials.signs.SignEntityListener)1 SignPlayerListener (com.earth2me.essentials.signs.SignPlayerListener)1 Event (org.bukkit.event.Event)1 EventException (org.bukkit.event.EventException)1 EventHandler (org.bukkit.event.EventHandler)1 PlayerRespawnEvent (org.bukkit.event.player.PlayerRespawnEvent)1 EventExecutor (org.bukkit.plugin.EventExecutor)1