Search in sources :

Example 1 with SPacketDisconnect

use of net.minecraft.network.play.server.SPacketDisconnect in project SpongeCommon by SpongePowered.

the class MixinPlayerList method disconnectClient.

private void disconnectClient(NetworkManager netManager, Optional<Text> disconnectMessage, @Nullable GameProfile profile) {
    ITextComponent reason;
    if (disconnectMessage.isPresent()) {
        reason = SpongeTexts.toComponent(disconnectMessage.get());
    } else {
        reason = new TextComponentTranslation("disconnect.disconnected");
    }
    try {
        LOGGER.info("Disconnecting " + (profile != null ? profile.toString() + " (" + netManager.getRemoteAddress().toString() + ")" : String.valueOf(netManager.getRemoteAddress() + ": " + reason.getUnformattedText())));
        netManager.sendPacket(new SPacketDisconnect(reason));
        netManager.closeChannel(reason);
    } catch (Exception exception) {
        LOGGER.error("Error whilst disconnecting player", exception);
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ITextComponent(net.minecraft.util.text.ITextComponent) SPacketDisconnect(net.minecraft.network.play.server.SPacketDisconnect)

Example 2 with SPacketDisconnect

use of net.minecraft.network.play.server.SPacketDisconnect in project SpongeCommon by SpongePowered.

the class PlayerKickHelper method kickPlayer.

/**
 * A {@link ITextComponent}-friendly version of
 * {@link NetHandlerPlayServer#kickPlayerFromServer(String)}. This
 * duplicates the code of that kick implementation pretty much exactly
 *
 * @param ply The player to kick
 * @param component The kick message
 */
public static void kickPlayer(final EntityPlayerMP ply, final ITextComponent component) {
    ply.connection.getNetworkManager().sendPacket(new SPacketDisconnect(component), future -> ply.connection.getNetworkManager().closeChannel(component));
    ply.connection.getNetworkManager().disableAutoRead();
    // fix this getServer.
    Futures.getUnchecked(ply.getServer().addScheduledTask(() -> ply.connection.getNetworkManager().checkDisconnected()));
}
Also used : SPacketDisconnect(net.minecraft.network.play.server.SPacketDisconnect)

Example 3 with SPacketDisconnect

use of net.minecraft.network.play.server.SPacketDisconnect in project MinecraftForge by MinecraftForge.

the class NetworkDispatcher method kickWithMessage.

private void kickWithMessage(String message) {
    FMLLog.log(Level.ERROR, "Network Disconnect: %s", message);
    final TextComponentString TextComponentString = new TextComponentString(message);
    if (side == Side.CLIENT) {
        manager.closeChannel(TextComponentString);
    } else {
        manager.sendPacket(new SPacketDisconnect(TextComponentString), new GenericFutureListener<Future<? super Void>>() {

            @Override
            public void operationComplete(Future<? super Void> result) {
                manager.closeChannel(TextComponentString);
            }
        }, (GenericFutureListener<? extends Future<? super Void>>[]) null);
    }
    manager.channel().config().setAutoRead(false);
}
Also used : Future(io.netty.util.concurrent.Future) SPacketDisconnect(net.minecraft.network.play.server.SPacketDisconnect) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

SPacketDisconnect (net.minecraft.network.play.server.SPacketDisconnect)3 Future (io.netty.util.concurrent.Future)1 GenericFutureListener (io.netty.util.concurrent.GenericFutureListener)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1