Search in sources :

Example 1 with ClientboundDisconnectPacket

use of net.minecraft.network.protocol.game.ClientboundDisconnectPacket in project SpongeCommon by SpongePowered.

the class PlayerListMixin method impl$disconnectClient.

private void impl$disconnectClient(final Connection netManager, final Component disconnectMessage, @Nullable final GameProfile profile) {
    final net.minecraft.network.chat.Component reason = SpongeAdventure.asVanilla(disconnectMessage);
    try {
        PlayerListMixin.LOGGER.info("Disconnecting " + (profile != null ? profile.toString() + " (" + netManager.getRemoteAddress().toString() + ")" : netManager.getRemoteAddress() + ": " + reason.getString()));
        netManager.send(new ClientboundDisconnectPacket(reason));
        netManager.disconnect(reason);
    } catch (final Exception exception) {
        PlayerListMixin.LOGGER.error("Error whilst disconnecting player", exception);
    }
}
Also used : ClientboundDisconnectPacket(net.minecraft.network.protocol.game.ClientboundDisconnectPacket) UnknownHostException(java.net.UnknownHostException)

Example 2 with ClientboundDisconnectPacket

use of net.minecraft.network.protocol.game.ClientboundDisconnectPacket in project SpongeCommon by SpongePowered.

the class ServerLoginPacketListenerImplMixin method impl$disconnectError.

private void impl$disconnectError(final Throwable throwable, final boolean gameDisconnect) {
    SpongeCommon.logger().error("Forcibly disconnecting user {} due to an error during login.", this.gameProfile, throwable);
    final net.minecraft.network.chat.Component message = new TextComponent("Internal Server Error: unable to complete login.");
    // At this point, the client might be in the GAME state, so we need to send the right packet.
    if (gameDisconnect) {
        this.connection.send(new ClientboundDisconnectPacket(message), (param1) -> this.connection.disconnect(message));
    } else {
        this.shadow$disconnect(message);
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) ClientboundDisconnectPacket(net.minecraft.network.protocol.game.ClientboundDisconnectPacket)

Aggregations

ClientboundDisconnectPacket (net.minecraft.network.protocol.game.ClientboundDisconnectPacket)2 UnknownHostException (java.net.UnknownHostException)1 TextComponent (net.minecraft.network.chat.TextComponent)1