Search in sources :

Example 1 with KickMessage

use of net.glowstone.net.message.KickMessage 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)

Aggregations

KickMessage (net.glowstone.net.message.KickMessage)1 LoginProtocol (net.glowstone.net.protocol.LoginProtocol)1 PlayProtocol (net.glowstone.net.protocol.PlayProtocol)1 PlayerKickEvent (org.bukkit.event.player.PlayerKickEvent)1