Catch exception inside client-side JOIN event (#2813)

* Catch exception inside client-side JOIN event

* Update fabric-networking-api-v1/src/client/java/net/fabricmc/fabric/impl/networking/client/ClientPlayNetworkAddon.java

Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com>

Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com>
(cherry picked from commit 4017a8cb18)
This commit is contained in:
apple502j 2023-01-02 22:03:53 +09:00 committed by modmuss50
parent 3e1e13ab8f
commit 10eb22f456

View file

@ -20,6 +20,9 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import com.mojang.logging.LogUtils;
import org.slf4j.Logger;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.Packet;
@ -42,6 +45,8 @@ public final class ClientPlayNetworkAddon extends AbstractChanneledNetworkAddon<
private final MinecraftClient client;
private boolean sentInitialRegisterPacket;
private static final Logger LOGGER = LogUtils.getLogger();
public ClientPlayNetworkAddon(ClientPlayNetworkHandler handler, MinecraftClient client) {
super(ClientNetworkingImpl.PLAY, handler.getConnection(), "ClientPlayNetworkAddon for " + handler.getProfile().getName());
this.handler = handler;
@ -64,7 +69,11 @@ public final class ClientPlayNetworkAddon extends AbstractChanneledNetworkAddon<
}
public void onServerReady() {
ClientPlayConnectionEvents.JOIN.invoker().onPlayReady(this.handler, this, this.client);
try {
ClientPlayConnectionEvents.JOIN.invoker().onPlayReady(this.handler, this, this.client);
} catch (RuntimeException e) {
LOGGER.error("Exception thrown while invoking ClientPlayConnectionEvents.JOIN", e);
}
// The client cannot send any packets, including `minecraft:register` until after GameJoinS2CPacket is received.
this.sendInitialChannelRegistrationPacket();