Skip to content

Commit

Permalink
Remove Result and GenericEvent (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadows-of-Fire authored Feb 1, 2024
1 parent 739be09 commit ea4401c
Show file tree
Hide file tree
Showing 18 changed files with 12 additions and 468 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}
}
plugins {
id 'net.neoforged.gradleutils' version '3.0.0-alpha.5'
id 'net.neoforged.gradleutils' version '3.0.0-alpha.10'
id 'com.github.ben-manes.versions' version '0.42.0'
id 'net.neoforged.licenser' version '0.7.2' apply false
}
Expand Down
15 changes: 0 additions & 15 deletions bus-test/src/test/java/net/neoforged/bus/test/TestNoLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,6 @@ public void testThreadedEventFiring() {
doTest(new ThreadedListenerExceptionTest() {});
}

@Test
public void testGenericListener() {
doTest(new GenericListenerTests.Basic() {});
}

@Test
public void testGenericListenerRegisteredIncorrectly() {
doTest(new GenericListenerTests.IncorrectRegistration() {});
}

@Test
public void testGenericListenerWildcard() {
doTest(new GenericListenerTests.Wildcard() {});
}

@Test
public void testNonPublicEventHandler() {
doTest(new NonPublicEventHandler() {});
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public static void postCombined(Object bus)
private static void postAll(IEventBus bus)
{
bus.post(new CancellableEvent());
bus.post(new ResultEvent());
bus.post(new EventWithData("Foo", 5, true)); //Some example data
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,12 @@

public class SubscriberDynamic
{

@SubscribeEvent
public void onCancellableEvent(CancellableEvent event)
{

}

@SubscribeEvent
public void onResultEvent(ResultEvent event)
{

}

@SubscribeEvent
public void onSimpleEvent(EventWithData event)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@

public class SubscriberLambda
{

public static void register(IEventBus bus)
{
bus.addListener(SubscriberLambda::onCancellableEvent);
bus.addListener(SubscriberLambda::onResultEvent);
bus.addListener(SubscriberLambda::onSimpleEvent);
}

Expand All @@ -22,11 +20,6 @@ public static void onCancellableEvent(CancellableEvent event)

}

public static void onResultEvent(ResultEvent event)
{

}

public static void onSimpleEvent(EventWithData event)
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,12 @@

public class SubscriberStatic
{

@SubscribeEvent
public static void onCancellableEvent(CancellableEvent event)
{

}

@SubscribeEvent
public static void onResultEvent(ResultEvent event)
{

}

@SubscribeEvent
public static void onSimpleEvent(EventWithData event)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ public class DummyEvent extends Event {
public static class GoodEvent extends DummyEvent {}
public static class BadEvent extends DummyEvent {}
public static class CancellableEvent extends DummyEvent implements ICancellableEvent {}
@HasResult
public static class ResultEvent extends DummyEvent {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ public void evtMethod3(DummyEvent.CancellableEvent evt) {

}

@SubscribeEvent
public void evtMethod4(DummyEvent.ResultEvent evt) {

}


@SubscribeEvent
public void badEventMethod(DummyEvent.BadEvent evt) {
throw new RuntimeException("BARF");
Expand Down
38 changes: 1 addition & 37 deletions src/main/java/net/neoforged/bus/EventBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,6 @@ private <T extends Event> Predicate<T> passNotGenericFilter(boolean receiveCance
return receiveCanceled ? null : e -> !((ICancellableEvent) e).isCanceled();
}

private <T extends IGenericEvent<? extends F>, F> Predicate<T> passGenericFilter(Class<F> type, boolean receiveCanceled) {
return receiveCanceled ? e -> e.getGenericType() == type : e -> e.getGenericType() == type && !(e instanceof ICancellableEvent cancellable && cancellable.isCanceled());
}

private void checkNotGeneric(final Consumer<? extends Event> consumer) {
checkNotGeneric(getEventClass(consumer));
}

private void checkNotGeneric(final Class<? extends Event> eventType) {
if (IGenericEvent.class.isAssignableFrom(eventType)) {
throw new IllegalArgumentException("Cannot register a generic event listener with addListener, use addGenericListener");
}
}

@Override
public <T extends Event> void addListener(final Consumer<T> consumer) {
addListener(EventPriority.NORMAL, consumer);
Expand All @@ -201,7 +187,6 @@ public <T extends Event> void addListener(final EventPriority priority, final Co

@Override
public <T extends Event> void addListener(final EventPriority priority, final boolean receiveCanceled, final Consumer<T> consumer) {
checkNotGeneric(consumer);
addListener(priority, passNotGenericFilter(receiveCanceled), consumer);
}

Expand All @@ -227,30 +212,9 @@ public <T extends Event> void addListener(Class<T> eventType, Consumer<T> consum

@Override
public <T extends Event> void addListener(final EventPriority priority, final boolean receiveCanceled, final Class<T> eventType, final Consumer<T> consumer) {
checkNotGeneric(eventType);
addListener(priority, passNotGenericFilter(receiveCanceled), eventType, consumer);
}

@Override
public <T extends Event & IGenericEvent<? extends F>, F> void addGenericListener(final Class<F> genericClassFilter, final Consumer<T> consumer) {
addGenericListener(genericClassFilter, EventPriority.NORMAL, consumer);
}

@Override
public <T extends Event & IGenericEvent<? extends F>, F> void addGenericListener(final Class<F> genericClassFilter, final EventPriority priority, final Consumer<T> consumer) {
addGenericListener(genericClassFilter, priority, false, consumer);
}

@Override
public <T extends Event & IGenericEvent<? extends F>, F> void addGenericListener(final Class<F> genericClassFilter, final EventPriority priority, final boolean receiveCanceled, final Consumer<T> consumer) {
addListener(priority, passGenericFilter(genericClassFilter, receiveCanceled), consumer);
}

@Override
public <T extends Event & IGenericEvent<? extends F>, F> void addGenericListener(final Class<F> genericClassFilter, final EventPriority priority, final boolean receiveCanceled, final Class<T> eventType, final Consumer<T> consumer) {
addListener(priority, passGenericFilter(genericClassFilter, receiveCanceled), eventType, consumer);
}

@SuppressWarnings("unchecked")
private <T extends Event> Class<T> getEventClass(Consumer<T> consumer) {
final Class<T> eventClass = (Class<T>) TypeResolver.resolveRawArgument(Consumer.class, consumer.getClass());
Expand Down Expand Up @@ -285,7 +249,7 @@ private <T extends Event> void addListener(final EventPriority priority, @Nullab

private void register(Class<?> eventType, Object target, Method method)
{
SubscribeEventListener listener = new SubscribeEventListener(target, method, IGenericEvent.class.isAssignableFrom(eventType));
SubscribeEventListener listener = new SubscribeEventListener(target, method);
addToListeners(target, eventType, listener, listener.getPriority());
}

Expand Down
49 changes: 0 additions & 49 deletions src/main/java/net/neoforged/bus/EventListenerHelper.java

This file was deleted.

5 changes: 2 additions & 3 deletions src/main/java/net/neoforged/bus/ListenerList.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import net.neoforged.bus.api.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Semaphore;
Expand All @@ -47,8 +46,8 @@ public class ListenerList {
priorities.add(new ArrayList<>());
}

// Unwrap if the event is not cancellable and not generic
canUnwrapListeners = !ICancellableEvent.class.isAssignableFrom(eventClass) && !IGenericEvent.class.isAssignableFrom(eventClass);
// Unwrap if the event is not cancellable
canUnwrapListeners = !ICancellableEvent.class.isAssignableFrom(eventClass);
this.buildPerPhaseList = buildPerPhaseList;
}

Expand Down
Loading

0 comments on commit ea4401c

Please sign in to comment.