1
0
mirror of https://e.coding.net/circlecloud/BukkitInjectedTools.git synced 2024-11-24 01:58:50 +00:00

feat: 支持修复ProtocolSupport新旧版本

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-07-25 16:43:31 +08:00
parent e4ee7945d6
commit dba7ca7556
4 changed files with 49 additions and 14 deletions

BIN
lib/ProtocolSupport-New.jar Normal file

Binary file not shown.

View File

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

View File

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

View File

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