From 7279b4cd6e58f211af2ca13059cebce9aa46a926 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 1 Nov 2020 22:09:59 +0800 Subject: [PATCH] Fix event proxies --- .../me/shedaniel/architectury/event/EventFactory.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/me/shedaniel/architectury/event/EventFactory.java b/common/src/main/java/me/shedaniel/architectury/event/EventFactory.java index 612572ef..6a175885 100644 --- a/common/src/main/java/me/shedaniel/architectury/event/EventFactory.java +++ b/common/src/main/java/me/shedaniel/architectury/event/EventFactory.java @@ -27,7 +27,6 @@ import net.minecraft.world.InteractionResult; import org.apache.commons.lang3.ArrayUtils; import java.lang.reflect.Array; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.Objects; @@ -46,9 +45,12 @@ public final class EventFactory { @SuppressWarnings("UnstableApiUsage") public static Event createLoop(Class clazz) { - return create(ts -> (T) Proxy.newProxyInstance(EventFactory.class.getClassLoader(), new Class[]{clazz}, new AbstractInvocationHandler() { + return create(listeners -> (T) Proxy.newProxyInstance(EventFactory.class.getClassLoader(), new Class[]{clazz}, new AbstractInvocationHandler() { @Override - protected Object handleInvocation(Object proxy, Method method, Object[] args) { + protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { + for (T listener : listeners) { + method.invoke(listener, args); + } return null; } })); @@ -56,10 +58,9 @@ public final class EventFactory { @SuppressWarnings("UnstableApiUsage") public static Event createInteractionResult(Class clazz) { - return create(ts -> (T) Proxy.newProxyInstance(EventFactory.class.getClassLoader(), new Class[]{clazz}, new AbstractInvocationHandler() { + return create(listeners -> (T) Proxy.newProxyInstance(EventFactory.class.getClassLoader(), new Class[]{clazz}, new AbstractInvocationHandler() { @Override protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { - T[] listeners = (T[]) args; for (T listener : listeners) { InteractionResult result = (InteractionResult) method.invoke(listener, args); if (result != InteractionResult.PASS) {