Skip to content

Commit 42e48aa

Browse files
committed
Be more specific in which sendPacket method we choose
Related to PaperMC/Paper#3282
1 parent 18d0193 commit 42e48aa

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/main/java/com/comphenix/protocol/utility/MinecraftMethods.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.lang.reflect.InvocationTargetException;
44
import java.lang.reflect.Method;
5+
import java.lang.reflect.Modifier;
56
import java.util.List;
67
import java.util.Map;
78

@@ -12,7 +13,6 @@
1213

1314
import io.netty.buffer.Unpooled;
1415
import io.netty.channel.ChannelHandlerContext;
15-
import io.netty.util.concurrent.GenericFutureListener;
1616

1717
import net.sf.cglib.proxy.Enhancer;
1818
import net.sf.cglib.proxy.MethodInterceptor;
@@ -85,7 +85,7 @@ public static Method getSendPacketMethod() {
8585
* @param playerConnection - the player connection.
8686
* @return The
8787
*/
88-
public static Method getDisconnectMethod(Class<? extends Object> playerConnection) {
88+
public static Method getDisconnectMethod(Class<?> playerConnection) {
8989
try {
9090
return FuzzyReflection.fromClass(playerConnection).getMethodByName("disconnect.*");
9191
} catch (IllegalArgumentException e) {
@@ -95,7 +95,7 @@ public static Method getDisconnectMethod(Class<? extends Object> playerConnectio
9595
}
9696

9797
/**
98-
* Retrieve the handle(Packet, GenericFutureListener[]) method of network manager.
98+
* Retrieve the handle/send packet method of network manager.
9999
* <p>
100100
* This only exists in version 1.7.2 and above.
101101
* @return The handle method.
@@ -104,15 +104,20 @@ public static Method getNetworkManagerHandleMethod() {
104104
if (networkManagerHandle == null) {
105105
networkManagerHandle = FuzzyReflection
106106
.fromClass(MinecraftReflection.getNetworkManagerClass(), true)
107-
.getMethodByParameters("handle", MinecraftReflection.getPacketClass());
107+
.getMethod(FuzzyMethodContract.newBuilder()
108+
.banModifier(Modifier.STATIC)
109+
.returnTypeVoid()
110+
.parameterCount(1)
111+
.parameterExactType(MinecraftReflection.getPacketClass())
112+
.build());
108113
networkManagerHandle.setAccessible(true);
109114
}
110115

111116
return networkManagerHandle;
112117
}
113118

114119
/**
115-
* Retrieve the packetRead(ChannelHandlerContext, Packet) method of NetworkMananger.
120+
* Retrieve the packetRead(ChannelHandlerContext, Packet) method of NetworkManager.
116121
* <p>
117122
* This only exists in version 1.7.2 and above.
118123
* @return The packetRead method.

0 commit comments

Comments
 (0)