From 5ad8a3fc837175f0030f09f7a6a29b478166f2ec Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 13 Nov 2020 22:54:58 +0800 Subject: [PATCH] Lazily initialize event invokers --- .../me/shedaniel/architectury/event/EventFactory.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 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 741a6c9b..a9db666d 100644 --- a/common/src/main/java/me/shedaniel/architectury/event/EventFactory.java +++ b/common/src/main/java/me/shedaniel/architectury/event/EventFactory.java @@ -122,7 +122,6 @@ public final class EventFactory { this.clazz = Objects.requireNonNull(clazz); this.function = function; this.listeners = emptyArray(); - update(); } private T[] emptyArray() { @@ -135,19 +134,22 @@ public final class EventFactory { @Override public T invoker() { + if (invoker == null) { + update(); + } return invoker; } @Override public void register(T listener) { listeners = ArrayUtils.add(listeners, listener); - update(); + invoker = null; } @Override public void unregister(T listener) { listeners = ArrayUtils.removeElement(listeners, listener); - update(); + invoker = null; } @Override @@ -158,7 +160,7 @@ public final class EventFactory { @Override public void clearListeners() { listeners = emptyArray(); - update(); + invoker = null; } public void update() {