mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-11-22 22:38:46 +00:00
feat: 完善能耗监控系统
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
ffeccab654
commit
f8a987606a
2
pom.xml
2
pom.xml
@ -90,7 +90,7 @@
|
|||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<version>1.9-R0.1-SNAPSHOT</version>
|
<version>1.10.2-R0.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.citycraft</groupId>
|
<groupId>cn.citycraft</groupId>
|
||||||
|
@ -45,9 +45,7 @@ public class Yum extends JavaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
NetworkManager.unregister();
|
NetworkManager.unregister();
|
||||||
// for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
|
||||||
// YumAPI.uninject(plugin);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -60,8 +58,9 @@ public class Yum extends JavaPlugin {
|
|||||||
initListeners();
|
initListeners();
|
||||||
initRunnable();
|
initRunnable();
|
||||||
new VersionChecker(this);
|
new VersionChecker(this);
|
||||||
YumAPI.updaterepo(Bukkit.getConsoleSender());
|
YumAPI.updateInject();
|
||||||
YumAPI.updatecheck(Bukkit.getConsoleSender());
|
YumAPI.updateRepo(Bukkit.getConsoleSender());
|
||||||
|
YumAPI.updateCheck(Bukkit.getConsoleSender());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -12,7 +12,9 @@ import org.bukkit.plugin.Plugin;
|
|||||||
|
|
||||||
import cn.citycraft.CommonData.UpdatePlugin;
|
import cn.citycraft.CommonData.UpdatePlugin;
|
||||||
import cn.citycraft.PluginHelper.kit.PKit;
|
import cn.citycraft.PluginHelper.kit.PKit;
|
||||||
|
import cn.citycraft.PluginHelper.kit.PluginKit;
|
||||||
import pw.yumc.Yum.inject.CommandInjector;
|
import pw.yumc.Yum.inject.CommandInjector;
|
||||||
|
import pw.yumc.Yum.inject.ListenerInjector;
|
||||||
import pw.yumc.Yum.inject.TaskInjector;
|
import pw.yumc.Yum.inject.TaskInjector;
|
||||||
import pw.yumc.Yum.managers.ConfigManager;
|
import pw.yumc.Yum.managers.ConfigManager;
|
||||||
import pw.yumc.Yum.managers.DownloadManager;
|
import pw.yumc.Yum.managers.DownloadManager;
|
||||||
@ -104,9 +106,11 @@ public class YumAPI {
|
|||||||
* 插件
|
* 插件
|
||||||
*/
|
*/
|
||||||
public static void inject(final Plugin plugin) {
|
public static void inject(final Plugin plugin) {
|
||||||
CommandInjector.inject(plugin);
|
if (plugin.isEnabled()) {
|
||||||
// ListenerInjector.inject(plugin);
|
CommandInjector.inject(plugin);
|
||||||
TaskInjector.inject(plugin);
|
ListenerInjector.inject(plugin);
|
||||||
|
TaskInjector.inject(plugin);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -150,8 +154,8 @@ public class YumAPI {
|
|||||||
* 插件名称
|
* 插件名称
|
||||||
* @return 是否安装成功
|
* @return 是否安装成功
|
||||||
*/
|
*/
|
||||||
public static boolean installfromyum(final CommandSender sender, final String pluginname) {
|
public static boolean installFromYum(final CommandSender sender, final String pluginname) {
|
||||||
return installfromyum(sender, pluginname, null);
|
return installFromYum(sender, pluginname, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -165,7 +169,7 @@ public class YumAPI {
|
|||||||
* 插件版本
|
* 插件版本
|
||||||
* @return 是否安装成功
|
* @return 是否安装成功
|
||||||
*/
|
*/
|
||||||
public static boolean installfromyum(final CommandSender sender, final String pluginname, final String version) {
|
public static boolean installFromYum(final CommandSender sender, final String pluginname, final String version) {
|
||||||
final PluginInfo pi = repo.getPlugin(pluginname);
|
final PluginInfo pi = repo.getPlugin(pluginname);
|
||||||
if (pi != null) {
|
if (pi != null) {
|
||||||
return install(sender, pi.name, pi.getUrl(sender, version));
|
return install(sender, pi.name, pi.getUrl(sender, version));
|
||||||
@ -203,6 +207,18 @@ public class YumAPI {
|
|||||||
plugman.reload(plugin);
|
plugman.reload(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消注入
|
||||||
|
*
|
||||||
|
* @param plugin
|
||||||
|
* 插件
|
||||||
|
*/
|
||||||
|
public static void uninject() {
|
||||||
|
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||||
|
YumAPI.uninject(plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取消注入
|
* 取消注入
|
||||||
*
|
*
|
||||||
@ -264,7 +280,7 @@ public class YumAPI {
|
|||||||
* @param sender
|
* @param sender
|
||||||
* 命令发送者
|
* 命令发送者
|
||||||
*/
|
*/
|
||||||
public static void updateall(final CommandSender sender) {
|
public static void updateAll(final CommandSender sender) {
|
||||||
main.getServer().getScheduler().runTaskAsynchronously(main, new Runnable() {
|
main.getServer().getScheduler().runTaskAsynchronously(main, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -279,7 +295,7 @@ public class YumAPI {
|
|||||||
sender.sendMessage("§d开始更新服务器可更新插件");
|
sender.sendMessage("§d开始更新服务器可更新插件");
|
||||||
for (final Plugin updateplugin : ulist) {
|
for (final Plugin updateplugin : ulist) {
|
||||||
sender.sendMessage("§d一键更新: §a开始更新" + updateplugin.getName() + "!");
|
sender.sendMessage("§d一键更新: §a开始更新" + updateplugin.getName() + "!");
|
||||||
if (!updatefromyum(sender, updateplugin, null, true)) {
|
if (!updateFromYum(sender, updateplugin, null, true)) {
|
||||||
failed++;
|
failed++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -288,7 +304,7 @@ public class YumAPI {
|
|||||||
}
|
}
|
||||||
sender.sendMessage("§d一键更新: §e已下载所有需要升级的插件到 服务器更新 文件夹");
|
sender.sendMessage("§d一键更新: §e已下载所有需要升级的插件到 服务器更新 文件夹");
|
||||||
sender.sendMessage("§d一键更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!");
|
sender.sendMessage("§d一键更新: §e插件将在重启后自动更新(或使用§b/yum upgrade§e直接升级)!");
|
||||||
updatecheck(sender);
|
updateCheck(sender);
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("§6更新: §e未找到需要更新且可以用Yum处理的插件!");
|
sender.sendMessage("§6更新: §e未找到需要更新且可以用Yum处理的插件!");
|
||||||
}
|
}
|
||||||
@ -303,8 +319,8 @@ public class YumAPI {
|
|||||||
* @param sender
|
* @param sender
|
||||||
* 命令发送者
|
* 命令发送者
|
||||||
*/
|
*/
|
||||||
public static void updatecheck(final CommandSender sender) {
|
public static void updateCheck(final CommandSender sender) {
|
||||||
main.getServer().getScheduler().runTaskLaterAsynchronously(main, new Runnable() {
|
PluginKit.runTaskLaterAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final List<Plugin> ulist = getUpdateList(sender);
|
final List<Plugin> ulist = getUpdateList(sender);
|
||||||
@ -324,8 +340,8 @@ public class YumAPI {
|
|||||||
* 插件实体
|
* 插件实体
|
||||||
* @return 是否更新成功
|
* @return 是否更新成功
|
||||||
*/
|
*/
|
||||||
public static boolean updatefromyum(final CommandSender sender, final Plugin plugin) {
|
public static boolean updateFromYum(final CommandSender sender, final Plugin plugin) {
|
||||||
return updatefromyum(sender, plugin, null);
|
return updateFromYum(sender, plugin, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -339,8 +355,8 @@ public class YumAPI {
|
|||||||
* 插件版本(null则自动获取)
|
* 插件版本(null则自动获取)
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean updatefromyum(final CommandSender sender, final Plugin plugin, final String version) {
|
public static boolean updateFromYum(final CommandSender sender, final Plugin plugin, final String version) {
|
||||||
return updatefromyum(sender, plugin, version, false);
|
return updateFromYum(sender, plugin, version, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -356,7 +372,7 @@ public class YumAPI {
|
|||||||
* 是否一键更新
|
* 是否一键更新
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean updatefromyum(final CommandSender sender, final Plugin plugin, final String version, final boolean oneKeyUpdate) {
|
public static boolean updateFromYum(final CommandSender sender, final Plugin plugin, final String version, final boolean oneKeyUpdate) {
|
||||||
final PluginInfo pi = repo.getPlugin(plugin.getName());
|
final PluginInfo pi = repo.getPlugin(plugin.getName());
|
||||||
if (pi != null) {
|
if (pi != null) {
|
||||||
final File pFile = new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName());
|
final File pFile = new File(Bukkit.getUpdateFolderFile(), plugman.getPluginFile(plugin).getName());
|
||||||
@ -374,11 +390,25 @@ public class YumAPI {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新注入
|
||||||
|
*/
|
||||||
|
public static void updateInject() {
|
||||||
|
PluginKit.runTaskLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||||
|
YumAPI.inject(plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 60);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新Yum源数据
|
* 更新Yum源数据
|
||||||
*/
|
*/
|
||||||
public static void updaterepo(final CommandSender sender) {
|
public static void updateRepo(final CommandSender sender) {
|
||||||
main.getServer().getScheduler().runTaskAsynchronously(main, new Runnable() {
|
PluginKit.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
repo.updateRepositories(sender);
|
repo.updateRepositories(sender);
|
||||||
|
@ -23,6 +23,7 @@ import cn.citycraft.PluginHelper.commands.HandlerCommands;
|
|||||||
import cn.citycraft.PluginHelper.commands.InvokeCommandEvent;
|
import cn.citycraft.PluginHelper.commands.InvokeCommandEvent;
|
||||||
import cn.citycraft.PluginHelper.commands.InvokeSubCommand;
|
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 pw.yumc.Yum.Yum;
|
import pw.yumc.Yum.Yum;
|
||||||
import pw.yumc.Yum.inject.CommandInjector;
|
import pw.yumc.Yum.inject.CommandInjector;
|
||||||
import pw.yumc.Yum.inject.ListenerInjector;
|
import pw.yumc.Yum.inject.ListenerInjector;
|
||||||
@ -34,10 +35,13 @@ import pw.yumc.Yum.inject.TaskInjector;
|
|||||||
* @author 喵♂呜
|
* @author 喵♂呜
|
||||||
*/
|
*/
|
||||||
public class MonitorCommand implements HandlerCommands {
|
public class MonitorCommand implements HandlerCommands {
|
||||||
Yum main;
|
private final String prefix = "§6[§bYum §a能耗监控§6] ";
|
||||||
|
private final String total = "§6总耗时: §a%.2f秒 ";
|
||||||
|
private final String count = "§6执行次数: §b%s次 ";
|
||||||
|
private final String avg = "§6平均耗时: §d%.5f秒!";
|
||||||
|
private final String p_n_f = prefix + "§c插件不存在!";
|
||||||
|
|
||||||
public MonitorCommand(final Yum yum) {
|
public MonitorCommand(final Yum yum) {
|
||||||
main = yum;
|
|
||||||
final InvokeSubCommand cmdhandler = new InvokeSubCommand(yum, "monitor");
|
final InvokeSubCommand cmdhandler = new InvokeSubCommand(yum, "monitor");
|
||||||
cmdhandler.setAllCommandOnlyConsole(yum.getConfig().getBoolean("onlyFileCommandConsole", true));
|
cmdhandler.setAllCommandOnlyConsole(yum.getConfig().getBoolean("onlyFileCommandConsole", true));
|
||||||
cmdhandler.registerCommands(this);
|
cmdhandler.registerCommands(this);
|
||||||
@ -54,12 +58,12 @@ public class MonitorCommand implements HandlerCommands {
|
|||||||
final String pname = e.getArgs()[0];
|
final String pname = e.getArgs()[0];
|
||||||
final CommandSender sender = e.getSender();
|
final CommandSender sender = e.getSender();
|
||||||
if (Bukkit.getPluginManager().getPlugin(pname) == null) {
|
if (Bukkit.getPluginManager().getPlugin(pname) == null) {
|
||||||
sender.sendMessage("§c插件不存在!");
|
sender.sendMessage(p_n_f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final PluginManager pluginManager = Bukkit.getPluginManager();
|
final PluginManager pluginManager = Bukkit.getPluginManager();
|
||||||
final SimpleCommandMap commandMap = Reflect.on(pluginManager).get("commandMap");
|
final SimpleCommandMap commandMap = Reflect.on(pluginManager).get("commandMap");
|
||||||
sender.sendMessage("§6插件 §b" + pname + " §6的命令能耗如下!");
|
sender.sendMessage(prefix + "§6插件 §b" + pname + " §6的命令能耗如下!");
|
||||||
final Map<String, Command> temp = new HashMap<>();
|
final Map<String, Command> temp = new HashMap<>();
|
||||||
for (final Command command : commandMap.getCommands()) {
|
for (final Command command : commandMap.getCommands()) {
|
||||||
if (command instanceof PluginCommand) {
|
if (command instanceof PluginCommand) {
|
||||||
@ -76,10 +80,10 @@ public class MonitorCommand implements HandlerCommands {
|
|||||||
final CommandInjector injected = (CommandInjector) executor;
|
final CommandInjector injected = (CommandInjector) executor;
|
||||||
final StringBuffer str = new StringBuffer();
|
final StringBuffer str = new StringBuffer();
|
||||||
str.append("§6- §e" + command.getValue().getName() + " ");
|
str.append("§6- §e" + command.getValue().getName() + " ");
|
||||||
str.append(String.format("§6总耗时: §a%.2f秒 ", injected.totalTime / 1000000.0));
|
str.append(String.format(total, injected.totalTime / 1000000.0));
|
||||||
str.append("§6执行次数: §b" + injected.count + "次 ");
|
str.append(String.format(count, injected.count));
|
||||||
if (injected.count != 0) {
|
if (injected.count != 0) {
|
||||||
str.append(String.format("§6平均耗时: §d%.2f秒!", injected.totalTime / 1000000.0 / injected.count));
|
str.append(String.format(avg, injected.totalTime / 1000000.0 / injected.count));
|
||||||
}
|
}
|
||||||
e.getSender().sendMessage(str.toString());
|
e.getSender().sendMessage(str.toString());
|
||||||
}
|
}
|
||||||
@ -92,25 +96,38 @@ public class MonitorCommand implements HandlerCommands {
|
|||||||
final CommandSender sender = e.getSender();
|
final CommandSender sender = e.getSender();
|
||||||
final Plugin plugin = Bukkit.getPluginManager().getPlugin(pname);
|
final Plugin plugin = Bukkit.getPluginManager().getPlugin(pname);
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
sender.sendMessage("§c插件不存在!");
|
sender.sendMessage(p_n_f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sender.sendMessage("§6插件 §b" + pname + " §6的事件能耗如下!");
|
sender.sendMessage(prefix + "§6插件 §b" + pname + " §6的事件能耗如下!");
|
||||||
final List<RegisteredListener> listeners = HandlerList.getRegisteredListeners(plugin);
|
final List<RegisteredListener> listeners = HandlerList.getRegisteredListeners(plugin);
|
||||||
|
final Map<String, Long> eventTotalTime = new HashMap<>();
|
||||||
|
final Map<String, Long> eventCount = new HashMap<>();
|
||||||
for (final RegisteredListener listener : listeners) {
|
for (final RegisteredListener listener : listeners) {
|
||||||
final EventExecutor executor = Reflect.on(listener).get("executor");
|
final EventExecutor executor = Reflect.on(listener).get("executor");
|
||||||
if (executor instanceof ListenerInjector) {
|
if (executor instanceof ListenerInjector) {
|
||||||
final ListenerInjector injected = (ListenerInjector) executor;
|
final ListenerInjector injected = (ListenerInjector) executor;
|
||||||
final StringBuffer str = new StringBuffer();
|
for (final String entry : injected.eventTotalTime.keySet()) {
|
||||||
str.append("§6- §e" + injected.getOriginalExecutor().getClass().getSimpleName() + " ");
|
if (eventTotalTime.containsKey(entry)) {
|
||||||
str.append(String.format("§6总耗时: §a%.2f秒 ", injected.totalTime / 1000000.0));
|
eventTotalTime.put(entry, eventTotalTime.get(entry) + injected.eventTotalTime.get(entry));
|
||||||
str.append("§6执行次数: §b" + injected.count + "次 ");
|
eventCount.put(entry, eventCount.get(entry) + injected.eventCount.get(entry));
|
||||||
if (injected.count != 0) {
|
} else {
|
||||||
str.append(String.format("§6平均耗时: §d%.2f秒!", injected.totalTime / 1000000.0 / injected.count));
|
eventTotalTime.put(entry, injected.eventTotalTime.get(entry));
|
||||||
|
eventCount.put(entry, injected.eventCount.get(entry));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
e.getSender().sendMessage(str.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (final String event : eventTotalTime.keySet()) {
|
||||||
|
final StringBuffer str = new StringBuffer();
|
||||||
|
str.append("§6- §e" + event + " ");
|
||||||
|
str.append(String.format(total, eventTotalTime.get(event) / 1000000.0));
|
||||||
|
str.append(String.format(count, eventCount.get(event)));
|
||||||
|
if (eventCount.get(event) != 0) {
|
||||||
|
str.append(String.format(avg, eventTotalTime.get(event) / 1000000.0 / eventCount.get(event)));
|
||||||
|
}
|
||||||
|
e.getSender().sendMessage(str.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@HandlerCommand(name = "task", minimumArguments = 1, possibleArguments = "插件名称")
|
@HandlerCommand(name = "task", minimumArguments = 1, possibleArguments = "插件名称")
|
||||||
@ -119,23 +136,26 @@ public class MonitorCommand implements HandlerCommands {
|
|||||||
final CommandSender sender = e.getSender();
|
final CommandSender sender = e.getSender();
|
||||||
final Plugin plugin = Bukkit.getPluginManager().getPlugin(pname);
|
final Plugin plugin = Bukkit.getPluginManager().getPlugin(pname);
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
sender.sendMessage("§c插件不存在!");
|
sender.sendMessage(p_n_f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final List<BukkitTask> pendingTasks = Bukkit.getScheduler().getPendingTasks();
|
final List<BukkitTask> pendingTasks = Bukkit.getScheduler().getPendingTasks();
|
||||||
sender.sendMessage("§6插件 §b" + pname + " §6的任务能耗如下!");
|
sender.sendMessage(prefix + "§6插件 §b" + pname + " §6的任务能耗如下!");
|
||||||
for (final BukkitTask pendingTask : pendingTasks) {
|
for (final BukkitTask pendingTask : pendingTasks) {
|
||||||
final Runnable task = Reflect.on(pendingTask).get("task");
|
if (pendingTask.getOwner().getName().equalsIgnoreCase(pname)) {
|
||||||
if (task instanceof TaskInjector) {
|
final Runnable task = Reflect.on(pendingTask).get("task");
|
||||||
final TaskInjector executor = (TaskInjector) task;
|
if (task instanceof TaskInjector) {
|
||||||
final StringBuffer str = new StringBuffer();
|
final TaskInjector executor = (TaskInjector) task;
|
||||||
str.append("§6- §e" + executor.getOriginalTask().getClass().getSimpleName() + " ");
|
final StringBuffer str = new StringBuffer();
|
||||||
str.append(String.format("§6总耗时: §a%.2f秒 ", executor.totalTime / 1000000.0));
|
final Class<? extends Runnable> taskName = executor.getOriginalTask().getClass();
|
||||||
str.append("§6执行次数: §b" + executor.count + "次 ");
|
str.append("§6- §e" + (StrKit.isBlank(taskName.getSimpleName()) ? taskName.getName() : taskName.getSimpleName()) + " ");
|
||||||
if (executor.count != 0) {
|
str.append(String.format(total, executor.totalTime / 1000000.0));
|
||||||
str.append(String.format("§6平均耗时: §d%.2f秒!", executor.totalTime / 1000000.0 / executor.count));
|
str.append(String.format(count, executor.count));
|
||||||
|
if (executor.count != 0) {
|
||||||
|
str.append(String.format(avg, executor.totalTime / 1000000.0 / executor.count));
|
||||||
|
}
|
||||||
|
e.getSender().sendMessage(str.toString());
|
||||||
}
|
}
|
||||||
e.getSender().sendMessage(str.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,9 +143,9 @@ public class YumCommand implements HandlerCommands, Listener {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
YumAPI.installfromyum(sender, pluginname);
|
YumAPI.installFromYum(sender, pluginname);
|
||||||
} else {
|
} else {
|
||||||
YumAPI.installfromyum(sender, pluginname, args[1]);
|
YumAPI.installFromYum(sender, pluginname, args[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -178,7 +178,7 @@ public class YumCommand implements HandlerCommands, Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onAdminJoin(final PlayerJoinEvent e) {
|
public void onAdminJoin(final PlayerJoinEvent e) {
|
||||||
if (e.getPlayer().isOp()) {
|
if (e.getPlayer().isOp()) {
|
||||||
YumAPI.updatecheck(e.getPlayer());
|
YumAPI.updateCheck(e.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,9 +334,9 @@ public class YumCommand implements HandlerCommands, Listener {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
YumAPI.updatefromyum(sender, plugin);
|
YumAPI.updateFromYum(sender, plugin);
|
||||||
} else {
|
} else {
|
||||||
YumAPI.updatefromyum(sender, plugin, args[1]);
|
YumAPI.updateFromYum(sender, plugin, args[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -354,7 +354,7 @@ public class YumCommand implements HandlerCommands, Listener {
|
|||||||
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(main, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
YumAPI.updateall(e.getSender());
|
YumAPI.updateAll(e.getSender());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ public class CommandInjector implements TabExecutor {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||||
final long start = System.nanoTime();
|
final long start = System.nanoTime();
|
||||||
// todo add a more aggressive 10 ms cpu sample
|
// TODO add a more aggressive 10 ms cpu sample
|
||||||
final boolean result = originalExecutor.onCommand(sender, command, label, args);
|
final boolean result = originalExecutor.onCommand(sender, command, label, args);
|
||||||
final long end = System.nanoTime();
|
final long end = System.nanoTime();
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ public class CommandInjector implements TabExecutor {
|
|||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(final CommandSender sender, final Command command, final String alias, final String[] args) {
|
public List<String> onTabComplete(final CommandSender sender, final Command command, final String alias, final String[] args) {
|
||||||
final long start = System.nanoTime();
|
final long start = System.nanoTime();
|
||||||
// todo add a more aggressive 10 ms cpu sample
|
// TODO add a more aggressive 10 ms cpu sample
|
||||||
final List<String> result = originalCompleter.onTabComplete(sender, command, alias, args);
|
final List<String> result = originalCompleter.onTabComplete(sender, command, alias, args);
|
||||||
final long end = System.nanoTime();
|
final long end = System.nanoTime();
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package pw.yumc.Yum.inject;
|
package pw.yumc.Yum.inject;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.EventException;
|
import org.bukkit.event.EventException;
|
||||||
@ -9,6 +11,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.plugin.EventExecutor;
|
import org.bukkit.plugin.EventExecutor;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.RegisteredListener;
|
import org.bukkit.plugin.RegisteredListener;
|
||||||
|
import org.bukkit.plugin.TimedRegisteredListener;
|
||||||
|
|
||||||
import cn.citycraft.PluginHelper.ext.kit.Reflect;
|
import cn.citycraft.PluginHelper.ext.kit.Reflect;
|
||||||
|
|
||||||
@ -16,17 +19,25 @@ public class ListenerInjector implements EventExecutor {
|
|||||||
|
|
||||||
private final EventExecutor originalExecutor;
|
private final EventExecutor originalExecutor;
|
||||||
|
|
||||||
public long totalTime;
|
public Map<String, Long> eventTotalTime;
|
||||||
public long count;
|
public Map<String, Long> eventCount;
|
||||||
|
|
||||||
public ListenerInjector(final EventExecutor originalExecutor) {
|
public ListenerInjector(final EventExecutor originalExecutor) {
|
||||||
this.originalExecutor = originalExecutor;
|
this.originalExecutor = originalExecutor;
|
||||||
|
eventTotalTime = new HashMap<>();
|
||||||
|
eventCount = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void inject(final Plugin plugin) {
|
public static void inject(final Plugin plugin) {
|
||||||
final List<RegisteredListener> listeners = HandlerList.getRegisteredListeners(plugin);
|
final List<RegisteredListener> listeners = HandlerList.getRegisteredListeners(plugin);
|
||||||
for (final RegisteredListener listener : listeners) {
|
for (final RegisteredListener listener : listeners) {
|
||||||
|
if (listener instanceof TimedRegisteredListener) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final EventExecutor originalExecutor = Reflect.on(listener).get("executor");
|
final EventExecutor originalExecutor = Reflect.on(listener).get("executor");
|
||||||
|
if (originalExecutor instanceof ListenerInjector) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final ListenerInjector listenerInjector = new ListenerInjector(originalExecutor);
|
final ListenerInjector listenerInjector = new ListenerInjector(originalExecutor);
|
||||||
Reflect.on(listener).set("executor", listenerInjector);
|
Reflect.on(listener).set("executor", listenerInjector);
|
||||||
}
|
}
|
||||||
@ -35,6 +46,9 @@ public class ListenerInjector implements EventExecutor {
|
|||||||
public static void uninject(final Plugin plugin) {
|
public static void uninject(final Plugin plugin) {
|
||||||
final List<RegisteredListener> listeners = HandlerList.getRegisteredListeners(plugin);
|
final List<RegisteredListener> listeners = HandlerList.getRegisteredListeners(plugin);
|
||||||
for (final RegisteredListener listener : listeners) {
|
for (final RegisteredListener listener : listeners) {
|
||||||
|
if (listener instanceof TimedRegisteredListener) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final EventExecutor executor = Reflect.on(listener).get("executor");
|
final EventExecutor executor = Reflect.on(listener).get("executor");
|
||||||
if (executor instanceof ListenerInjector) {
|
if (executor instanceof ListenerInjector) {
|
||||||
Reflect.on(listener).set("executor", ((ListenerInjector) executor).getOriginalExecutor());
|
Reflect.on(listener).set("executor", ((ListenerInjector) executor).getOriginalExecutor());
|
||||||
@ -46,12 +60,17 @@ public class ListenerInjector implements EventExecutor {
|
|||||||
public void execute(final Listener listener, final Event event) throws EventException {
|
public void execute(final Listener listener, final Event event) throws EventException {
|
||||||
if (!event.isAsynchronous()) {
|
if (!event.isAsynchronous()) {
|
||||||
final long start = System.nanoTime();
|
final long start = System.nanoTime();
|
||||||
// todo add a more aggressive 10 ms cpu sample
|
// TODO add a more aggressive 10 ms cpu sample
|
||||||
originalExecutor.execute(listener, event);
|
originalExecutor.execute(listener, event);
|
||||||
final long end = System.nanoTime();
|
final long end = System.nanoTime();
|
||||||
|
final String en = event.getEventName();
|
||||||
totalTime += end - start;
|
if (eventTotalTime.containsKey(en)) {
|
||||||
count++;
|
eventTotalTime.put(en, eventTotalTime.get(en) + end - start);
|
||||||
|
eventCount.put(en, eventCount.get(en) + 1);
|
||||||
|
} else {
|
||||||
|
eventTotalTime.put(en, end - start);
|
||||||
|
eventCount.put(en, 1L);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
originalExecutor.execute(listener, event);
|
originalExecutor.execute(listener, event);
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,9 @@ public class TaskInjector implements Runnable {
|
|||||||
// we could ignore async tasks for now
|
// we could ignore async tasks for now
|
||||||
if (pendingTask.isSync() && pendingTask.getOwner().equals(plugin)) {
|
if (pendingTask.isSync() && pendingTask.getOwner().equals(plugin)) {
|
||||||
final Runnable originalTask = Reflect.on(pendingTask).get("task");
|
final Runnable originalTask = Reflect.on(pendingTask).get("task");
|
||||||
|
if (originalTask instanceof TaskInjector) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final TaskInjector taskInjector = new TaskInjector(originalTask);
|
final TaskInjector taskInjector = new TaskInjector(originalTask);
|
||||||
Reflect.on(pendingTask).set("task", taskInjector);
|
Reflect.on(pendingTask).set("task", taskInjector);
|
||||||
}
|
}
|
||||||
@ -56,7 +59,7 @@ public class TaskInjector implements Runnable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final long start = System.nanoTime();
|
final long start = System.nanoTime();
|
||||||
// todo add a more aggressive 10 ms cpu sample
|
// TODO add a more aggressive 10 ms cpu sample
|
||||||
originalTask.run();
|
originalTask.run();
|
||||||
final long end = System.nanoTime();
|
final long end = System.nanoTime();
|
||||||
|
|
||||||
|
@ -109,6 +109,7 @@ public class PluginInfo implements Serializable {
|
|||||||
} else if (pom != null && !pom.isEmpty()) {
|
} else if (pom != null && !pom.isEmpty()) {
|
||||||
pom = pom.replace("[name]", name).replace("[branch]", branch);
|
pom = pom.replace("[name]", name).replace("[branch]", branch);
|
||||||
sender.sendMessage("§6版本: §b尝试从在线POM文件获取最新版本...");
|
sender.sendMessage("§6版本: §b尝试从在线POM文件获取最新版本...");
|
||||||
|
System.out.println(pom);
|
||||||
ver = IOUtil.getXMLTag(pom, "version", null);
|
ver = IOUtil.getXMLTag(pom, "version", null);
|
||||||
if (ver != null) {
|
if (ver != null) {
|
||||||
sender.sendMessage("§6版本: §a成功获取到最新版本 §e" + ver + " §a...");
|
sender.sendMessage("§6版本: §a成功获取到最新版本 §e" + ver + " §a...");
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
############################
|
||||||
|
### Yum插件主配置文件
|
||||||
|
############################
|
||||||
|
|
||||||
#配置版本号 请勿修改!!!
|
#配置版本号 请勿修改!!!
|
||||||
Version: 2.2
|
Version: 2.2
|
||||||
|
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
############################
|
||||||
|
### 能耗监控系统配置文件
|
||||||
|
############################
|
||||||
|
|
||||||
|
#配置版本号 请勿修改!!!
|
||||||
|
Version: 1.0
|
||||||
|
|
||||||
|
#是否开启
|
||||||
|
Enable: true
|
@ -1,3 +1,7 @@
|
|||||||
|
############################
|
||||||
|
### 网络管理系统配置文件
|
||||||
|
############################
|
||||||
|
|
||||||
#配置版本号 请勿修改!!!
|
#配置版本号 请勿修改!!!
|
||||||
Version: 1.2
|
Version: 1.2
|
||||||
|
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
############################
|
||||||
|
### 安全管理系统配置文件
|
||||||
|
############################
|
||||||
|
|
||||||
#配置版本号 请勿修改!!!
|
#配置版本号 请勿修改!!!
|
||||||
Version: 1.0
|
Version: 1.0
|
||||||
|
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
############################
|
||||||
|
### 线程管理系统配置文件
|
||||||
|
############################
|
||||||
|
|
||||||
#配置版本号 请勿修改!!!
|
#配置版本号 请勿修改!!!
|
||||||
Version: 1.0
|
Version: 1.0
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user