feat: 添加手动注入命令

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-07-18 10:42:45 +08:00
parent c282213d02
commit d772899f26
5 changed files with 52 additions and 8 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>pw.yumc</groupId> <groupId>pw.yumc</groupId>
<artifactId>Yum</artifactId> <artifactId>Yum</artifactId>
<version>2.6.2</version> <version>2.6.3</version>
<name>Yum</name> <name>Yum</name>
<description>Minecraft 服务器插件管理系统</description> <description>Minecraft 服务器插件管理系统</description>
<build> <build>
@ -60,9 +60,10 @@
<properties> <properties>
<update.description>&amp;a全新 2.X 版本 更多守护与优化</update.description> <update.description>&amp;a全新 2.X 版本 更多守护与优化</update.description>
<update.changes> <update.changes>
&amp;e预告 &amp;6- &amp;e下个版本将加入从&amp;bBukkitDev&amp;e下载和更新...;
&amp;b2.6.3 &amp;6- &amp;a注入操作延时执行 防止部分任务未注册 添加手动注入...;
&amp;b2.6.2 &amp;6- &amp;d能耗监控添加忽略列表 &amp;3详见monitor.yml...; &amp;b2.6.2 &amp;6- &amp;d能耗监控添加忽略列表 &amp;3详见monitor.yml...;
&amp;b2.6.1 &amp;6- &amp;c优化能耗监控 命令别名修改为mi(防止与ESS冲突)...; &amp;b2.6.1 &amp;6- &amp;c优化能耗监控 命令别名修改为mi(防止与ESS冲突)...;
&amp;b2.6 &amp;6- &amp;a添加能耗监控系统 事件错误监控...;
</update.changes> </update.changes>
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT> <env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -26,6 +26,7 @@ import cn.citycraft.PluginHelper.commands.InvokeSubCommand;
import cn.citycraft.PluginHelper.ext.kit.Reflect; import cn.citycraft.PluginHelper.ext.kit.Reflect;
import cn.citycraft.PluginHelper.kit.StrKit; import cn.citycraft.PluginHelper.kit.StrKit;
import pw.yumc.Yum.Yum; import pw.yumc.Yum.Yum;
import pw.yumc.Yum.api.YumAPI;
import pw.yumc.Yum.inject.CommandInjector; import pw.yumc.Yum.inject.CommandInjector;
import pw.yumc.Yum.inject.ListenerInjector; import pw.yumc.Yum.inject.ListenerInjector;
import pw.yumc.Yum.inject.TaskInjector; import pw.yumc.Yum.inject.TaskInjector;
@ -43,6 +44,10 @@ public class MonitorCommand implements HandlerCommands {
private final String avg_warn = "§6平均耗时: §c%.5f毫秒!"; private final String avg_warn = "§6平均耗时: §c%.5f毫秒!";
private final String p_n_f = prefix + "§c插件 §b%s §c不存在!"; private final String p_n_f = prefix + "§c插件 §b%s §c不存在!";
private final String injected = "§a插件 §b%s §a成功注入能耗监控器!";
private final String uninjected = "§a插件 §b%s §a成功撤销能耗监控器!";
private final String notEnable = "§c插件 §b%s §c未成功加载 无法执行注入!";
private final double um = 1000000.0; private final double um = 1000000.0;
public MonitorCommand(final Yum yum) { public MonitorCommand(final Yum yum) {
@ -51,7 +56,7 @@ public class MonitorCommand implements HandlerCommands {
cmdhandler.registerCommands(PluginTabComplete.instence); cmdhandler.registerCommands(PluginTabComplete.instence);
} }
@HandlerCommand(name = "cmd", description = "查看插件命令能耗", minimumArguments = 1, possibleArguments = "插件名称") @HandlerCommand(name = "cmd", description = "查看插件命令能耗", minimumArguments = 1, possibleArguments = "[插件名称]")
public void cmd(final InvokeCommandEvent e) { public void cmd(final InvokeCommandEvent e) {
final String pname = e.getArgs()[0]; final String pname = e.getArgs()[0];
final CommandSender sender = e.getSender(); final CommandSender sender = e.getSender();
@ -88,7 +93,7 @@ public class MonitorCommand implements HandlerCommands {
} }
} }
@HandlerCommand(name = "event", description = "查看插件事件能耗", minimumArguments = 1, possibleArguments = "插件名称") @HandlerCommand(name = "event", description = "查看插件事件能耗", minimumArguments = 1, possibleArguments = "[插件名称]")
public void event(final InvokeCommandEvent e) throws InstantiationException, IllegalAccessException { public void event(final InvokeCommandEvent e) throws InstantiationException, IllegalAccessException {
final String pname = e.getArgs()[0]; final String pname = e.getArgs()[0];
final CommandSender sender = e.getSender(); final CommandSender sender = e.getSender();
@ -135,7 +140,24 @@ public class MonitorCommand implements HandlerCommands {
} }
} }
@HandlerCommand(name = "task", description = "查看插件任务能耗", minimumArguments = 1, possibleArguments = "插件名称") @HandlerCommand(name = "inject", aliases = "i", description = "注入能耗监控器", minimumArguments = 1, possibleArguments = "[插件名称]")
public void inject(final InvokeCommandEvent e) {
final String pname = e.getArgs()[0];
final CommandSender sender = e.getSender();
final Plugin plugin = Bukkit.getPluginManager().getPlugin(pname);
if (plugin == null) {
sender.sendMessage(String.format(p_n_f, pname));
return;
}
if (plugin.isEnabled()) {
YumAPI.inject(plugin);
sender.sendMessage(String.format(prefix + injected, pname));
} else {
sender.sendMessage(String.format(prefix + notEnable, pname));
}
}
@HandlerCommand(name = "task", description = "查看插件任务能耗", minimumArguments = 1, possibleArguments = "[插件名称]")
public void task(final InvokeCommandEvent e) { public void task(final InvokeCommandEvent e) {
final String pname = e.getArgs()[0]; final String pname = e.getArgs()[0];
final CommandSender sender = e.getSender(); final CommandSender sender = e.getSender();
@ -164,4 +186,19 @@ public class MonitorCommand implements HandlerCommands {
} }
} }
} }
@HandlerCommand(name = "uninject", aliases = "ui", description = "撤销能耗监控器", minimumArguments = 1, possibleArguments = "[插件名称]")
public void uninject(final InvokeCommandEvent e) {
final String pname = e.getArgs()[0];
final CommandSender sender = e.getSender();
final Plugin plugin = Bukkit.getPluginManager().getPlugin(pname);
if (plugin == null) {
sender.sendMessage(String.format(p_n_f, pname));
return;
}
if (plugin.isEnabled()) {
YumAPI.uninject(plugin);
sender.sendMessage(String.format(prefix + uninjected, pname));
}
}
} }

View File

@ -29,6 +29,11 @@ public class PluginListener implements Listener {
@EventHandler @EventHandler
public void onPluginEnable(final PluginEnableEvent e) { public void onPluginEnable(final PluginEnableEvent e) {
YumAPI.inject(e.getPlugin()); PluginKit.runTaskLater(new Runnable() {
@Override
public void run() {
YumAPI.inject(e.getPlugin());
}
}, 60);
} }
} }

View File

@ -39,7 +39,7 @@ public class PluginNetworkListener implements Listener {
if (ConfigManager.i().getNetworkWhiteURL().contains(e.getUrl().getHost())) { if (ConfigManager.i().getNetworkWhiteURL().contains(e.getUrl().getHost())) {
return; return;
} }
if (urlinfo.contains("yumc") || urlinfo.contains("502647092")) { if (urlinfo.contains("yumc") || urlinfo.contains("citycraft") || urlinfo.contains("502647092")) {
final String 大神你好 = "反编译的大神们我知道你们又要说了这货有后门"; final String 大神你好 = "反编译的大神们我知道你们又要说了这货有后门";
大神你好.isEmpty(); 大神你好.isEmpty();
return; return;

View File

@ -25,4 +25,5 @@ WhiteURL:
- mcstats.org - mcstats.org
- report.mcstats.org - report.mcstats.org
- www.spigotmc.org - www.spigotmc.org
- dev.bukkit.org - dev.bukkit.org
- api.curseforge.com