From 15e77588c9c29c7b6a375ab07917429e7cdf4201 Mon Sep 17 00:00:00 2001 From: creeper123123321 <7974274+creeper123123321@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:37:48 -0300 Subject: [PATCH] fix possible NPE, fix message --- src/main/java/com/viaversion/aas/codec/MinecraftCodec.java | 4 +++- .../com/viaversion/aas/handler/state/ConfigurationState.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/viaversion/aas/codec/MinecraftCodec.java b/src/main/java/com/viaversion/aas/codec/MinecraftCodec.java index 68e92c6..11dd4a7 100644 --- a/src/main/java/com/viaversion/aas/codec/MinecraftCodec.java +++ b/src/main/java/com/viaversion/aas/codec/MinecraftCodec.java @@ -25,10 +25,12 @@ public class MinecraftCodec extends MessageToMessageCodec { try { var handler = ctx.pipeline().get(MinecraftHandler.class); + var version = handler.getData().getFrontVer(); + if (version == null) version = ProtocolVersion.unknown; PacketRegistry.INSTANCE.encode( msg, buf, - handler.getData().getFrontVer(), + version, handler.getFrontEnd() ? Direction.CLIENTBOUND : Direction.SERVERBOUND ); out.add(buf.retain()); diff --git a/src/main/java/com/viaversion/aas/handler/state/ConfigurationState.java b/src/main/java/com/viaversion/aas/handler/state/ConfigurationState.java index 5cd49c0..df1d480 100644 --- a/src/main/java/com/viaversion/aas/handler/state/ConfigurationState.java +++ b/src/main/java/com/viaversion/aas/handler/state/ConfigurationState.java @@ -54,7 +54,7 @@ public class ConfigurationState implements ConnectionState { public void disconnect(@NotNull MinecraftHandler handler, @NotNull String msg) { ConnectionState.DefaultImpls.disconnect(this, handler, msg); var packet = new ConfigurationDisconnect(); - packet.setMsgForVersion(new JsonPrimitive("[VIAaaS] §c$msg"), handler.getData().getFrontVer()); + packet.setMsgForVersion(new JsonPrimitive("[VIAaaS] §c" + msg), handler.getData().getFrontVer()); UtilKt.writeFlushClose(handler.getData().getFrontChannel(), packet, false); }