Skip to content

Commit f357ac8

Browse files
authored
Preserve the pipeline order when async receiving packets (#3351)
1 parent 66cdb5b commit f357ac8

File tree

2 files changed

+5
-27
lines changed

2 files changed

+5
-27
lines changed

src/main/java/com/comphenix/protocol/injector/netty/channel/NettyChannelInjector.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,7 @@ public void readServerboundPacket(Object packet) {
289289

290290
this.ensureInEventLoop(() -> {
291291
try {
292-
// try to invoke the method, this should normally not fail
293-
this.listenerInvoker.read(packet);
292+
this.channel.pipeline().context(INBOUND_INTERCEPTOR_NAME).fireChannelRead(packet);
294293
} catch (Exception exception) {
295294
this.errorReporter.reportWarning(this, Report.newBuilder(REPORT_CANNOT_READ_PACKET)
296295
.messageParam(packet, this.playerName)

src/main/java/com/comphenix/protocol/injector/netty/channel/PacketListenerInvoker.java

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
import com.comphenix.protocol.utility.MinecraftReflection;
1515
import com.comphenix.protocol.wrappers.WrappedChatComponent;
1616

17-
import io.netty.channel.ChannelHandlerContext;
18-
1917
/**
2018
* This class facilitates the invocation of methods on the current packet listener.
21-
* It attempts to execute the <code>send</code>, <code>read</code>, and <code>disconnect</code>
22-
* methods and, upon failure (either due to the absence of the method or the packet
23-
* listener being of an incorrect type), it delegates the call to the network manager.
19+
* It attempts to execute the <code>send</code>, and <code>disconnect</code> methods, upon failure
20+
* (either due to the absence of the method or the packet listener being of an incorrect type),
21+
* it delegates the call to the network manager.
2422
*
2523
* <p>Supported packet listener types include CONFIGURATION and PLAY. If the packet
2624
* listener does not match these types, or if the required method is missing, the
@@ -43,7 +41,6 @@ public class PacketListenerInvoker {
4341
private static final boolean DOES_PACKET_LISTENER_DISCONNECT_USE_COMPONENT = doesPacketListenerDisconnectUseComponent();
4442

4543
private static final MethodAccessor NETWORK_MANAGER_SEND = getNetworkManagerSend();
46-
private static final MethodAccessor NETWORK_MANAGER_READ = getNetworkManagerRead();
4744
private static final MethodAccessor NETWORK_MANAGER_DISCONNECT = getNetworkManagerDisconnect();
4845
private static final MethodAccessor NETWORK_MANAGER_PACKET_LISTENER = getNetworkManagerPacketListener();
4946

@@ -117,15 +114,6 @@ private static MethodAccessor getNetworkManagerSend() {
117114
return Accessors.getMethodAccessor(send);
118115
}
119116

120-
private static MethodAccessor getNetworkManagerRead() {
121-
FuzzyReflection networkManager = FuzzyReflection.fromClass(MinecraftReflection.getNetworkManagerClass(), true);
122-
123-
Method read = networkManager
124-
.getMethodByParameters("read", ChannelHandlerContext.class, MinecraftReflection.getPacketClass());
125-
126-
return Accessors.getMethodAccessor(read);
127-
}
128-
129117
private static MethodAccessor getNetworkManagerDisconnect() {
130118
FuzzyReflection networkManager = FuzzyReflection.fromClass(MinecraftReflection.getNetworkManagerClass());
131119

@@ -190,7 +178,7 @@ private Object getPacketListener() {
190178
}
191179

192180
/**
193-
* Sends a packet using the current packet listener if available and valid; otherwise,
181+
* Sends a packet using the current packet listener if available and valid; otherwise,
194182
* falls back to the network manager.
195183
*
196184
* @param packet The packet to be sent.
@@ -204,15 +192,6 @@ public void send(Object packet) {
204192
}
205193
}
206194

207-
/**
208-
* Reads a packet directly using the network manager.
209-
*
210-
* @param packet The packet to be read.
211-
*/
212-
public void read(Object packet) {
213-
NETWORK_MANAGER_READ.invoke(this.networkManager, null, packet);
214-
}
215-
216195
/**
217196
* Disconnects the player using the current packet listener if available and valid; otherwise,
218197
* falls back to the network manager.

0 commit comments

Comments
 (0)