From 1cbc18ef4f8c35ef124c78ee9307ad241cde1c81 Mon Sep 17 00:00:00 2001 From: apple502j <33279053+apple502j@users.noreply.github.com> Date: Fri, 8 Sep 2023 14:03:07 +0900 Subject: [PATCH] Add helper method for disconnection --- .../networking/v1/ClientConfigurationNetworking.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/api/client/networking/v1/ClientConfigurationNetworking.java b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/api/client/networking/v1/ClientConfigurationNetworking.java index 78a5dbe044..829a76d8a4 100644 --- a/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/api/client/networking/v1/ClientConfigurationNetworking.java +++ b/fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/api/client/networking/v1/ClientConfigurationNetworking.java @@ -27,6 +27,7 @@ import net.minecraft.network.PacketByteBuf; import net.minecraft.network.listener.ServerCommonPacketListener; import net.minecraft.network.packet.Packet; +import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.thread.ThreadExecutor; @@ -393,6 +394,14 @@ public static void send(T packet) { throw new IllegalStateException("Cannot send packet while not configuring!"); } + /** + * Disconnects from the server. + * @param handler the network handler + */ + public static void disconnect(ClientConfigurationNetworkHandler handler, Text reason) { + ((ClientCommonNetworkHandlerAccessor) handler).getConnection().disconnect(reason); + } + private ClientConfigurationNetworking() { }