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

Better fix for when packets of type HANDSHAKING are not found in the registry. #2945

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ public Object apply(Channel channel, PacketType.Sender sender) {
AttributeKey<Object> key = this.getKeyForSender(sender);
Object codecData = channel.attr(key).get();
if (codecData == null) {
return null;
// If the codec handler was not found, fallback to HANDSHAKING
// Fixes https://github.com/dmulloy2/ProtocolLib/issues/2601
return PacketType.Protocol.HANDSHAKING;
}

FieldAccessor protocolAccessor = this.getProtocolAccessor(codecData.getClass());
Expand Down Expand Up @@ -152,7 +154,9 @@ public Object apply(Channel channel, PacketType.Sender sender) {
String key = this.getKeyForSender(sender);
Object codecHandler = channel.pipeline().get(key);
if (codecHandler == null) {
return null;
// If the codec handler was not found, fallback to HANDSHAKING
// Fixes https://github.com/dmulloy2/ProtocolLib/issues/2601
return PacketType.Protocol.HANDSHAKING;
}

Function<Object, Object> protocolAccessor = this.getProtocolAccessor(codecHandler.getClass(), sender);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,7 @@ public PacketEvent onPacketReceiving(Injector injector, Object packet, NetworkMa
if (marker != null || inboundListeners.contains(packetClass)) {
// wrap the packet and construct the event
PacketType.Protocol currentProtocol = injector.getCurrentProtocol(PacketType.Sender.CLIENT);
PacketType packetType = PacketRegistry.getPacketType(currentProtocol, packetClass);

// if packet type could not be found, fallback to HANDSHAKING protocol
// temporary workaround for https://github.com/dmulloy2/ProtocolLib/issues/2601
if (packetType == null) {
packetType = PacketRegistry.getPacketType(PacketType.Protocol.HANDSHAKING, packetClass);
}

PacketContainer container = new PacketContainer(packetType, packet);
PacketContainer container = new PacketContainer(PacketRegistry.getPacketType(currentProtocol, packetClass), packet);
PacketEvent packetEvent = PacketEvent.fromClient(this, container, marker, injector.getPlayer());

// post to all listeners, then return the packet event we constructed
Expand Down
Loading