1
0
mirror of https://e.coding.net/circlecloud/BukkitInjectedTools.git synced 2024-11-21 01:38:47 +00:00

feat: 添加ProtocolSupport注入

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
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>
<version>1.0</version>
</dependency>
<dependency>
<groupId>ProtocolSupport</groupId>
<artifactId>ProtocolSupport</artifactId>
<scope>system</scope>
<systemPath>${project.basedir}/lib/ProtocolSupport.jar</systemPath>
<version>1.0</version>
</dependency>
</dependencies>
</project>

View File

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

View File

@ -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 {

View File

@ -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正在主线程下载文件,请勿重复测试...!");

View File

@ -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
*/