From 456f7dd6600c1ab2c745c17bcb96371e5c2d5cae Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 27 Aug 2022 21:04:35 +0200 Subject: [PATCH] Optimize listener injection Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/linkage/LinkageProcessor.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/BauSystem_Linkage/src/de/steamwar/bausystem/linkage/LinkageProcessor.java b/BauSystem_Linkage/src/de/steamwar/bausystem/linkage/LinkageProcessor.java index e799c597..5c2e83a2 100644 --- a/BauSystem_Linkage/src/de/steamwar/bausystem/linkage/LinkageProcessor.java +++ b/BauSystem_Linkage/src/de/steamwar/bausystem/linkage/LinkageProcessor.java @@ -131,6 +131,10 @@ public class LinkageProcessor extends AbstractProcessor { if (!eventMethods.isEmpty()) { List eventLines = new ArrayList<>(); linkLines.put(LinkageType.LISTENER, eventLines); + eventClasses.forEach((s, typeElement) -> { + eventLines.add("handlerList" + typeElement.getSimpleName().toString() + " = " + typeElement.getQualifiedName().toString() + ".getHandlerList()"); + }); + eventLines.add(""); eventMethods.forEach((typeElement, map) -> { String instance = "local" + typeElement.getSimpleName().toString(); eventLines.add(typeElement.getQualifiedName().toString() + " " + instance + " = " + getElement(typeElement, neededFields)); @@ -227,7 +231,7 @@ public class LinkageProcessor extends AbstractProcessor { writer.write("\n"); } for (Map.Entry entry : eventClasses.entrySet()) { - writer.write(" private static org.bukkit.event.HandlerList handlerList" + entry.getValue().getSimpleName().toString() + " = " + entry.getKey() + ".getHandlerList();\n"); + writer.write(" private static org.bukkit.event.HandlerList handlerList" + entry.getValue().getSimpleName().toString() + ";\n"); writer.write(" private static void " + entry.getValue().getSimpleName().toString() + "(org.bukkit.event.Listener listener, java.util.function.Consumer<" + entry.getKey() + "> consumer, org.bukkit.event.EventPriority eventPriority, boolean ignoreCancelled) {\n"); writer.write(" org.bukkit.plugin.EventExecutor eventExecutor = (l, event) -> {\n"); writer.write(" if (event instanceof " + entry.getKey() + ") {\n");