Skip to content

Commit aeeb871

Browse files
authored
Update for method name changes in 1.18 (MrMicky-FR#19)
1 parent 18f6cba commit aeeb871

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/main/java/fr/mrmicky/fastboard/FastBoard.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.lang.invoke.MethodType;
3232
import java.lang.reflect.Array;
3333
import java.lang.reflect.Field;
34+
import java.lang.reflect.Method;
3435
import java.lang.reflect.Modifier;
3536
import java.util.ArrayList;
3637
import java.util.Arrays;
@@ -110,6 +111,10 @@ public class FastBoard {
110111
Field playerConnectionField = Arrays.stream(entityPlayerClass.getFields())
111112
.filter(field -> field.getType().isAssignableFrom(playerConnectionClass))
112113
.findFirst().orElseThrow(NoSuchFieldException::new);
114+
Class<?>[] sendPacketParameters = new Class[]{packetClass};
115+
Method sendPacketMethod = Arrays.stream(playerConnectionClass.getMethods())
116+
.filter(method -> Arrays.equals(method.getParameterTypes(), sendPacketParameters))
117+
.findFirst().orElseThrow(NoSuchMethodException::new);
113118

114119
MESSAGE_FROM_STRING = lookup.unreflect(craftChatMessageClass.getMethod("fromString", String.class));
115120
CHAT_COMPONENT_CLASS = FastReflection.nmsClass("network.chat", "IChatBaseComponent");
@@ -118,7 +123,7 @@ public class FastBoard {
118123
RESET_FORMATTING = FastReflection.enumValueOf(CHAT_FORMAT_ENUM, "RESET", 21);
119124
PLAYER_GET_HANDLE = lookup.findVirtual(craftPlayerClass, "getHandle", MethodType.methodType(entityPlayerClass));
120125
PLAYER_CONNECTION = lookup.unreflectGetter(playerConnectionField);
121-
SEND_PACKET = lookup.findVirtual(playerConnectionClass, "sendPacket", MethodType.methodType(void.class, packetClass));
126+
SEND_PACKET = lookup.unreflect(sendPacketMethod);
122127
PACKET_SB_OBJ = FastReflection.findPacketConstructor(packetSbObjClass, lookup);
123128
PACKET_SB_DISPLAY_OBJ = FastReflection.findPacketConstructor(packetSbDisplayObjClass, lookup);
124129
PACKET_SB_SCORE = FastReflection.findPacketConstructor(packetSbScoreClass, lookup);

0 commit comments

Comments
 (0)