Skip to content

Commit

Permalink
fix(bungee): error when MinecraftEncoder not present in netty pipeline (
Browse files Browse the repository at this point in the history
#342)

Fixes #289
  • Loading branch information
diogotcorreia authored Nov 2, 2023
1 parent c7b49e7 commit 1b5328e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions core/src/main/java/com/rexcantor64/triton/BungeeMLP.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,20 @@ public void injectPipeline(BungeeLanguagePlayer lp, Connection p) {
Object ch = NMSUtils.getDeclaredField(p, "ch");
Method method = ch.getClass().getDeclaredMethod("getHandle");
Channel channel = (Channel) method.invoke(ch, new Object[0]);
int protocolVersion = (int) NMSUtils.getDeclaredField(channel.pipeline().get(MinecraftEncoder.class), "protocolVersion");
MinecraftEncoder encoder = channel.pipeline().get(MinecraftEncoder.class);
if (encoder == null) {
getLogger().logWarning("[PacketInjector] Player %1's pipeline does not have a MinecraftEncoder. Failed to get protocol version. Ignore this if the player was kicked from the server.",
lp.getUUID());
return;
}
int protocolVersion = encoder.getProtocolVersion();

channel.pipeline().addAfter(PipelineUtils.PACKET_DECODER, "triton-custom-decoder", new BungeeDecoder(lp));
channel.pipeline()
.addAfter(PipelineUtils.PACKET_ENCODER, "triton-custom-encoder", new BungeeListener(lp, protocolVersion));
channel.pipeline().remove("triton-pre-login-encoder");
} catch (Exception e) {
getLogger().logError("[PacketInjector] Failed to inject client connection for %1", lp.getUUID());
e.printStackTrace();
getLogger().logError(e, "[PacketInjector] Failed to inject client connection for %1", lp.getUUID());
}
}

Expand Down

0 comments on commit 1b5328e

Please sign in to comment.