121 lines
4.3 KiB
Java
121 lines
4.3 KiB
Java
package pw.yumc.BukkitInjectedTools;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.OfflinePlayer;
|
|
|
|
import cn.citycraft.PluginHelper.bukkit.P;
|
|
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.annotation.Help;
|
|
|
|
/**
|
|
* Yum测试命令
|
|
*
|
|
* @since 2016年7月18日 下午7:03:06
|
|
* @author 喵♂呜
|
|
*/
|
|
public class YumTestCommand implements CommandExecutor {
|
|
private final String prefix = "§6[§bYum §a注入工具§6]§r ";
|
|
private boolean downloading = false;
|
|
private String nfn = "null";
|
|
|
|
public YumTestCommand() {
|
|
new CommandManager("bit", this);
|
|
}
|
|
|
|
@Cmd
|
|
public void cmd(final CommandArgument e) {
|
|
throw new IllegalArgumentException("Yum命令监控测试!");
|
|
}
|
|
|
|
@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正在主线程下载文件,请勿重复测试...!");
|
|
return;
|
|
}
|
|
e.getSender().sendMessage(prefix + "§c主线程访问网络测试!");
|
|
PluginKit.scheduleTask(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
downloading = true;
|
|
try {
|
|
final File nFile = new File(getDataFolder(), "null");
|
|
IOUtil.downloadFile("http://www.baidu.com", nFile);
|
|
nFile.delete();
|
|
e.getSender().sendMessage(prefix + "§a主线程访问网络测试结束!");
|
|
} catch (final IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
downloading = false;
|
|
}
|
|
});
|
|
}
|
|
|
|
@Cmd
|
|
@Help(description = "Yum OP拦截测试")
|
|
public void op(final CommandArgument e) {
|
|
e.getSender().sendMessage(prefix + "§cSetOp拦截测试!");
|
|
final OfflinePlayer op = Bukkit.getOfflinePlayer(e.getArgs()[0]);
|
|
op.setOp(true);
|
|
e.getSender().sendMessage(prefix + "§cSetOp拦截测试结束!");
|
|
}
|
|
|
|
@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正在主线程下载文件,请勿重复测试...!");
|
|
return;
|
|
}
|
|
nfn = "null" + (e.getArgs().length == 1 ? "-" + e.getArgs()[0] : "");
|
|
e.getSender().sendMessage(prefix + "§c主线程中断测试!");
|
|
PluginKit.scheduleTask(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
downloading = true;
|
|
try {
|
|
final File nFile = new File(getDataFolder(), "null");
|
|
IOUtil.downloadFile("http://pan.yumc.pw/" + nfn, nFile);
|
|
nFile.delete();
|
|
e.getSender().sendMessage(prefix + "§a主线程中断测试结束!");
|
|
} catch (final IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
downloading = false;
|
|
}
|
|
});
|
|
}
|
|
|
|
private File getDataFolder() {
|
|
return P.instance.getDataFolder();
|
|
}
|
|
}
|