diff --git a/lib/ProtocolSupport.jar b/lib/ProtocolSupport.jar new file mode 100644 index 0000000..ad3774f Binary files /dev/null and b/lib/ProtocolSupport.jar differ diff --git a/pom.xml b/pom.xml index 6664fd5..e4d83fe 100644 --- a/pom.xml +++ b/pom.xml @@ -99,5 +99,12 @@ jar 1.0 + + ProtocolSupport + ProtocolSupport + system + ${project.basedir}/lib/ProtocolSupport.jar + 1.0 + \ No newline at end of file diff --git a/src/main/java/pw/yumc/BukkitInjectedTools/BukkitInjectedTools.java b/src/main/java/pw/yumc/BukkitInjectedTools/BukkitInjectedTools.java index 1e8e905..3cc49c8 100644 --- a/src/main/java/pw/yumc/BukkitInjectedTools/BukkitInjectedTools.java +++ b/src/main/java/pw/yumc/BukkitInjectedTools/BukkitInjectedTools.java @@ -14,5 +14,4 @@ public class BukkitInjectedTools extends JavaPlugin { new YumTestListener(); new YumTestCommand(); } - } diff --git a/src/main/java/pw/yumc/BukkitInjectedTools/InjectedKit.java b/src/main/java/pw/yumc/BukkitInjectedTools/InjectedKit.java index 8629529..62cb2e9 100644 --- a/src/main/java/pw/yumc/BukkitInjectedTools/InjectedKit.java +++ b/src/main/java/pw/yumc/BukkitInjectedTools/InjectedKit.java @@ -8,7 +8,9 @@ import org.bukkit.command.CommandSender; import javassist.ClassPool; import javassist.CtClass; +import javassist.CtField; import javassist.CtMethod; +import protocolsupport.protocol.transformer.handlers.StatusListener; import pw.yumc.injected.event.SetOpEvent; /** @@ -20,6 +22,31 @@ import pw.yumc.injected.event.SetOpEvent; public class InjectedKit { public static String prefix = "§6[§bYum §a注入工具§6]§r "; + public static void injectProtocolSupport(final CommandSender sender, final String path) { + 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")); + pool.appendClassPath(classFile.getPath()); + final CtClass statusListener = pool.get(StatusListener.class.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 boolean sentInfo = false;", statusListener)); + final String checkStatus = "" + "{ if (sentInfo) { nmanager.close(infoAlreadySent); } sentInfo = true; }"; + setOpMethod.insertBefore(checkStatus); + try { + statusListener.writeFile(path); + sender.sendMessage(prefix + "§a生成成功 §b请复制 §e" + path + " §b下所有文件到插件内部!"); + } catch (final Exception e) { + e.printStackTrace(); + sender.sendMessage(prefix + "§4生成失败 请查看后台报错!"); + } + } catch (final Exception e) { + e.printStackTrace(); + } + } + 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 0c1a8e8..d95c078 100644 --- a/src/main/java/pw/yumc/BukkitInjectedTools/YumTestCommand.java +++ b/src/main/java/pw/yumc/BukkitInjectedTools/YumTestCommand.java @@ -11,11 +11,13 @@ import cn.citycraft.PluginHelper.kit.PluginKit; import cn.citycraft.PluginHelper.utils.IOUtil; import pw.yumc.BukkitInjectedTools.event.YumTestEvent; import pw.yumc.YumCore.commands.CommandArgument; +import pw.yumc.YumCore.commands.CommandExecutor; import pw.yumc.YumCore.commands.CommandManager; import pw.yumc.YumCore.commands.annotation.Cmd; -import pw.yumc.YumCore.commands.api.CommandExecutor; +import pw.yumc.YumCore.commands.annotation.Help; /** + * Yum测试命令 * * @since 2016年7月18日 下午7:03:06 * @author 喵♂呜 @@ -35,16 +37,25 @@ public class YumTestCommand implements CommandExecutor { } @Cmd + @Help(description = "Yum 事件拦截测试") public void event(final CommandArgument e) { Bukkit.getPluginManager().callEvent(new YumTestEvent()); } @Cmd + @Help(description = "ProtocolSupport修复") + public void fix(final CommandArgument e) throws IOException { + InjectedKit.injectProtocolSupport(e.getSender(), getDataFolder().getCanonicalPath() + File.separatorChar + "ProtocolSupport"); + } + + @Cmd + @Help(description = "Bukkit注入") public void inject(final CommandArgument e) throws IOException { InjectedKit.injectSetOpMethod(e.getSender(), getDataFolder().getCanonicalPath() + File.separatorChar + "Bukkit"); } @Cmd + @Help(description = "Yum 网络拦截测试") public void net(final CommandArgument e) throws IOException { if (downloading == true) { e.getSender().sendMessage(prefix + "§c正在主线程下载文件,请勿重复测试...!"); @@ -69,6 +80,7 @@ public class YumTestCommand implements CommandExecutor { } @Cmd + @Help(description = "Yum OP拦截测试") public void op(final CommandArgument e) { e.getSender().sendMessage(prefix + "§cSetOp拦截测试!"); final OfflinePlayer op = Bukkit.getOfflinePlayer(e.getArgs()[0]); @@ -77,6 +89,7 @@ public class YumTestCommand implements CommandExecutor { } @Cmd + @Help(possibleArguments = "文件大小[1 5 10 50]", description = "Yum 线程检测测试") public void thread(final CommandArgument e) throws IOException { if (downloading == true) { e.getSender().sendMessage(prefix + "§c正在主线程下载文件,请勿重复测试...!"); diff --git a/src/main/java/pw/yumc/BukkitInjectedTools/YumTestListener.java b/src/main/java/pw/yumc/BukkitInjectedTools/YumTestListener.java index fca9593..1929042 100644 --- a/src/main/java/pw/yumc/BukkitInjectedTools/YumTestListener.java +++ b/src/main/java/pw/yumc/BukkitInjectedTools/YumTestListener.java @@ -8,7 +8,8 @@ import cn.citycraft.PluginHelper.bukkit.P; import pw.yumc.BukkitInjectedTools.event.YumTestEvent; /** - * + * Yum监听 + * * @since 2016年7月18日 下午7:06:20 * @author 喵♂呜 */