Skip to content

Commit

Permalink
refactor(bungee): get protocol version from pending connection (#343)
Browse files Browse the repository at this point in the history
Relates to #342
Relates to #289
  • Loading branch information
diogotcorreia authored Nov 2, 2023
1 parent 1b5328e commit 7fb13e4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
12 changes: 2 additions & 10 deletions core/src/main/java/com/rexcantor64/triton/BungeeMLP.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.scheduler.ScheduledTask;
import net.md_5.bungee.netty.PipelineUtils;
import net.md_5.bungee.protocol.MinecraftEncoder;
import org.bstats.bungeecord.Metrics;
import org.bstats.charts.SingleLineChart;

Expand Down Expand Up @@ -60,7 +59,7 @@ public void onEnable() {

for (ProxiedPlayer p : getBungeeCord().getPlayers()) {
BungeeLanguagePlayer lp = (BungeeLanguagePlayer) getPlayerManager().get(p.getUniqueId());
injectPipeline(lp, p);
injectPipeline(lp, p, p.getPendingConnection().getVersion());
}

val commandHandler = new BungeeCommandHandler();
Expand Down Expand Up @@ -115,19 +114,12 @@ public String getVersion() {
return getLoader().getDescription().getVersion();
}

public void injectPipeline(BungeeLanguagePlayer lp, Connection p) {
public void injectPipeline(BungeeLanguagePlayer lp, Connection p, int protocolVersion) {
Triton.get().getLogger().logTrace("Injecting pipeline for player %1", lp);
try {
Object ch = NMSUtils.getDeclaredField(p, "ch");
Method method = ch.getClass().getDeclaredMethod("getHandle");
Channel channel = (Channel) method.invoke(ch, new Object[0]);
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void onLogin(LoginEvent event) {
Triton.asBungee().getBungeeCord().getScheduler().runAsync(plugin, () -> {
val lp = new BungeeLanguagePlayer(event.getConnection().getUniqueId(), event.getConnection());
Triton.get().getPlayerManager().registerPlayer(lp);
BungeeMLP.asBungee().injectPipeline(lp, event.getConnection());
BungeeMLP.asBungee().injectPipeline(lp, event.getConnection(), event.getConnection().getVersion());
event.completeIntent(plugin);
});
}
Expand Down

0 comments on commit 7fb13e4

Please sign in to comment.