Skip to content

Commit

Permalink
incorporate changes recommended by Wesley1808
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul19988 committed Oct 3, 2023
1 parent b789257 commit 1b07659
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,15 @@ public void setState(StateRegistry state) {
ensureInEventLoop();

this.state = state;
this.channel.pipeline().get(MinecraftEncoder.class).setState(state);
this.channel.pipeline().get(MinecraftDecoder.class).setState(state);
MinecraftEncoder encoder = channel.pipeline().get(MinecraftEncoder.class);
MinecraftDecoder decoder = channel.pipeline().get(MinecraftDecoder.class);
encoder.setState(state);
decoder.setState(state);

if (state == StateRegistry.CONFIG) {
// Activate the play packet queue
this.channel.pipeline().addAfter(Connections.MINECRAFT_ENCODER, Connections.PLAY_PACKET_QUEUE,
new PlayPacketQueueHandler(this.protocolVersion));
new PlayPacketQueueHandler(this.protocolVersion, encoder.getDirection()));
} else if (this.channel.pipeline().get(Connections.PLAY_PACKET_QUEUE) != null) {
// Remove the queue
this.channel.pipeline().remove(Connections.PLAY_PACKET_QUEUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ public void setState(StateRegistry state) {
this.state = state;
this.setProtocolVersion(registry.version);
}

public ProtocolUtils.Direction getDirection() {
return direction;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,17 @@
*/
public class PlayPacketQueueHandler extends ChannelDuplexHandler {

private final StateRegistry.PacketRegistry.ProtocolRegistry clientRegistry;
private final StateRegistry.PacketRegistry.ProtocolRegistry serverRegistry;
private final StateRegistry.PacketRegistry.ProtocolRegistry registry;
private final Queue<MinecraftPacket> queue = PlatformDependent.newMpscQueue();

/**
* Provides registries for client & server bound packets.
*
* @param version the protocol version
*/
public PlayPacketQueueHandler(ProtocolVersion version) {
this.clientRegistry =
StateRegistry.CONFIG.getProtocolRegistry(ProtocolUtils.Direction.CLIENTBOUND, version);
this.serverRegistry =
StateRegistry.CONFIG.getProtocolRegistry(ProtocolUtils.Direction.SERVERBOUND, version);
public PlayPacketQueueHandler(ProtocolVersion version, ProtocolUtils.Direction direction) {
this.registry =
StateRegistry.CONFIG.getProtocolRegistry(direction, version);
}

@Override
Expand All @@ -68,12 +65,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)

// If the packet exists in the CONFIG state, we want to always
// ensure that it gets sent out to the client
if (this.clientRegistry.containsPacket(((MinecraftPacket) msg))) {
ctx.write(msg, promise);
return;
}

if (this.serverRegistry.containsPacket(((MinecraftPacket) msg))) {
if (this.registry.containsPacket(((MinecraftPacket) msg))) {
ctx.write(msg, promise);
return;
}
Expand Down

0 comments on commit 1b07659

Please sign in to comment.