1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-11-23 01:58:49 +00:00

fix: 修复类型处理错误的问题

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2017-07-25 23:45:20 +08:00
parent 2b0a0d3a20
commit 24b81e5f00

View File

@ -37,6 +37,7 @@ public class C {
private static Method chatSerializer;
private static Method getHandle;
private static Method nmsChatMessageTypeClassValueOf;
private static String version;
private static boolean newversion;
@ -44,7 +45,7 @@ public class C {
private static Field playerConnection;
private static Method sendPacket;
private static Object[] ChatMessageTypes;
private static Object[] chatMessageTypes;
public static boolean init;
static {
@ -55,12 +56,22 @@ public class C {
chatSerializer = nmsChatSerializer.getMethod("a", String.class);
nmsIChatBaseComponent = Class.forName(a("IChatBaseComponent"));
packetType = Class.forName(a("PacketPlayOutChat"));
try {
nmsChatMessageTypeClass = Class.forName(a("ChatMessageType"));
ChatMessageTypes = nmsChatMessageTypeClass.getEnumConstants();
packetTypeConstructor = packetType.getConstructor(nmsIChatBaseComponent, nmsChatMessageTypeClass);
} catch (ClassNotFoundException ex) {
packetTypeConstructor = packetType.getConstructor(nmsIChatBaseComponent, newversion ? int.class : byte.class);
Arrays.stream(packetType.getConstructors()).forEach(c -> {
if (c.getParameterTypes().length == 2) {
packetTypeConstructor = c;
}
});
nmsChatMessageTypeClass = packetTypeConstructor.getParameterTypes()[1];
if (nmsChatMessageTypeClass.isEnum()) {
chatMessageTypes = nmsChatMessageTypeClass.getEnumConstants();
} else {
switch (nmsChatMessageTypeClass.getName()) {
case "int":
nmsChatMessageTypeClass = Integer.class;
case "byte":
nmsChatMessageTypeClass = Byte.class;
}
nmsChatMessageTypeClassValueOf = nmsChatMessageTypeClass.getDeclaredMethod("valueOf", String.class);
}
Class<?> typeCraftPlayer = Class.forName(b("entity.CraftPlayer"));
Class<?> typeNMSPlayer = Class.forName(a("EntityPlayer"));
@ -112,11 +123,8 @@ public class C {
Object serialized = chatSerializer.invoke(null, json);
Object player = getHandle.invoke(receivingPacket);
Object connection = playerConnection.get(player);
if (nmsChatMessageTypeClass != null) {
sendPacket.invoke(connection, packetTypeConstructor.newInstance(serialized, ChatMessageTypes[type]));
} else {
sendPacket.invoke(connection, packetTypeConstructor.newInstance(serialized, newversion ? type : (byte) type));
}
Object typeObj = chatMessageTypes == null ? nmsChatMessageTypeClassValueOf.invoke(null, String.valueOf(type)) : chatMessageTypes[type];
sendPacket.invoke(connection, packetTypeConstructor.newInstance(serialized, typeObj));
} catch (Exception ex) {
Log.d("Json发包错误 " + version, ex);
}