diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 52ccecf4..4108c067 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ #Tue Sep 24 15:14:52 CEST 2019 -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists diff --git a/src/main/java/net/minecraftforge/eventbus/EventBus.java b/src/main/java/net/minecraftforge/eventbus/EventBus.java index 2b6a0f02..5dd51561 100644 --- a/src/main/java/net/minecraftforge/eventbus/EventBus.java +++ b/src/main/java/net/minecraftforge/eventbus/EventBus.java @@ -149,19 +149,18 @@ public void addListener(final Consumer consumer) { addListener(EventPriority.NORMAL, consumer); } - @Override public void addListener(final EventPriority priority, final Consumer consumer) { addListener(priority, false, consumer); } @Override public void addListener(final EventPriority priority, final boolean receiveCancelled, final Consumer consumer) { - addListener(priority, passCancelled(receiveCancelled), consumer); + addListenerWithTypetools(priority, passCancelled(receiveCancelled), consumer); } @Override public void addListener(final EventPriority priority, final boolean receiveCancelled, final Class eventType, final Consumer consumer) { - addListener(priority, passCancelled(receiveCancelled), eventType, consumer); + addListenerWithExplicitClass(priority, passCancelled(receiveCancelled), eventType, consumer); } @Override @@ -176,16 +175,16 @@ public , F> void addGenericListener(final Cl @Override public , F> void addGenericListener(final Class genericClassFilter, final EventPriority priority, final boolean receiveCancelled, final Consumer consumer) { - addListener(priority, passGenericFilter(genericClassFilter).and(passCancelled(receiveCancelled)), consumer); + addListenerWithTypetools(priority, passGenericFilter(genericClassFilter).and(passCancelled(receiveCancelled)), consumer); } @Override public , F> void addGenericListener(final Class genericClassFilter, final EventPriority priority, final boolean receiveCancelled, final Class eventType, final Consumer consumer) { - addListener(priority, passGenericFilter(genericClassFilter).and(passCancelled(receiveCancelled)), eventType, consumer); + addListenerWithExplicitClass(priority, passGenericFilter(genericClassFilter).and(passCancelled(receiveCancelled)), eventType, consumer); } @SuppressWarnings("unchecked") - private void addListener(final EventPriority priority, final Predicate filter, final Consumer consumer) { + private void addListenerWithTypetools(final EventPriority priority, final Predicate filter, final Consumer consumer) { final Class eventClass = (Class) TypeResolver.resolveRawArgument(Consumer.class, consumer.getClass()); if ((Class) eventClass == TypeResolver.Unknown.class) { @@ -199,14 +198,14 @@ private void addListener(final EventPriority priority, final P + "the generic type information is erased and cannot be recovered at runtime."); } - addListener(priority, filter, eventClass, consumer); + addListenerWithExplicitClass(priority, filter, eventClass, consumer); } - private void addListener(final EventPriority priority, final Predicate filter, final Class eventClass, final Consumer consumer) { - addListener(priority, filter, eventClass, consumer, consumer); + private void addListenerWithExplicitClass(final EventPriority priority, final Predicate filter, final Class eventClass, final Consumer consumer) { + addListenerWithExplicitClass(priority, filter, eventClass, consumer, consumer); } - private void addListener(final EventPriority priority, final Predicate filter, final Class eventClass, final Consumer consumer, final Object context) { + private void addListenerWithExplicitClass(final EventPriority priority, final Predicate filter, final Class eventClass, final Consumer consumer, final Object context) { IEventListener listener = event -> doCastFilter(filter, consumer, event); ListenerList listenerList = EventListenerHelper.getListenerList(eventClass); diff --git a/src/main/java/net/minecraftforge/eventbus/api/IEventBus.java b/src/main/java/net/minecraftforge/eventbus/api/IEventBus.java index 12a3af1d..2790f977 100644 --- a/src/main/java/net/minecraftforge/eventbus/api/IEventBus.java +++ b/src/main/java/net/minecraftforge/eventbus/api/IEventBus.java @@ -36,6 +36,10 @@ public interface IEventBus { */ void addListener(Consumer consumer); + default void addExplicitListener(Consumer consumer, Class eventClass) { + addListener(EventPriority.NORMAL, false, eventClass, consumer); + } + /** * Add a consumer listener with the specified {@link EventPriority} and not receiving cancelled events. * @@ -45,6 +49,10 @@ public interface IEventBus { */ void addListener(EventPriority priority, Consumer consumer); + default void addExplicitListener(EventPriority priority, Consumer consumer, Class eventClass) { + addListener(priority, false, eventClass, consumer); + } + /** * Add a consumer listener with the specified {@link EventPriority} and potentially cancelled events. * @@ -68,7 +76,6 @@ public interface IEventBus { * @param The {@link Event} subclass to listen for */ void addListener(EventPriority priority, boolean receiveCancelled, Class eventType, Consumer consumer); - /** * Add a consumer listener for a {@link GenericEvent} subclass, filtered to only be called for the specified * filter {@link Class}.