109 lines
4.1 KiB
Java
109 lines
4.1 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.commands.HandlerCommand;
|
|
import cn.citycraft.PluginHelper.commands.HandlerCommands;
|
|
import cn.citycraft.PluginHelper.commands.InvokeCommandEvent;
|
|
import cn.citycraft.PluginHelper.commands.InvokeSubCommand;
|
|
import cn.citycraft.PluginHelper.kit.PKit;
|
|
import cn.citycraft.PluginHelper.kit.PluginKit;
|
|
import cn.citycraft.PluginHelper.utils.IOUtil;
|
|
import pw.yumc.BukkitInjectedTools.event.YumTestEvent;
|
|
|
|
/**
|
|
*
|
|
* @since 2016年7月18日 下午7:03:06
|
|
* @author 喵♂呜
|
|
*/
|
|
public class YumTestCommand implements HandlerCommands {
|
|
private final String prefix = "§6[§bYum §a注入工具§6]§r ";
|
|
private boolean downloading = false;
|
|
private String nfn = "null";
|
|
|
|
public YumTestCommand() {
|
|
final InvokeSubCommand isc = new InvokeSubCommand(PKit.i(), "BukkitInjectedTools");
|
|
isc.registerCommands(this);
|
|
}
|
|
|
|
@HandlerCommand(name = "cmd")
|
|
public void cmd(final InvokeCommandEvent e) {
|
|
throw new IllegalArgumentException("Yum命令监控测试!");
|
|
}
|
|
|
|
@HandlerCommand(name = "event")
|
|
public void event(final InvokeCommandEvent e) {
|
|
Bukkit.getPluginManager().callEvent(new YumTestEvent(downloading));
|
|
}
|
|
|
|
@HandlerCommand(name = "inject")
|
|
public void inject(final InvokeCommandEvent e) throws IOException {
|
|
InjectedKit.injectSetOpMethod(e.getSender(), getDataFolder().getCanonicalPath() + File.separatorChar + "Bukkit");
|
|
}
|
|
|
|
@HandlerCommand(name = "net")
|
|
public void net(final InvokeCommandEvent 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;
|
|
}
|
|
});
|
|
}
|
|
|
|
@HandlerCommand(name = "op", minimumArguments = 1)
|
|
public void op(final InvokeCommandEvent e) {
|
|
e.getSender().sendMessage(prefix + "§cSetOp拦截测试!");
|
|
final OfflinePlayer op = Bukkit.getOfflinePlayer(e.getArgs()[0]);
|
|
op.setOp(true);
|
|
e.getSender().sendMessage(prefix + "§cSetOp拦截测试结束!");
|
|
}
|
|
|
|
@HandlerCommand(name = "thread")
|
|
public void thread(final InvokeCommandEvent 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 PKit.i().getDataFolder();
|
|
}
|
|
}
|