Search in sources :

Example 1 with PlayerQuitEvent

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

the class PlayerListenerTest method shouldRemoveMessageOnQuit.

@Test
public void shouldRemoveMessageOnQuit() {
    // given
    given(settings.getProperty(RegistrationSettings.REMOVE_LEAVE_MESSAGE)).willReturn(true);
    given(antiBotService.wasPlayerKicked(anyString())).willReturn(false);
    Player player = mockPlayerWithName("Billy");
    PlayerQuitEvent event = new PlayerQuitEvent(player, "Player has quit the server");
    // when
    listener.onPlayerQuit(event);
    // then
    assertThat(event.getQuitMessage(), nullValue());
    verify(antiBotService).wasPlayerKicked("Billy");
    verify(management).performQuit(player);
}
Also used : Player(org.bukkit.entity.Player) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) Test(org.junit.Test)

Example 2 with PlayerQuitEvent

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

the class PlayerListenerTest method shouldProcessPlayerAndKeepQuitMessage.

@Test
public void shouldProcessPlayerAndKeepQuitMessage() {
    // given
    String name = "Louis";
    Player player = mockPlayerWithName(name);
    given(settings.getProperty(RegistrationSettings.REMOVE_LEAVE_MESSAGE)).willReturn(false);
    given(settings.getProperty(RegistrationSettings.REMOVE_UNLOGGED_LEAVE_MESSAGE)).willReturn(false);
    given(antiBotService.wasPlayerKicked(name)).willReturn(false);
    String quitMessage = "The player has left the server.";
    PlayerQuitEvent event = new PlayerQuitEvent(player, quitMessage);
    // when
    listener.onPlayerQuit(event);
    // then
    assertThat(event.getQuitMessage(), equalTo(quitMessage));
    verify(antiBotService).wasPlayerKicked(name);
    verify(management).performQuit(player);
}
Also used : Player(org.bukkit.entity.Player) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 3 with PlayerQuitEvent

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

the class PlayerListenerTest method shouldRemoveMessageForUnloggedUser.

@Test
public void shouldRemoveMessageForUnloggedUser() {
    // given
    given(settings.getProperty(RegistrationSettings.REMOVE_LEAVE_MESSAGE)).willReturn(false);
    given(settings.getProperty(RegistrationSettings.REMOVE_UNLOGGED_LEAVE_MESSAGE)).willReturn(true);
    String name = "Joel";
    given(antiBotService.wasPlayerKicked(name)).willReturn(true);
    Player player = mockPlayerWithName(name);
    PlayerQuitEvent event = new PlayerQuitEvent(player, "Joel exits the party");
    given(listenerService.shouldCancelEvent(event)).willReturn(true);
    // when
    listener.onPlayerQuit(event);
    // then
    assertThat(event.getQuitMessage(), nullValue());
    verify(antiBotService).wasPlayerKicked(name);
    verifyZeroInteractions(management);
}
Also used : Player(org.bukkit.entity.Player) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 4 with PlayerQuitEvent

use of org.bukkit.event.player.PlayerQuitEvent in project VoxelGamesLibv2 by VoxelGamesLib.

the class GameListener method onLeave.

@EventHandler
public void onLeave(@Nonnull PlayerQuitEvent event) {
    User user = userHandler.getUser(event.getPlayer().getUniqueId()).orElseThrow(() -> new UserException("Unknown user " + event.getPlayer().getDisplayName() + "(" + event.getPlayer().getUniqueId() + ")"));
    gameHandler.getGames(event.getPlayer().getUniqueId(), true).forEach((game -> game.leave(user)));
}
Also used : PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) UserHandler(com.voxelgameslib.voxelgameslib.user.UserHandler) Logger(java.util.logging.Logger) GameLeaveEvent(com.voxelgameslib.voxelgameslib.event.events.game.GameLeaveEvent) Inject(javax.inject.Inject) EventHandler(org.bukkit.event.EventHandler) VoxelGamesLib(com.voxelgameslib.voxelgameslib.VoxelGamesLib) UserException(com.voxelgameslib.voxelgameslib.exception.UserException) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) User(com.voxelgameslib.voxelgameslib.user.User) Nonnull(javax.annotation.Nonnull) GameJoinEvent(com.voxelgameslib.voxelgameslib.event.events.game.GameJoinEvent) Bukkit(org.bukkit.Bukkit) Listener(org.bukkit.event.Listener) User(com.voxelgameslib.voxelgameslib.user.User) UserException(com.voxelgameslib.voxelgameslib.exception.UserException) EventHandler(org.bukkit.event.EventHandler)

Example 5 with PlayerQuitEvent

use of org.bukkit.event.player.PlayerQuitEvent in project NoCheatPlus by NoCheatPlus.

the class NoCheatPlus method getCoreListener.

/**
 * Quick solution to hide the listener methods, expect refactoring.
 * @return
 */
private Listener getCoreListener() {
    return new NCPListener() {

        @EventHandler(priority = EventPriority.NORMAL)
        public void onPlayerLogin(final PlayerLoginEvent event) {
            // (NORMAL to have chat checks come after this.)
            if (event.getResult() != Result.ALLOWED) {
                return;
            }
            final Player player = event.getPlayer();
            // TODO: Store by id + HashMapLOW.
            if (checkDenyLoginsNames(player.getName())) {
                if (DataManager.getPlayerData(player).hasPermission(Permissions.BYPASS_DENY_LOGIN, player)) {
                    return;
                }
                // TODO: Consider using the vanilla temporary ban feature instead (for an alternative?).
                // TODO: Display time for which the player is banned.
                event.setResult(Result.KICK_OTHER);
                // TODO: Some basic/language configuration object, possibly independent of checks.
                event.setKickMessage(ColorUtil.replaceColors(ConfigManager.getConfigFile(player.getWorld().getName()).getString(ConfPaths.STRINGS + ".msgtempdenylogin")));
            }
        }

        // Do update comment in NoCheatPlusAPI with changing.
        @EventHandler(priority = EventPriority.LOWEST)
        public void onPlayerJoinLowest(final PlayerJoinEvent event) {
            if (clearExemptionsOnJoin) {
                final Player player = event.getPlayer();
                NCPExemptionManager.unexempt(player);
            }
        }

        @EventHandler(priority = EventPriority.LOW)
        public void onPlayerJoinLow(final PlayerJoinEvent event) {
            // LOWEST is for DataMan and CombinedListener.
            onJoinLow(event.getPlayer());
        }

        @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
        public void onPlayerKick(final PlayerKickEvent event) {
            onLeave(event.getPlayer());
        }

        @EventHandler(priority = EventPriority.MONITOR)
        public void onPlayerQuit(final PlayerQuitEvent event) {
            onLeave(event.getPlayer());
        }

        @EventHandler(priority = EventPriority.MONITOR)
        public void onWorldLoad(final WorldLoadEvent event) {
            NoCheatPlus.this.onWorldLoad(event);
        }
    };
}
Also used : PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) Player(org.bukkit.entity.Player) PlayerLoginEvent(org.bukkit.event.player.PlayerLoginEvent) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) PlayerKickEvent(org.bukkit.event.player.PlayerKickEvent) WorldLoadEvent(org.bukkit.event.world.WorldLoadEvent) NCPListener(fr.neatmonster.nocheatplus.components.registry.feature.NCPListener)

Aggregations

PlayerQuitEvent (org.bukkit.event.player.PlayerQuitEvent)5 Player (org.bukkit.entity.Player)4 Test (org.junit.Test)3 PlayerJoinEvent (org.bukkit.event.player.PlayerJoinEvent)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 VoxelGamesLib (com.voxelgameslib.voxelgameslib.VoxelGamesLib)1 GameJoinEvent (com.voxelgameslib.voxelgameslib.event.events.game.GameJoinEvent)1 GameLeaveEvent (com.voxelgameslib.voxelgameslib.event.events.game.GameLeaveEvent)1 UserException (com.voxelgameslib.voxelgameslib.exception.UserException)1 User (com.voxelgameslib.voxelgameslib.user.User)1 UserHandler (com.voxelgameslib.voxelgameslib.user.UserHandler)1 NCPListener (fr.neatmonster.nocheatplus.components.registry.feature.NCPListener)1 Logger (java.util.logging.Logger)1 Nonnull (javax.annotation.Nonnull)1 Inject (javax.inject.Inject)1 Bukkit (org.bukkit.Bukkit)1 EventHandler (org.bukkit.event.EventHandler)1 Listener (org.bukkit.event.Listener)1 PlayerKickEvent (org.bukkit.event.player.PlayerKickEvent)1 PlayerLoginEvent (org.bukkit.event.player.PlayerLoginEvent)1