Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions common/src/main/java/dev/architectury/event/EventFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static <T> Event<EventActor<T>> attachToForgeEventActorCancellable(Event<
private static class EventImpl<T> implements Event<T> {
private final Function<List<T>, T> function;
private T invoker = null;
private ArrayList<T> listeners;
private List<T> listeners;

public EventImpl(Function<List<T>, T> function) {
this.function = function;
Expand All @@ -221,7 +221,9 @@ public void register(T listener) {
@Override
public void unregister(T listener) {
listeners.remove(listener);
listeners.trimToSize();
if(listeners instanceof ArrayList<?> arrayListListeners) {
arrayListListeners.trimToSize();
}
invoker = null;
}

Expand All @@ -233,7 +235,9 @@ public boolean isRegistered(T listener) {
@Override
public void clearListeners() {
listeners.clear();
listeners.trimToSize();
if(listeners instanceof ArrayList<?> arrayListListeners) {
arrayListListeners.trimToSize();
}
invoker = null;
}

Expand Down