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);
}
}
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()));
}
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);
}
Aggregations