9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-29 03:49:07 +00:00

Back up for big changes

This commit is contained in:
XiaoMoMi
2024-05-11 03:33:31 +08:00
parent f83281a2a1
commit f19d0e05c5
75 changed files with 533 additions and 682 deletions

View File

@@ -37,22 +37,7 @@ public class ReflectionUtils {
public static Class<?> bukkitClass;
public static void load() {
// spigot map
try {
Class<?> bar = Class.forName("net.minecraft.network.protocol.game.PacketPlayOutBoss");
Field remove = bar.getDeclaredField("f");
remove.setAccessible(true);
removeBossBarPacket = remove.get(null);
Class<?> packetBossClassF = Class.forName("net.minecraft.network.protocol.game.PacketPlayOutBoss$f");
progressConstructor = packetBossClassF.getDeclaredConstructor(float.class);
progressConstructor.setAccessible(true);
Class<?> packetBossClassE = Class.forName("net.minecraft.network.protocol.game.PacketPlayOutBoss$e");
updateConstructor = packetBossClassE.getDeclaredConstructor(MinecraftReflection.getIChatBaseComponentClass());
updateConstructor.setAccessible(true);
iChatComponentMethod = MinecraftReflection.getChatSerializerClass().getMethod("a", String.class);
iChatComponentMethod.setAccessible(true);
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException | NoSuchMethodException e1) {
// mojmap
if (CustomFishingPlugin.get().getVersionManager().isMojmap()) {
try {
Class<?> bar = Class.forName("net.minecraft.network.protocol.game.ClientboundBossEventPacket");
Field remove = bar.getDeclaredField("REMOVE_OPERATION");
@@ -64,13 +49,29 @@ public class ReflectionUtils {
Class<?> packetBossClassE = Class.forName("net.minecraft.network.protocol.game.ClientboundBossEventPacket$UpdateNameOperation");
updateConstructor = packetBossClassE.getDeclaredConstructor(MinecraftReflection.getIChatBaseComponentClass());
updateConstructor.setAccessible(true);
iChatComponentMethod = MinecraftReflection.getChatSerializerClass().getMethod("fromJson", String.class);
Class<?> craftChatMessageClass = Class.forName("org.bukkit.craftbukkit.util.CraftChatMessage");
iChatComponentMethod = craftChatMessageClass.getDeclaredMethod("fromJSON", String.class);
iChatComponentMethod.setAccessible(true);
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException | NoSuchMethodException e2) {
LogUtils.severe("Error occurred when loading reflections", e2);
e2.printStackTrace();
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException | NoSuchMethodException exception) {
LogUtils.severe("Error occurred when loading reflections", exception);
}
} else {
try {
Class<?> bar = Class.forName("net.minecraft.network.protocol.game.PacketPlayOutBoss");
Field remove = bar.getDeclaredField("f");
remove.setAccessible(true);
removeBossBarPacket = remove.get(null);
Class<?> packetBossClassF = Class.forName("net.minecraft.network.protocol.game.PacketPlayOutBoss$f");
progressConstructor = packetBossClassF.getDeclaredConstructor(float.class);
progressConstructor.setAccessible(true);
Class<?> packetBossClassE = Class.forName("net.minecraft.network.protocol.game.PacketPlayOutBoss$e");
updateConstructor = packetBossClassE.getDeclaredConstructor(MinecraftReflection.getIChatBaseComponentClass());
updateConstructor.setAccessible(true);
iChatComponentMethod = MinecraftReflection.getChatSerializerClass().getMethod("a", String.class);
iChatComponentMethod.setAccessible(true);
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException | NoSuchMethodException exception) {
LogUtils.severe("Error occurred when loading reflections", exception);
}
return;
}
if (CustomFishingPlugin.get().getVersionManager().isSpigot()) return;
try {
@@ -82,11 +83,8 @@ public class ReflectionUtils {
gsonInstance = gsonMethod.invoke(null);
gsonDeserializeMethod = gsonComponentSerializerImplClass.getMethod("deserialize", String.class);
gsonDeserializeMethod.setAccessible(true);
} catch (ClassNotFoundException exception) {
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException exception) {
LogUtils.severe("Error occurred when loading reflections", exception);
exception.printStackTrace();
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}