1
0
mirror of https://e.coding.net/circlecloud/BukkitInjectedTools.git synced 2024-11-22 01:48:45 +00:00

feat: 添加监控拦截测试命令

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-07-18 20:37:23 +08:00
parent 140f506c87
commit d2126b4860
4 changed files with 181 additions and 80 deletions

View File

@ -1,95 +1,18 @@
package pw.yumc.BukkitInjectedTools;
import java.io.File;
import java.io.IOException;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.java.JavaPlugin;
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.PluginKit;
import cn.citycraft.PluginHelper.utils.IOUtil;
/**
* Bukkit 注入工具类
*
* @since 2016年3月31日 下午7:36:20
* @author
*/
public class BukkitInjectedTools extends JavaPlugin implements HandlerCommands {
private final String prefix = "§6[§bYum §a注入工具§6]§r ";
private boolean downloading = false;
private String nfn = "null";
@HandlerCommand(name = "inject")
public void inject(final InvokeCommandEvent e) throws IOException {
InjectedKit.injectSetOpMethod(e.getSender(), this.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;
}
});
}
public class BukkitInjectedTools extends JavaPlugin {
@Override
public void onEnable() {
final InvokeSubCommand isc = new InvokeSubCommand(this, "BukkitInjectedTools");
isc.registerCommands(this);
new YumTestListener();
new YumTestCommand();
}
@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;
}
});
}
}

View File

@ -0,0 +1,108 @@
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();
}
}

View File

@ -0,0 +1,23 @@
package pw.yumc.BukkitInjectedTools;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import cn.citycraft.PluginHelper.kit.PKit;
/**
*
* @since 2016年7月18日 下午7:06:20
* @author
*/
public class YumTestListener implements Listener {
public YumTestListener() {
Bukkit.getPluginManager().registerEvents(this, PKit.i());
}
@EventHandler
public void onCommand(final YumTestListener e) {
throw new IllegalArgumentException("Yum事件监控测试!");
}
}

View File

@ -0,0 +1,47 @@
package pw.yumc.BukkitInjectedTools.event;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Yum事件测试类
*
* @since 2016年7月18日 下午7:07:37
* @author
*/
public class YumTestEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final boolean value;
private boolean cancel = false;
public YumTestEvent(final boolean value) {
this.value = value;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancel;
}
/**
* @return value
*/
public boolean isValue() {
return value;
}
@Override
public void setCancelled(final boolean arg0) {
cancel = arg0;
}
}