diff --git a/src/main/scala/io/izzel/taboolib/compat/kotlin/CompatKotlin.java b/src/main/scala/io/izzel/taboolib/compat/kotlin/CompatKotlin.java index a2c98f1..3682f29 100644 --- a/src/main/scala/io/izzel/taboolib/compat/kotlin/CompatKotlin.java +++ b/src/main/scala/io/izzel/taboolib/compat/kotlin/CompatKotlin.java @@ -9,16 +9,24 @@ import io.izzel.taboolib.util.Reflection; */ public class CompatKotlin { - public static boolean isCompanion(Class clazz) { - return clazz.getName().endsWith("$Companion"); + public static boolean isCompanion(Class pluginClass) { + return pluginClass.getName().endsWith("$Companion"); } - public static Object getCompanion(Class clazz) { + public static Object getCompanion(Class pluginClass) { try { - return Reflection.getValue(null, TabooLibAPI.getPluginBridge().getClass(clazz.getName().substring(0, clazz.getName().indexOf("$Companion"))), true, "Companion"); + return Reflection.getValue(null, TabooLibAPI.getPluginBridge().getClass(pluginClass.getName().substring(0, pluginClass.getName().indexOf("$Companion"))), true, "Companion"); } catch (Throwable t) { t.printStackTrace(); } return null; } + + public static Object getInstance(Class pluginClass) { + try { + return Reflection.getValue(null, pluginClass, true, "INSTANCE"); + } catch (Throwable ignored) { + } + return null; + } } diff --git a/src/main/scala/io/izzel/taboolib/module/db/local/LocalLoader.java b/src/main/scala/io/izzel/taboolib/module/db/local/LocalLoader.java index 340c7ec..3410d31 100644 --- a/src/main/scala/io/izzel/taboolib/module/db/local/LocalLoader.java +++ b/src/main/scala/io/izzel/taboolib/module/db/local/LocalLoader.java @@ -1,12 +1,11 @@ package io.izzel.taboolib.module.db.local; import io.izzel.taboolib.TabooLibLoader; -import io.izzel.taboolib.module.locale.logger.TLogger; +import io.izzel.taboolib.module.inject.TInjectHelper; import io.izzel.taboolib.util.Ref; import org.bukkit.plugin.Plugin; import java.lang.reflect.Field; -import java.lang.reflect.Modifier; /** * @Author 坏黑 @@ -21,21 +20,13 @@ public class LocalLoader implements TabooLibLoader.Loader { if (annotation == null) { continue; } - Object instance = null; - // 如果是非静态类型 - if (!Modifier.isStatic(field.getModifiers())) { - // 是否为主类 - if (pluginClass.equals(plugin.getClass())) { - instance = plugin; - } else { - TLogger.getGlobalLogger().error(field.getName() + " is not a static field. (" + pluginClass.getName() + ")"); - continue; - } - } Ref.forcedAccess(field); - try { - field.set(instance, Local.get(plugin.getName()).get(annotation.value())); - } catch (IllegalAccessException ignored) { + for (Object instance : TInjectHelper.getInstance(field, pluginClass, plugin)) { + try { + field.set(instance, Local.get(plugin.getName()).get(annotation.value())); + } catch (Throwable t) { + t.printStackTrace(); + } } } } diff --git a/src/main/scala/io/izzel/taboolib/module/inject/PlayerContainerLoader.java b/src/main/scala/io/izzel/taboolib/module/inject/PlayerContainerLoader.java index 718dedb..f110082 100644 --- a/src/main/scala/io/izzel/taboolib/module/inject/PlayerContainerLoader.java +++ b/src/main/scala/io/izzel/taboolib/module/inject/PlayerContainerLoader.java @@ -32,9 +32,12 @@ public class PlayerContainerLoader implements Listener, TabooLibLoader.Loader { continue; } field.setAccessible(true); - try { - pluginContainer.computeIfAbsent(plugin.getName(), name -> new ArrayList<>()).add(new Container(field.get(pluginClass), annotation.uniqueId())); - } catch (IllegalAccessException ignored) { + for (Object instance : TInjectHelper.getInstance(field, pluginClass, plugin)) { + try { + pluginContainer.computeIfAbsent(plugin.getName(), name -> new ArrayList<>()).add(new Container(field.get(instance), annotation.uniqueId())); + } catch (Throwable t) { + t.printStackTrace(); + } } } } diff --git a/src/main/scala/io/izzel/taboolib/module/inject/TFunctionLoader.java b/src/main/scala/io/izzel/taboolib/module/inject/TFunctionLoader.java index 3c24028..58a9fac 100644 --- a/src/main/scala/io/izzel/taboolib/module/inject/TFunctionLoader.java +++ b/src/main/scala/io/izzel/taboolib/module/inject/TFunctionLoader.java @@ -1,13 +1,10 @@ package io.izzel.taboolib.module.inject; import io.izzel.taboolib.TabooLibLoader; -import io.izzel.taboolib.compat.kotlin.CompatKotlin; -import io.izzel.taboolib.module.locale.logger.TLogger; import org.bukkit.plugin.Plugin; import java.lang.annotation.Annotation; import java.lang.reflect.Method; -import java.lang.reflect.Modifier; /** * @Author sky @@ -17,65 +14,49 @@ public class TFunctionLoader implements TabooLibLoader.Loader { @Override public void preLoad(Plugin plugin, Class pluginClass) { - invokeMethods(pluginClass, TFunction.Load.class); + invokeMethods(plugin, pluginClass, TFunction.Load.class); } @Override public void postLoad(Plugin plugin, Class pluginClass) { - invokeMethods(pluginClass, true); - invokeMethods(pluginClass, TFunction.Init.class); + invokeMethods(plugin, pluginClass, true); + invokeMethods(plugin, pluginClass, TFunction.Init.class); } @Override public void unload(Plugin plugin, Class pluginClass) { - invokeMethods(pluginClass, false); - invokeMethods(pluginClass, TFunction.Cancel.class); + invokeMethods(plugin, pluginClass, false); + invokeMethods(plugin, pluginClass, TFunction.Cancel.class); } - public void invokeMethods(Class pluginClass, boolean enable) { + public void invokeMethods(Plugin plugin, Class pluginClass, boolean enable) { if (pluginClass.isAnnotationPresent(TFunction.class)) { TFunction function = pluginClass.getAnnotation(TFunction.class); try { - Object instance = null; Method method = pluginClass.getDeclaredMethod(enable ? function.enable() : function.disable()); - if (CompatKotlin.isCompanion(pluginClass)) { - instance = CompatKotlin.getCompanion(pluginClass); - if (instance == null) { - TLogger.getGlobalLogger().error(method.getName() + " required @JvmStatic."); - return; - } - } else if (!Modifier.isStatic(method.getModifiers())) { - TLogger.getGlobalLogger().error(method.getName() + " is not a static method."); - return; - } method.setAccessible(true); - method.invoke(instance); + for (Object instance : TInjectHelper.getInstance(method, pluginClass, plugin)) { + try { + method.invoke(instance); + } catch (Throwable t) { + t.printStackTrace(); + } + } } catch (NoSuchMethodException ignore) { - } catch (Exception e) { - e.printStackTrace(); } } } - public void invokeMethods(Class pluginClass, Class a) { + public void invokeMethods(Plugin plugin, Class pluginClass, Class a) { for (Method declaredMethod : pluginClass.getDeclaredMethods()) { if (declaredMethod.isAnnotationPresent(a)) { - try { - Object instance = null; - if (CompatKotlin.isCompanion(pluginClass)) { - instance = CompatKotlin.getCompanion(pluginClass); - if (instance == null) { - TLogger.getGlobalLogger().error(declaredMethod.getName() + " required @JvmStatic."); - return; - } - } else if (!Modifier.isStatic(declaredMethod.getModifiers())) { - TLogger.getGlobalLogger().error(declaredMethod.getName() + " is not a static method."); - return; + declaredMethod.setAccessible(true); + for (Object instance : TInjectHelper.getInstance(declaredMethod, pluginClass, plugin)) { + try { + declaredMethod.invoke(instance); + } catch (Throwable t) { + t.printStackTrace(); } - declaredMethod.setAccessible(true); - declaredMethod.invoke(instance); - } catch (Throwable t) { - t.printStackTrace(); } } } diff --git a/src/main/scala/io/izzel/taboolib/module/inject/THookLoader.java b/src/main/scala/io/izzel/taboolib/module/inject/THookLoader.java index 3412548..d617698 100644 --- a/src/main/scala/io/izzel/taboolib/module/inject/THookLoader.java +++ b/src/main/scala/io/izzel/taboolib/module/inject/THookLoader.java @@ -2,14 +2,12 @@ package io.izzel.taboolib.module.inject; import io.izzel.taboolib.TabooLibAPI; import io.izzel.taboolib.TabooLibLoader; -import io.izzel.taboolib.module.locale.logger.TLogger; import io.izzel.taboolib.util.Ref; import io.izzel.taboolib.util.Strings; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import java.lang.reflect.Field; -import java.lang.reflect.Modifier; /** * @Author sky @@ -29,22 +27,13 @@ public class THookLoader implements TabooLibLoader.Loader { if (Plugin.class.isAssignableFrom(declaredField.getType()) && declaredField.isAnnotationPresent(THook.class)) { THook hook = declaredField.getAnnotation(THook.class); if (Strings.nonEmpty(hook.plugin())) { - Object instance = null; - // 如果是非静态类型 - if (!Modifier.isStatic(declaredField.getModifiers())) { - // 是否为主类 - if (pluginClass.equals(plugin.getClass())) { - instance = plugin; - } else { - TLogger.getGlobalLogger().error(declaredField.getName() + " is not a static field. (" + pluginClass.getName() + ")"); - continue; - } - } Ref.forcedAccess(declaredField); - try { - declaredField.set(instance, Bukkit.getPluginManager().getPlugin(hook.plugin())); - } catch (Throwable t) { - t.printStackTrace(); + for (Object instance : TInjectHelper.getInstance(declaredField, pluginClass, plugin)) { + try { + declaredField.set(instance, Bukkit.getPluginManager().getPlugin(hook.plugin())); + } catch (Throwable t) { + t.printStackTrace(); + } } } } diff --git a/src/main/scala/io/izzel/taboolib/module/inject/TInjectAsm.java b/src/main/scala/io/izzel/taboolib/module/inject/TInjectAsm.java index 8712734..c2b3e1d 100644 --- a/src/main/scala/io/izzel/taboolib/module/inject/TInjectAsm.java +++ b/src/main/scala/io/izzel/taboolib/module/inject/TInjectAsm.java @@ -2,12 +2,10 @@ package io.izzel.taboolib.module.inject; import io.izzel.taboolib.TabooLibLoader; import io.izzel.taboolib.module.lite.SimpleVersionControl; -import io.izzel.taboolib.module.locale.logger.TLogger; import io.izzel.taboolib.util.Ref; import org.bukkit.plugin.Plugin; import java.lang.reflect.Field; -import java.lang.reflect.Modifier; /** * @Author sky @@ -22,22 +20,13 @@ public class TInjectAsm implements TabooLibLoader.Loader { if (annotation == null || annotation.asm().isEmpty()) { continue; } - Object instance = null; - // 如果是非静态类型 - if (!Modifier.isStatic(declaredField.getModifiers())) { - // 是否为主类 - if (pluginClass.equals(plugin.getClass())) { - instance = plugin; - } else { - TLogger.getGlobalLogger().error(declaredField.getName() + " is not a static field. (" + pluginClass.getName() + ")"); - continue; - } - } Ref.forcedAccess(declaredField); - try { - declaredField.set(instance, SimpleVersionControl.createNMS(annotation.asm()).useCache().translate(plugin).newInstance()); - } catch (Throwable t) { - TLogger.getGlobalLogger().warn("Cannot translate class \"" + declaredField.getType().getName() + "\": " + t.getMessage()); + for (Object instance : TInjectHelper.getInstance(declaredField, pluginClass, plugin)) { + try { + declaredField.set(instance, SimpleVersionControl.createNMS(annotation.asm()).useCache().translate(plugin).newInstance()); + } catch (Throwable t) { + t.printStackTrace(); + } } } } diff --git a/src/main/scala/io/izzel/taboolib/module/inject/TInjectCreator.java b/src/main/scala/io/izzel/taboolib/module/inject/TInjectCreator.java index a8aa7ab..5bdb0fa 100644 --- a/src/main/scala/io/izzel/taboolib/module/inject/TInjectCreator.java +++ b/src/main/scala/io/izzel/taboolib/module/inject/TInjectCreator.java @@ -8,7 +8,7 @@ import io.izzel.taboolib.util.Reflection; import org.bukkit.plugin.Plugin; import java.lang.reflect.Field; -import java.lang.reflect.Modifier; +import java.util.List; import java.util.Map; import java.util.Objects; @@ -54,27 +54,15 @@ public class TInjectCreator implements TabooLibLoader.Loader { if (annotation == null || annotation.state() != state) { continue; } - ClassData classData = new ClassData(loadClass, declaredField.getType()); - Object instance = null; - // 非静态类型 - if (!Modifier.isStatic(declaredField.getModifiers())) { - // 在插件主类 - if (loadClass.equals(plugin.getClass())) { - instance = plugin; - } - // 判断 pluginCLass 是否为 TInject 创建 - else if (instanceMap.containsKey(classData)) { - instance = instanceMap.get(classData).getInstance(); - } else { - TLogger.getGlobalLogger().error(declaredField.getName() + " is not a static field. (" + loadClass.getName() + ")"); - continue; - } + List instance = TInjectHelper.getInstance(declaredField, loadClass, plugin); + if (instance.isEmpty()) { + continue; } Ref.forcedAccess(declaredField); try { InstanceData instanceData = new InstanceData(declaredField.getType().newInstance(), annotation); declaredField.set(instance, instanceData.getInstance()); - instanceMap.put(classData, instanceData); + instanceMap.put(new ClassData(loadClass, declaredField.getType()), instanceData); } catch (Throwable t) { TLogger.getGlobalLogger().error(declaredField.getName() + " instantiation failed: " + t.getMessage()); } diff --git a/src/main/scala/io/izzel/taboolib/module/inject/TInjectHelper.java b/src/main/scala/io/izzel/taboolib/module/inject/TInjectHelper.java index 3df82fa..ed76371 100644 --- a/src/main/scala/io/izzel/taboolib/module/inject/TInjectHelper.java +++ b/src/main/scala/io/izzel/taboolib/module/inject/TInjectHelper.java @@ -1,5 +1,15 @@ package io.izzel.taboolib.module.inject; +import com.google.common.collect.Lists; +import io.izzel.taboolib.compat.kotlin.CompatKotlin; +import io.izzel.taboolib.module.locale.logger.TLogger; +import org.bukkit.plugin.Plugin; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.List; + /** * @Author sky * @Since 2019-08-17 23:22 @@ -23,4 +33,60 @@ public class TInjectHelper { return inject.cancel(); } } + + public static List getInstance(Field field, Class pluginClass, Plugin plugin) { + List instance = Lists.newArrayList(); + // Static + if (Modifier.isStatic(field.getModifiers())) { + instance.add(null); + } + // No Static + else if (!Modifier.isStatic(field.getModifiers())) { + // Main + if (pluginClass.equals(plugin.getClass())) { + instance.add(plugin); + } + // TInject + else if (TInjectCreator.getInstanceMap().entrySet().stream().anyMatch(e -> e.getKey().getType().equals(pluginClass))) { + TInjectCreator.getInstanceMap().entrySet().stream().filter(e -> e.getKey().getType().equals(pluginClass)).forEach(i -> instance.add(i.getValue().getInstance())); + } + } + // Nothing + else if (instance.isEmpty()) { + TLogger.getGlobalLogger().error(field.getName() + " is not a static field. (" + pluginClass.getName() + ")"); + } + return instance; + } + + public static List getInstance(Method method, Class pluginClass, Plugin plugin) { + List instance = Lists.newArrayList(); + // Object + if (CompatKotlin.getInstance(pluginClass) != null) { + instance.add(CompatKotlin.getInstance(pluginClass)); + } + // Companion Object + else if (CompatKotlin.isCompanion(pluginClass)) { + instance.add(CompatKotlin.getCompanion(pluginClass)); + } + // Static + else if (Modifier.isStatic(method.getModifiers())) { + instance.add(null); + } + // No Static + else if (!Modifier.isStatic(method.getModifiers())) { + // Main + if (pluginClass.equals(plugin.getClass())) { + instance.add(plugin); + } + // TInject + else if (TInjectCreator.getInstanceMap().entrySet().stream().anyMatch(e -> e.getKey().getType().equals(pluginClass))) { + TInjectCreator.getInstanceMap().entrySet().stream().filter(e -> e.getKey().getType().equals(pluginClass)).forEach(i -> instance.add(i.getValue().getInstance())); + } + } + // Nothing + else if (instance.isEmpty()) { + TLogger.getGlobalLogger().error(method.getName() + " is not a static method. (" + pluginClass.getName() + ")"); + } + return instance; + } } diff --git a/src/main/scala/io/izzel/taboolib/module/inject/TInjectLoader.java b/src/main/scala/io/izzel/taboolib/module/inject/TInjectLoader.java index d89db23..eae1ed6 100644 --- a/src/main/scala/io/izzel/taboolib/module/inject/TInjectLoader.java +++ b/src/main/scala/io/izzel/taboolib/module/inject/TInjectLoader.java @@ -17,7 +17,6 @@ import org.bukkit.plugin.java.JavaPlugin; import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.util.Map; /** @@ -135,22 +134,11 @@ public class TInjectLoader implements TabooLibLoader.Loader { public void preLoad(Plugin plugin, Class pluginClass) { for (Field declaredField : pluginClass.getDeclaredFields()) { TInject annotation = declaredField.getAnnotation(TInject.class); - // 是否为主类类型 if (annotation == null || !declaredField.getType().equals(plugin.getClass())) { continue; } - Object instance = null; - // 如果是非静态类型 - if (!Modifier.isStatic(declaredField.getModifiers())) { - // 是否为主类 - if (pluginClass.equals(plugin.getClass())) { - instance = plugin; - } else { - TLogger.getGlobalLogger().error(declaredField.getName() + " is not a static field. (" + pluginClass.getName() + ")"); - continue; - } - } - inject(plugin, declaredField, instance, annotation, injectTypes.get(Plugin.class), pluginClass); + Ref.forcedAccess(declaredField); + TInjectHelper.getInstance(declaredField, pluginClass, plugin).forEach(instance -> inject(plugin, declaredField, instance, annotation, injectTypes.get(Plugin.class), pluginClass)); } } @@ -161,26 +149,15 @@ public class TInjectLoader implements TabooLibLoader.Loader { if (annotation == null || declaredField.getType().equals(plugin.getClass())) { continue; } - Object instance = null; - // 如果是非静态类型 - if (!Modifier.isStatic(declaredField.getModifiers())) { - // 是否为主类 - if (pluginClass.equals(plugin.getClass())) { - instance = plugin; - } else { - TLogger.getGlobalLogger().error(declaredField.getName() + " is not a static field. (" + pluginClass.getName() + ")"); - continue; - } - } + Ref.forcedAccess(declaredField); TInjectTask tInjectTask = injectTypes.get(declaredField.getType()); if (tInjectTask != null) { - inject(plugin, declaredField, instance, annotation, tInjectTask, pluginClass); + TInjectHelper.getInstance(declaredField, pluginClass, plugin).forEach(instance -> inject(plugin, declaredField, instance, annotation, tInjectTask, pluginClass)); } } } public void inject(Plugin plugin, Field field, Object instance, TInject annotation, TInjectTask injectTask, Class pluginClass) { - Ref.forcedAccess(field); try { injectTask.run(plugin, field, annotation, pluginClass, instance); TabooLibAPI.debug(field.getName() + " injected. (" + field.getType().getName() + ")"); diff --git a/src/main/scala/io/izzel/taboolib/module/inject/TScheduleLoader.java b/src/main/scala/io/izzel/taboolib/module/inject/TScheduleLoader.java index ad4af95..9b2f9d7 100644 --- a/src/main/scala/io/izzel/taboolib/module/inject/TScheduleLoader.java +++ b/src/main/scala/io/izzel/taboolib/module/inject/TScheduleLoader.java @@ -4,13 +4,10 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import io.izzel.taboolib.TabooLib; import io.izzel.taboolib.TabooLibLoader; -import io.izzel.taboolib.compat.kotlin.CompatKotlin; -import io.izzel.taboolib.module.locale.logger.TLogger; import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.util.List; import java.util.Map; @@ -44,27 +41,18 @@ public class TScheduleLoader implements TabooLibLoader.Loader { if (annotation == null) { continue; } - Object[] instance = new Object[] {pluginClass.equals(plugin.getClass()) ? plugin : null}; - if (CompatKotlin.isCompanion(pluginClass)) { - instance[0] = CompatKotlin.getCompanion(pluginClass); - if (instance[0] == null) { - TLogger.getGlobalLogger().error(method.getName() + " required @JvmStatic."); - return; - } - } else if (!Modifier.isStatic(method.getModifiers()) && instance[0] == null) { - TLogger.getGlobalLogger().error(method.getName() + " is not a static method."); - continue; - } + method.setAccessible(true); if (plugin.equals(TabooLib.getPlugin())) { run(plugin, new BukkitRunnable() { @Override public void run() { - try { - method.setAccessible(true); - method.invoke(instance[0]); - } catch (Throwable t) { - t.printStackTrace(); + for (Object i : TInjectHelper.getInstance(method, pluginClass, plugin)) { + try { + method.invoke(i); + } catch (Throwable t) { + t.printStackTrace(); + } } } }, annotation.delay(), annotation.period(), annotation.async()); @@ -73,11 +61,12 @@ public class TScheduleLoader implements TabooLibLoader.Loader { @Override public void run() { - try { - method.setAccessible(true); - method.invoke(instance[0]); - } catch (Throwable t) { - t.printStackTrace(); + for (Object i : TInjectHelper.getInstance(method, pluginClass, plugin)) { + try { + method.invoke(i); + } catch (Throwable t) { + t.printStackTrace(); + } } } })); diff --git a/src/main/scala/io/izzel/taboolib/module/packet/TPacketLoader.java b/src/main/scala/io/izzel/taboolib/module/packet/TPacketLoader.java index 0262030..85d1acc 100644 --- a/src/main/scala/io/izzel/taboolib/module/packet/TPacketLoader.java +++ b/src/main/scala/io/izzel/taboolib/module/packet/TPacketLoader.java @@ -1,13 +1,14 @@ package io.izzel.taboolib.module.packet; import io.izzel.taboolib.TabooLibLoader; +import io.izzel.taboolib.module.inject.TInjectHelper; import io.izzel.taboolib.module.locale.logger.TLogger; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.util.Arrays; +import java.util.List; /** * @Author sky @@ -19,49 +20,44 @@ public class TPacketLoader implements TabooLibLoader.Loader { public void activeLoad(Plugin plugin, Class pluginClass) { for (Method method : pluginClass.getDeclaredMethods()) { if (method.isAnnotationPresent(TPacket.class)) { - Object instance = null; - // 如果是非静态类型 - if (!Modifier.isStatic(method.getModifiers())) { - // 是否为主类 - if (pluginClass.equals(plugin.getClass())) { - instance = plugin; - } else { - TLogger.getGlobalLogger().error(method.getName() + " is not a static method. (" + pluginClass.getName() + ")"); - continue; - } + List instance = TInjectHelper.getInstance(method, pluginClass, plugin); + if (instance.isEmpty()) { + continue; } method.setAccessible(true); TPacket packet = method.getAnnotation(TPacket.class); boolean packetType = method.getReturnType().equals(Boolean.TYPE) || method.getReturnType().equals(Boolean.class); // object type if (Arrays.equals(method.getParameterTypes(), new Class[] {Player.class, Object.class})) { - Object finalInstance = instance; - TPacketHandler.addListener(plugin, new TPacketListener() { - @Override - public boolean onSend(Player player, Object p) { - return eval(finalInstance, packet, TPacket.Type.SEND, packetType, method, player, p); - } + for (Object i : instance) { + TPacketHandler.addListener(plugin, new TPacketListener() { + @Override + public boolean onSend(Player player, Object p) { + return eval(i, packet, TPacket.Type.SEND, packetType, method, player, p); + } - @Override - public boolean onReceive(Player player, Object p) { - return eval(finalInstance, packet, TPacket.Type.RECEIVE, packetType, method, player, p); - } - }); + @Override + public boolean onReceive(Player player, Object p) { + return eval(i, packet, TPacket.Type.RECEIVE, packetType, method, player, p); + } + }); + } } // packet type else if (Arrays.equals(method.getParameterTypes(), new Class[] {Player.class, Packet.class})) { - Object finalInstance1 = instance; - TPacketHandler.addListener(plugin, new TPacketListener() { - @Override - public boolean onSend(Player player, Packet p) { - return eval(finalInstance1, packet, TPacket.Type.SEND, packetType, method, player, p); - } + for (Object i : instance) { + TPacketHandler.addListener(plugin, new TPacketListener() { + @Override + public boolean onSend(Player player, Packet p) { + return eval(i, packet, TPacket.Type.SEND, packetType, method, player, p); + } - @Override - public boolean onReceive(Player player, Packet p) { - return eval(finalInstance1, packet, TPacket.Type.RECEIVE, packetType, method, player, p); - } - }); + @Override + public boolean onReceive(Player player, Packet p) { + return eval(i, packet, TPacket.Type.RECEIVE, packetType, method, player, p); + } + }); + } } else { TLogger.getGlobalLogger().error(method.getName() + " is an invalid packet listener. (" + pluginClass.getName() + ")"); TLogger.getGlobalLogger().error("Usage: boolean fun(Player player, Object packet) { ... }");