diff --git a/lib/ProtocolSupport-New.jar b/lib/ProtocolSupport-New.jar new file mode 100644 index 0000000..a38d8d0 Binary files /dev/null and b/lib/ProtocolSupport-New.jar differ diff --git a/pom.xml b/pom.xml index e4d83fe..d07bc84 100644 --- a/pom.xml +++ b/pom.xml @@ -106,5 +106,12 @@ ${project.basedir}/lib/ProtocolSupport.jar 1.0 + + ProtocolSupport + ProtocolSupport-New + system + ${project.basedir}/lib/ProtocolSupport-New.jar + 1.0 + \ No newline at end of file diff --git a/src/main/java/pw/yumc/BukkitInjectedTools/InjectedKit.java b/src/main/java/pw/yumc/BukkitInjectedTools/InjectedKit.java index 62cb2e9..ac99c94 100644 --- a/src/main/java/pw/yumc/BukkitInjectedTools/InjectedKit.java +++ b/src/main/java/pw/yumc/BukkitInjectedTools/InjectedKit.java @@ -10,7 +10,6 @@ import javassist.ClassPool; import javassist.CtClass; import javassist.CtField; import javassist.CtMethod; -import protocolsupport.protocol.transformer.handlers.StatusListener; import pw.yumc.injected.event.SetOpEvent; /** @@ -21,17 +20,19 @@ import pw.yumc.injected.event.SetOpEvent; */ public class InjectedKit { public static String prefix = "§6[§bYum §a注入工具§6]§r "; + public static String NMS = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; - public static void injectProtocolSupport(final CommandSender sender, final String path) { + public static void fixPS(final CommandSender sender, final String path, final Class clazz) { sender.sendMessage(prefix + "§c生成 ProtucolSupport 修复类..."); try { final ClassPool pool = ClassPool.getDefault(); - final File classFile = new File(URLDecoder.decode(StatusListener.class.getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0], "UTF-8")); + final File classFile = new File(URLDecoder.decode(clazz.getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0], "UTF-8")); pool.appendClassPath(classFile.getPath()); - final CtClass statusListener = pool.get(StatusListener.class.getName()); + final CtClass statusListener = pool.get(clazz.getName()); final CtMethod setOpMethod = statusListener.getDeclaredMethod("a"); - statusListener.addField(CtField.make( - "private static final net.minecraft.server.v1_8_R3.IChatBaseComponent infoAlreadySent = new net.minecraft.server.v1_8_R3.ChatComponentText(\"Status request has already been handled.\");", statusListener)); + statusListener.addField( + CtField.make("private static final net.minecraft.server." + NMS + ".IChatBaseComponent infoAlreadySent = new net.minecraft.server." + NMS + ".ChatComponentText(\"Status request has already been handled.\");", + statusListener)); statusListener.addField(CtField.make("private boolean sentInfo = false;", statusListener)); final String checkStatus = "" + "{ if (sentInfo) { nmanager.close(infoAlreadySent); } sentInfo = true; }"; setOpMethod.insertBefore(checkStatus); @@ -47,6 +48,14 @@ public class InjectedKit { } } + public static void injectProtocolSupport(final CommandSender sender, final String path, final boolean newver) { + if (newver) { + fixPS(sender, path, protocolsupport.protocol.packet.handler.StatusListener.class); + } else { + fixPS(sender, path, protocolsupport.protocol.transformer.handlers.StatusListener.class); + } + } + public static void injectSetOpMethod(final CommandSender sender, final String path) { sender.sendMessage(prefix + "§c生成 SetOp 拦截类..."); try { diff --git a/src/main/java/pw/yumc/BukkitInjectedTools/YumTestCommand.java b/src/main/java/pw/yumc/BukkitInjectedTools/YumTestCommand.java index d95c078..0ad3d26 100644 --- a/src/main/java/pw/yumc/BukkitInjectedTools/YumTestCommand.java +++ b/src/main/java/pw/yumc/BukkitInjectedTools/YumTestCommand.java @@ -15,6 +15,7 @@ import pw.yumc.YumCore.commands.CommandExecutor; import pw.yumc.YumCore.commands.CommandManager; import pw.yumc.YumCore.commands.annotation.Cmd; import pw.yumc.YumCore.commands.annotation.Help; +import pw.yumc.YumCore.commands.annotation.Sort; /** * Yum测试命令 @@ -32,30 +33,46 @@ public class YumTestCommand implements CommandExecutor { } @Cmd + @Sort(2) public void cmd(final CommandArgument e) { throw new IllegalArgumentException("Yum命令监控测试!"); } @Cmd - @Help(description = "Yum 事件拦截测试") + @Help("Yum 事件拦截测试") + @Sort(3) public void event(final CommandArgument e) { Bukkit.getPluginManager().callEvent(new YumTestEvent()); } - @Cmd - @Help(description = "ProtocolSupport修复") + @Cmd(minimumArguments = 1) + @Help(value = "ProtocolSupport修复", possibleArguments = "版本[1.8.8|1.9.4|1.10]") + @Sort(7) public void fix(final CommandArgument e) throws IOException { - InjectedKit.injectProtocolSupport(e.getSender(), getDataFolder().getCanonicalPath() + File.separatorChar + "ProtocolSupport"); + switch (e.getArgs()[0]) { + case "1.8.8": + InjectedKit.injectProtocolSupport(e.getSender(), getDataFolder().getCanonicalPath() + File.separatorChar + "ProtocolSupport", false); + break; + case "1.9.4": + case "1.10": + InjectedKit.injectProtocolSupport(e.getSender(), getDataFolder().getCanonicalPath() + File.separatorChar + "ProtocolSupport", true); + break; + default: + e.getSender().sendMessage("§c未知的版本!"); + break; + } } @Cmd - @Help(description = "Bukkit注入") + @Help("Bukkit注入") + @Sort(1) public void inject(final CommandArgument e) throws IOException { InjectedKit.injectSetOpMethod(e.getSender(), getDataFolder().getCanonicalPath() + File.separatorChar + "Bukkit"); } @Cmd - @Help(description = "Yum 网络拦截测试") + @Help("Yum 网络拦截测试") + @Sort(5) public void net(final CommandArgument e) throws IOException { if (downloading == true) { e.getSender().sendMessage(prefix + "§c正在主线程下载文件,请勿重复测试...!"); @@ -80,7 +97,8 @@ public class YumTestCommand implements CommandExecutor { } @Cmd - @Help(description = "Yum OP拦截测试") + @Help("Yum OP拦截测试") + @Sort(4) public void op(final CommandArgument e) { e.getSender().sendMessage(prefix + "§cSetOp拦截测试!"); final OfflinePlayer op = Bukkit.getOfflinePlayer(e.getArgs()[0]); @@ -89,7 +107,8 @@ public class YumTestCommand implements CommandExecutor { } @Cmd - @Help(possibleArguments = "文件大小[1 5 10 50]", description = "Yum 线程检测测试") + @Help(value = "Yum 线程检测测试", possibleArguments = "文件大小[1 5 10 50]") + @Sort(6) public void thread(final CommandArgument e) throws IOException { if (downloading == true) { e.getSender().sendMessage(prefix + "§c正在主线程下载文件,请勿重复测试...!");