feat: 兼容PerWorldPlugins

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-07-20 16:26:46 +08:00
parent adaff66241
commit e65246f55e
2 changed files with 26 additions and 14 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.6</version> <version>2.6.7</version>
<name>Yum</name> <name>Yum</name>
<description>Minecraft 服务器插件管理系统</description> <description>Minecraft 服务器插件管理系统</description>
<build> <build>
@ -61,10 +61,9 @@
<update.description>&amp;a全新 2.X 版本 更多守护与优化</update.description> <update.description>&amp;a全新 2.X 版本 更多守护与优化</update.description>
<update.changes> <update.changes>
&amp;c注意 &amp;6- &amp;cYum更新需要重启服务器!重启服务器!重启服务器!; &amp;c注意 &amp;6- &amp;cYum更新需要重启服务器!重启服务器!重启服务器!;
&amp;b2.6.7 &amp;6- &amp;d兼容PerWorldPlugins...;
&amp;b2.6.6 &amp;6- &amp;c修复快捷点击按钮触发命令错误...; &amp;b2.6.6 &amp;6- &amp;c修复快捷点击按钮触发命令错误...;
&amp;b2.6.5 &amp;6- &amp;c修复list命令 &amp;a添加全局能耗统计...; &amp;b2.6.5 &amp;6- &amp;c修复list命令 &amp;a添加全局能耗统计...;
&amp;b2.6.4 &amp;6- &amp;e添加从&amp;bBukkitDev&amp;e下载和更新...;
&amp;b2.6.3 &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

@ -1,5 +1,6 @@
package pw.yumc.Yum.inject; package pw.yumc.Yum.inject;
import java.lang.reflect.Field;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -22,7 +23,7 @@ import pw.yumc.Yum.managers.MonitorManager;
public class ListenerInjector implements EventExecutor { public class ListenerInjector implements EventExecutor {
private final static String prefix = "§6[§bYum §a事件监控§6] "; private final static String prefix = "§6[§bYum §a事件监控§6] ";
private final static String inject_error = prefix + "§6插件 §b%s §c注入能耗监控失败!"; private final static String inject_error = prefix + "§6插件 §b%s §c注入能耗监控失败 §6注入类: §3%s!";
private final static String plugin_is_null = "插件不得为NULL!"; private final static String plugin_is_null = "插件不得为NULL!";
private final EventExecutor originalExecutor; private final EventExecutor originalExecutor;
@ -40,12 +41,22 @@ public class ListenerInjector implements EventExecutor {
public static void inject(final Plugin plugin) { public static void inject(final Plugin plugin) {
Validate.notNull(plugin, plugin_is_null); Validate.notNull(plugin, plugin_is_null);
try {
final List<RegisteredListener> listeners = HandlerList.getRegisteredListeners(plugin); final List<RegisteredListener> listeners = HandlerList.getRegisteredListeners(plugin);
for (final RegisteredListener listener : listeners) { for (final RegisteredListener listener : listeners) {
try {
if (listener instanceof TimedRegisteredListener) { if (listener instanceof TimedRegisteredListener) {
return; return;
} }
if (listener.getClass().getName().contains("PWPRegisteredListener")) {
final Field f = Reflect.on(listener).getDeclaredField(RegisteredListener.class, "executor");
f.setAccessible(true);
final EventExecutor originalExecutor = (EventExecutor) f.get(listener);
if (originalExecutor instanceof ListenerInjector) {
return;
}
final ListenerInjector listenerInjector = new ListenerInjector(originalExecutor, plugin);
f.set(listener, listenerInjector);
} else {
final EventExecutor originalExecutor = Reflect.on(listener).get("executor"); final EventExecutor originalExecutor = Reflect.on(listener).get("executor");
if (originalExecutor instanceof ListenerInjector) { if (originalExecutor instanceof ListenerInjector) {
return; return;
@ -54,7 +65,9 @@ public class ListenerInjector implements EventExecutor {
Reflect.on(listener).set("executor", listenerInjector); Reflect.on(listener).set("executor", listenerInjector);
} }
} catch (final Throwable e) { } catch (final Throwable e) {
PluginKit.sc(String.format(inject_error, plugin.getName())); PluginKit.sc(String.format(inject_error, plugin.getName(), listener.getClass().getName()));
e.printStackTrace();
}
} }
} }