1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-11-24 02:08:48 +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 chatSerializer;
private static Method getHandle; private static Method getHandle;
private static Method nmsChatMessageTypeClassValueOf;
private static String version; private static String version;
private static boolean newversion; private static boolean newversion;
@ -44,7 +45,7 @@ public class C {
private static Field playerConnection; private static Field playerConnection;
private static Method sendPacket; private static Method sendPacket;
private static Object[] ChatMessageTypes; private static Object[] chatMessageTypes;
public static boolean init; public static boolean init;
static { static {
@ -55,12 +56,22 @@ public class C {
chatSerializer = nmsChatSerializer.getMethod("a", String.class); chatSerializer = nmsChatSerializer.getMethod("a", String.class);
nmsIChatBaseComponent = Class.forName(a("IChatBaseComponent")); nmsIChatBaseComponent = Class.forName(a("IChatBaseComponent"));
packetType = Class.forName(a("PacketPlayOutChat")); packetType = Class.forName(a("PacketPlayOutChat"));
try { Arrays.stream(packetType.getConstructors()).forEach(c -> {
nmsChatMessageTypeClass = Class.forName(a("ChatMessageType")); if (c.getParameterTypes().length == 2) {
ChatMessageTypes = nmsChatMessageTypeClass.getEnumConstants(); packetTypeConstructor = c;
packetTypeConstructor = packetType.getConstructor(nmsIChatBaseComponent, nmsChatMessageTypeClass); }
} catch (ClassNotFoundException ex) { });
packetTypeConstructor = packetType.getConstructor(nmsIChatBaseComponent, newversion ? int.class : byte.class); 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<?> typeCraftPlayer = Class.forName(b("entity.CraftPlayer"));
Class<?> typeNMSPlayer = Class.forName(a("EntityPlayer")); Class<?> typeNMSPlayer = Class.forName(a("EntityPlayer"));
@ -112,11 +123,8 @@ public class C {
Object serialized = chatSerializer.invoke(null, json); Object serialized = chatSerializer.invoke(null, json);
Object player = getHandle.invoke(receivingPacket); Object player = getHandle.invoke(receivingPacket);
Object connection = playerConnection.get(player); Object connection = playerConnection.get(player);
if (nmsChatMessageTypeClass != null) { Object typeObj = chatMessageTypes == null ? nmsChatMessageTypeClassValueOf.invoke(null, String.valueOf(type)) : chatMessageTypes[type];
sendPacket.invoke(connection, packetTypeConstructor.newInstance(serialized, ChatMessageTypes[type])); sendPacket.invoke(connection, packetTypeConstructor.newInstance(serialized, typeObj));
} else {
sendPacket.invoke(connection, packetTypeConstructor.newInstance(serialized, newversion ? type : (byte) type));
}
} catch (Exception ex) { } catch (Exception ex) {
Log.d("Json发包错误 " + version, ex); Log.d("Json发包错误 " + version, ex);
} }