Search in sources :

Example 1 with PlayerKickEvent

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

the class PlayerListenerTest method shouldNotCancelOrdinaryKick.

@Test
public void shouldNotCancelOrdinaryKick() {
    // given
    given(settings.getProperty(RestrictionSettings.FORCE_SINGLE_SESSION)).willReturn(true);
    String name = "Bobby";
    Player player = mockPlayerWithName(name);
    PlayerKickEvent event = new PlayerKickEvent(player, "No longer desired here!", "");
    given(antiBotService.wasPlayerKicked(name)).willReturn(true);
    // when
    listener.onPlayerKick(event);
    // then
    assertThat(event.isCancelled(), equalTo(false));
    verify(antiBotService).wasPlayerKicked(name);
    verifyZeroInteractions(management);
}
Also used : Player(org.bukkit.entity.Player) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PlayerKickEvent(org.bukkit.event.player.PlayerKickEvent) Test(org.junit.Test)

Example 2 with PlayerKickEvent

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

the class PlayerListenerTest method shouldCancelKick.

/**
     * #831: If a player is kicked because of "logged in from another location", the kick
     * should be CANCELED when single session is enabled.
     */
@Test
public void shouldCancelKick() {
    // given
    given(settings.getProperty(RestrictionSettings.FORCE_SINGLE_SESSION)).willReturn(true);
    Player player = mock(Player.class);
    PlayerKickEvent event = new PlayerKickEvent(player, "You logged in from another location", "");
    // when
    listener.onPlayerKick(event);
    // then
    assertThat(event.isCancelled(), equalTo(true));
    verifyZeroInteractions(player, management, antiBotService);
}
Also used : Player(org.bukkit.entity.Player) PlayerKickEvent(org.bukkit.event.player.PlayerKickEvent) Test(org.junit.Test)

Example 3 with PlayerKickEvent

use of org.bukkit.event.player.PlayerKickEvent in project Glowstone by GlowstoneMC.

the class GlowSession method disconnect.

/**
     * Disconnects the session with the specified reason. This causes a
     * KickMessage to be sent. When it has been delivered, the channel
     * is closed.
     *
     * @param reason       The reason for disconnection.
     * @param overrideKick Whether to skip the kick event.
     */
public void disconnect(String reason, boolean overrideKick) {
    if (player != null && !overrideKick) {
        PlayerKickEvent event = EventFactory.onPlayerKick(player, reason);
        if (event.isCancelled()) {
            return;
        }
        reason = event.getReason();
        if (player.isOnline() && event.getLeaveMessage() != null) {
            server.broadcastMessage(event.getLeaveMessage());
        }
    }
    // log that the player was kicked
    if (player != null) {
        GlowServer.logger.info(player.getName() + " kicked: " + reason);
    } else {
        GlowServer.logger.info("[" + address + "] kicked: " + reason);
    }
    if (quitReason == null) {
        quitReason = "kicked";
    }
    // perform the kick, sending a kick message if possible
    if (isActive() && (getProtocol() instanceof LoginProtocol || getProtocol() instanceof PlayProtocol)) {
        // channel is both currently connected and in a protocol state allowing kicks
        sendWithFuture(new KickMessage(reason)).addListener(ChannelFutureListener.CLOSE);
    } else {
        getChannel().close();
    }
}
Also used : KickMessage(net.glowstone.net.message.KickMessage) PlayerKickEvent(org.bukkit.event.player.PlayerKickEvent) PlayProtocol(net.glowstone.net.protocol.PlayProtocol) LoginProtocol(net.glowstone.net.protocol.LoginProtocol)

Example 4 with PlayerKickEvent

use of org.bukkit.event.player.PlayerKickEvent in project Dragonet-Legacy by DragonetMC.

the class MCPESession method disconnect.

/**
     * Disconnects the session with the specified reason. This causes a
     * KickMessage to be sent. When it has been delivered, the channel is
     * closed.
     *
     * @param reason The reason for disconnection.
     * @param overrideKick Whether to skip the kick event.
     */
@Override
public void disconnect(String reason, boolean overrideKick) {
    if (player != null && !overrideKick) {
        PlayerKickEvent event = EventFactory.onPlayerKick(player, reason);
        if (event.isCancelled()) {
            return;
        }
        reason = event.getReason();
        if (event.getLeaveMessage() != null) {
            this.getServer().broadcastMessage(event.getLeaveMessage());
        }
    }
    // log that the player was kicked
    if (player != null) {
        GlowServer.logger.info(player.getName() + " kicked: " + reason);
        this.player.remove();
    } else {
        GlowServer.logger.info("[" + client.getRemoteAddress().getHostString() + ":" + client.getRemoteAddress().getPort() + "] kicked: " + reason);
    }
    client.disconnect(reason);
    this.statusActive = false;
    this.dServer.getSessionManager().removeSessionRaw(this);
    this.getServer().getSessionRegistry().remove((GlowSession) this);
    if (this.player != null) {
        this.player.getWorld().getRawPlayers().remove(this.player);
    }
    this.player = null;
}
Also used : PlayerKickEvent(org.bukkit.event.player.PlayerKickEvent)

Example 5 with PlayerKickEvent

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

the class PlayerListenerTest method shouldNotCancelKick.

@Test
public void shouldNotCancelKick() {
    // given
    given(settings.getProperty(RestrictionSettings.FORCE_SINGLE_SESSION)).willReturn(false);
    String name = "Bobby";
    Player player = mockPlayerWithName(name);
    PlayerKickEvent event = new PlayerKickEvent(player, "You logged in from another location", "");
    given(antiBotService.wasPlayerKicked(name)).willReturn(false);
    // when
    listener.onPlayerKick(event);
    // then
    assertThat(event.isCancelled(), equalTo(false));
    verify(antiBotService).wasPlayerKicked(name);
    verify(management).performQuit(player);
}
Also used : Player(org.bukkit.entity.Player) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PlayerKickEvent(org.bukkit.event.player.PlayerKickEvent) Test(org.junit.Test)

Aggregations

PlayerKickEvent (org.bukkit.event.player.PlayerKickEvent)5 Player (org.bukkit.entity.Player)3 Test (org.junit.Test)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 KickMessage (net.glowstone.net.message.KickMessage)1 LoginProtocol (net.glowstone.net.protocol.LoginProtocol)1 PlayProtocol (net.glowstone.net.protocol.PlayProtocol)1