From 42e48aa9b8b338e5e42a34c460d135cf3313634c Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Sun, 3 May 2020 12:44:59 -0400 Subject: [PATCH] Be more specific in which sendPacket method we choose Related to PaperMC/Paper#3282 --- .../protocol/utility/MinecraftMethods.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/comphenix/protocol/utility/MinecraftMethods.java b/src/main/java/com/comphenix/protocol/utility/MinecraftMethods.java index 9745b4c5..677a586b 100644 --- a/src/main/java/com/comphenix/protocol/utility/MinecraftMethods.java +++ b/src/main/java/com/comphenix/protocol/utility/MinecraftMethods.java @@ -2,6 +2,7 @@ package com.comphenix.protocol.utility; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.util.List; import java.util.Map; @@ -12,7 +13,6 @@ import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; -import io.netty.util.concurrent.GenericFutureListener; import net.sf.cglib.proxy.Enhancer; import net.sf.cglib.proxy.MethodInterceptor; @@ -85,7 +85,7 @@ public class MinecraftMethods { * @param playerConnection - the player connection. * @return The */ - public static Method getDisconnectMethod(Class playerConnection) { + public static Method getDisconnectMethod(Class playerConnection) { try { return FuzzyReflection.fromClass(playerConnection).getMethodByName("disconnect.*"); } catch (IllegalArgumentException e) { @@ -95,7 +95,7 @@ public class MinecraftMethods { } /** - * Retrieve the handle(Packet, GenericFutureListener[]) method of network manager. + * Retrieve the handle/send packet method of network manager. *

* This only exists in version 1.7.2 and above. * @return The handle method. @@ -104,7 +104,12 @@ public class MinecraftMethods { if (networkManagerHandle == null) { networkManagerHandle = FuzzyReflection .fromClass(MinecraftReflection.getNetworkManagerClass(), true) - .getMethodByParameters("handle", MinecraftReflection.getPacketClass()); + .getMethod(FuzzyMethodContract.newBuilder() + .banModifier(Modifier.STATIC) + .returnTypeVoid() + .parameterCount(1) + .parameterExactType(MinecraftReflection.getPacketClass()) + .build()); networkManagerHandle.setAccessible(true); } @@ -112,7 +117,7 @@ public class MinecraftMethods { } /** - * Retrieve the packetRead(ChannelHandlerContext, Packet) method of NetworkMananger. + * Retrieve the packetRead(ChannelHandlerContext, Packet) method of NetworkManager. *

* This only exists in version 1.7.2 and above. * @return The packetRead method.