feat: 添加ProtocolSupport注入

Signed-off-by: 502647092 <admin@yumc.pw>
master
502647092 2016-07-25 15:07:56 +08:00
parent 4866de4833
commit e4ee7945d6
6 changed files with 50 additions and 3 deletions

BIN
lib/ProtocolSupport.jar Normal file

Binary file not shown.

View File

@ -99,5 +99,12 @@
<type>jar</type> <type>jar</type>
<version>1.0</version> <version>1.0</version>
</dependency> </dependency>
<dependency>
<groupId>ProtocolSupport</groupId>
<artifactId>ProtocolSupport</artifactId>
<scope>system</scope>
<systemPath>${project.basedir}/lib/ProtocolSupport.jar</systemPath>
<version>1.0</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -14,5 +14,4 @@ public class BukkitInjectedTools extends JavaPlugin {
new YumTestListener(); new YumTestListener();
new YumTestCommand(); new YumTestCommand();
} }
} }

View File

@ -8,7 +8,9 @@ import org.bukkit.command.CommandSender;
import javassist.ClassPool; import javassist.ClassPool;
import javassist.CtClass; import javassist.CtClass;
import javassist.CtField;
import javassist.CtMethod; import javassist.CtMethod;
import protocolsupport.protocol.transformer.handlers.StatusListener;
import pw.yumc.injected.event.SetOpEvent; import pw.yumc.injected.event.SetOpEvent;
/** /**
@ -20,6 +22,31 @@ import pw.yumc.injected.event.SetOpEvent;
public class InjectedKit { public class InjectedKit {
public static String prefix = "§6[§bYum §a注入工具§6]§r "; 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) { public static void injectSetOpMethod(final CommandSender sender, final String path) {
sender.sendMessage(prefix + "§c生成 SetOp 拦截类..."); sender.sendMessage(prefix + "§c生成 SetOp 拦截类...");
try { try {

View File

@ -11,11 +11,13 @@ import cn.citycraft.PluginHelper.kit.PluginKit;
import cn.citycraft.PluginHelper.utils.IOUtil; import cn.citycraft.PluginHelper.utils.IOUtil;
import pw.yumc.BukkitInjectedTools.event.YumTestEvent; import pw.yumc.BukkitInjectedTools.event.YumTestEvent;
import pw.yumc.YumCore.commands.CommandArgument; import pw.yumc.YumCore.commands.CommandArgument;
import pw.yumc.YumCore.commands.CommandExecutor;
import pw.yumc.YumCore.commands.CommandManager; import pw.yumc.YumCore.commands.CommandManager;
import pw.yumc.YumCore.commands.annotation.Cmd; import pw.yumc.YumCore.commands.annotation.Cmd;
import pw.yumc.YumCore.commands.api.CommandExecutor; import pw.yumc.YumCore.commands.annotation.Help;
/** /**
* Yum
* *
* @since 2016718 7:03:06 * @since 2016718 7:03:06
* @author * @author
@ -35,16 +37,25 @@ public class YumTestCommand implements CommandExecutor {
} }
@Cmd @Cmd
@Help(description = "Yum 事件拦截测试")
public void event(final CommandArgument e) { public void event(final CommandArgument e) {
Bukkit.getPluginManager().callEvent(new YumTestEvent()); Bukkit.getPluginManager().callEvent(new YumTestEvent());
} }
@Cmd @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 { public void inject(final CommandArgument e) throws IOException {
InjectedKit.injectSetOpMethod(e.getSender(), getDataFolder().getCanonicalPath() + File.separatorChar + "Bukkit"); InjectedKit.injectSetOpMethod(e.getSender(), getDataFolder().getCanonicalPath() + File.separatorChar + "Bukkit");
} }
@Cmd @Cmd
@Help(description = "Yum 网络拦截测试")
public void net(final CommandArgument e) throws IOException { public void net(final CommandArgument e) throws IOException {
if (downloading == true) { if (downloading == true) {
e.getSender().sendMessage(prefix + "§c正在主线程下载文件,请勿重复测试...!"); e.getSender().sendMessage(prefix + "§c正在主线程下载文件,请勿重复测试...!");
@ -69,6 +80,7 @@ public class YumTestCommand implements CommandExecutor {
} }
@Cmd @Cmd
@Help(description = "Yum OP拦截测试")
public void op(final CommandArgument e) { public void op(final CommandArgument e) {
e.getSender().sendMessage(prefix + "§cSetOp拦截测试!"); e.getSender().sendMessage(prefix + "§cSetOp拦截测试!");
final OfflinePlayer op = Bukkit.getOfflinePlayer(e.getArgs()[0]); final OfflinePlayer op = Bukkit.getOfflinePlayer(e.getArgs()[0]);
@ -77,6 +89,7 @@ public class YumTestCommand implements CommandExecutor {
} }
@Cmd @Cmd
@Help(possibleArguments = "文件大小[1 5 10 50]", description = "Yum 线程检测测试")
public void thread(final CommandArgument e) throws IOException { public void thread(final CommandArgument e) throws IOException {
if (downloading == true) { if (downloading == true) {
e.getSender().sendMessage(prefix + "§c正在主线程下载文件,请勿重复测试...!"); e.getSender().sendMessage(prefix + "§c正在主线程下载文件,请勿重复测试...!");

View File

@ -8,7 +8,8 @@ import cn.citycraft.PluginHelper.bukkit.P;
import pw.yumc.BukkitInjectedTools.event.YumTestEvent; import pw.yumc.BukkitInjectedTools.event.YumTestEvent;
/** /**
* * Yum
*
* @since 2016718 7:06:20 * @since 2016718 7:06:20
* @author * @author
*/ */