mirror of
https://e.coding.net/circlecloud/YumCore.git
synced 2024-11-21 01:38:51 +00:00
对兼容类添加1.11+,Uranium,Cauldron和1.7支持
This commit is contained in:
parent
2ca0872f7c
commit
ebdd574cda
@ -48,41 +48,85 @@ public class C {
|
||||
private static Object[] chatMessageTypes;
|
||||
|
||||
public static boolean init;
|
||||
public static boolean cauldron;
|
||||
public static boolean uranium;
|
||||
public static boolean titlePAB;
|
||||
static {
|
||||
try {
|
||||
version = getNMSVersion();
|
||||
newversion = Integer.parseInt(version.split("_")[1]) > 7;
|
||||
nmsChatSerializer = Class.forName(a(newversion ? "IChatBaseComponent$ChatSerializer" : "ChatSerializer"));
|
||||
chatSerializer = nmsChatSerializer.getMethod("a", String.class);
|
||||
nmsIChatBaseComponent = Class.forName(a("IChatBaseComponent"));
|
||||
packetType = Class.forName(a("PacketPlayOutChat"));
|
||||
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);
|
||||
version=getNMSVersion();
|
||||
titlePAB=false;
|
||||
if(version.equals("v1_7_R4")&&Package.getPackage("net.minecraftforge.cauldron")!=null) {
|
||||
try{
|
||||
Class.forName("cc.uraniummc.Uranium");
|
||||
uranium=true;
|
||||
}catch (Exception e){
|
||||
Log.d("检测到不是Uranium服务端");
|
||||
}
|
||||
try {
|
||||
cauldron=true;
|
||||
nmsChatSerializer = Class.forName("net.minecraft.util.IChatComponent$Serializer");
|
||||
chatSerializer = nmsChatSerializer.getMethod("func_150699_a", String.class);
|
||||
nmsIChatBaseComponent = Class.forName("net.minecraft.util.IChatComponent");
|
||||
packetType = Class.forName("net.minecraft.network.play.server.S02PacketChat");
|
||||
Arrays.stream(packetType.getConstructors()).forEach(c -> {
|
||||
if (c.getParameterTypes().length == 2) {
|
||||
packetTypeConstructor = c;
|
||||
}
|
||||
});
|
||||
nmsChatMessageTypeClass = packetTypeConstructor.getParameterTypes()[1];
|
||||
if (nmsChatMessageTypeClass.isEnum()) {
|
||||
chatMessageTypes = nmsChatMessageTypeClass.getEnumConstants();
|
||||
} else if(uranium) {
|
||||
titlePAB=true;
|
||||
}
|
||||
Class<?> typeCraftPlayer = Class.forName(b("entity.CraftPlayer"));
|
||||
Class<?> typeNMSPlayer = Class.forName("net.minecraft.entity.player.EntityPlayerMP");
|
||||
Class<?> typePlayerConnection = Class.forName("net.minecraft.network.NetHandlerPlayServer");
|
||||
getHandle = typeCraftPlayer.getMethod("getHandle");
|
||||
playerConnection = typeNMSPlayer.getField("field_71135_a");
|
||||
sendPacket = typePlayerConnection.getMethod("func_147359_a", Class.forName("net.minecraft.network.Packet"));
|
||||
init = true;
|
||||
} catch (Exception e) {
|
||||
Log.w("C(Cauldron_1710) 兼容性工具初始化失败 可能造成部分功能不可用!");
|
||||
Log.d(e);
|
||||
}
|
||||
}else {
|
||||
try {
|
||||
version = getNMSVersion();
|
||||
newversion = Integer.parseInt(version.split("_")[1]) > 7;
|
||||
nmsChatSerializer = Class.forName(a(newversion ? "IChatBaseComponent$ChatSerializer" : "ChatSerializer"));
|
||||
chatSerializer = nmsChatSerializer.getMethod("a", String.class);
|
||||
nmsIChatBaseComponent = Class.forName(a("IChatBaseComponent"));
|
||||
packetType = Class.forName(a("PacketPlayOutChat"));
|
||||
Arrays.stream(packetType.getConstructors()).forEach(c -> {
|
||||
if (c.getParameterTypes().length == 2) {
|
||||
packetTypeConstructor = c;
|
||||
}
|
||||
});
|
||||
nmsChatMessageTypeClass = packetTypeConstructor.getParameterTypes()[1];
|
||||
if (nmsChatMessageTypeClass.isEnum()) {
|
||||
chatMessageTypes = nmsChatMessageTypeClass.getEnumConstants();
|
||||
} else {
|
||||
if(newversion) {
|
||||
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"));
|
||||
Class<?> typePlayerConnection = Class.forName(a("PlayerConnection"));
|
||||
getHandle = typeCraftPlayer.getMethod("getHandle");
|
||||
playerConnection = typeNMSPlayer.getField("playerConnection");
|
||||
sendPacket = typePlayerConnection.getMethod("sendPacket", Class.forName(a("Packet")));
|
||||
init = true;
|
||||
} catch (Exception e) {
|
||||
Log.w("C 兼容性工具初始化失败 可能造成部分功能不可用!");
|
||||
Log.d(e);
|
||||
}
|
||||
Class<?> typeCraftPlayer = Class.forName(b("entity.CraftPlayer"));
|
||||
Class<?> typeNMSPlayer = Class.forName(a("EntityPlayer"));
|
||||
Class<?> typePlayerConnection = Class.forName(a("PlayerConnection"));
|
||||
getHandle = typeCraftPlayer.getMethod("getHandle");
|
||||
playerConnection = typeNMSPlayer.getField("playerConnection");
|
||||
sendPacket = typePlayerConnection.getMethod("sendPacket", Class.forName(a("Packet")));
|
||||
init = true;
|
||||
} catch (Exception e) {
|
||||
Log.w("C 兼容性工具初始化失败 可能造成部分功能不可用!");
|
||||
Log.d(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,7 +167,17 @@ public class C {
|
||||
Object serialized = chatSerializer.invoke(null, json);
|
||||
Object player = getHandle.invoke(receivingPacket);
|
||||
Object connection = playerConnection.get(player);
|
||||
Object typeObj = chatMessageTypes == null ? nmsChatMessageTypeClassValueOf.invoke(null, String.valueOf(type)) : chatMessageTypes[type];
|
||||
Object typeObj;
|
||||
if(titlePAB){
|
||||
sendPacket.invoke(connection,Title.packetTitleSendConstructor.newInstance(Title.actions[2],serialized));
|
||||
return;
|
||||
}else {
|
||||
if (!newversion) {
|
||||
typeObj = true;
|
||||
} else {
|
||||
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);
|
||||
@ -328,14 +382,35 @@ public class C {
|
||||
private static Constructor<?> packetTitleSetTimeConstructor;
|
||||
private static Object[] actions;
|
||||
static {
|
||||
try {
|
||||
packetActions = Class.forName(a(newversion ? "PacketPlayOutTitle$EnumTitleAction" : "EnumTitleAction"));
|
||||
packetTitle = Class.forName(a("PacketPlayOutTitle"));
|
||||
packetTitleSendConstructor = packetTitle.getConstructor(packetActions, nmsIChatBaseComponent);
|
||||
packetTitleSetTimeConstructor = packetTitle.getConstructor(packetActions, nmsIChatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE);
|
||||
actions = packetActions.getEnumConstants();
|
||||
} catch (Exception ignore) {
|
||||
Log.w("Title 兼容性工具初始化失败 可能造成部分功能不可用!");
|
||||
if(cauldron&&uranium) {
|
||||
try {
|
||||
packetActions = Class.forName("cc.uraniummc.packet.S45PacketTitle$Type");
|
||||
packetTitle = Class.forName("cc.uraniummc.packet.S45PacketTitle");
|
||||
packetTitleSendConstructor = packetTitle.getConstructor(packetActions, nmsIChatBaseComponent);
|
||||
packetTitleSetTimeConstructor = packetTitle.getConstructor(packetActions, nmsIChatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE);
|
||||
actions = packetActions.getEnumConstants();
|
||||
} catch (Exception ignore) {
|
||||
titlePAB=false;
|
||||
Log.w("Title(Uranium 1.7.10) 兼容性工具初始化失败 可能造成部分功能不可用!");
|
||||
Log.d(ignore);
|
||||
}
|
||||
}else {
|
||||
try {
|
||||
packetActions = Class.forName(a(newversion ? "PacketPlayOutTitle$EnumTitleAction" : "EnumTitleAction"));
|
||||
packetTitle = Class.forName(a("PacketPlayOutTitle"));
|
||||
packetTitleSendConstructor = packetTitle.getConstructor(packetActions, nmsIChatBaseComponent);
|
||||
packetTitleSetTimeConstructor = packetTitle.getConstructor(packetActions, nmsIChatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE);
|
||||
actions = packetActions.getEnumConstants();
|
||||
for(Object data:actions){
|
||||
Enum enum_=(Enum)data;
|
||||
if(enum_.name().equals("ACTIONBAR")){
|
||||
titlePAB=true;
|
||||
}
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
Log.w("Title 兼容性工具初始化失败 可能造成部分功能不可用!");
|
||||
Log.d(ignore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -406,7 +481,7 @@ public class C {
|
||||
// Send timings first
|
||||
Object player = getHandle.invoke(recoverPlayer);
|
||||
Object connection = playerConnection.get(player);
|
||||
Object packet = packetTitleSendConstructor.newInstance(actions[4], null);
|
||||
Object packet = packetTitleSendConstructor.newInstance(titlePAB?actions[5]:actions[4], null);
|
||||
sendPacket.invoke(connection, packet);
|
||||
}
|
||||
|
||||
@ -453,7 +528,7 @@ public class C {
|
||||
Object packet;
|
||||
// Send if set
|
||||
if ((fadeInTime != -1) && (fadeOutTime != -1) && (stayTime != -1)) {
|
||||
packet = packetTitleSetTimeConstructor.newInstance(actions[2], null, fadeInTime * 20, stayTime * 20, fadeOutTime * 20);
|
||||
packet = packetTitleSetTimeConstructor.newInstance(titlePAB?actions[3]:actions[2], null, fadeInTime * 20, stayTime * 20, fadeOutTime * 20);
|
||||
sendPacket.invoke(connection, packet);
|
||||
}
|
||||
// Send title
|
||||
|
Loading…
Reference in New Issue
Block a user