Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bungee): error when MinecraftEncoder not present in netty pipeline #342

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading