Skip to content

Commit

Permalink
Skip event if no listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
DenaryDev committed Jun 5, 2022
1 parent 03fbf4e commit 3534a0c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions patches/api/0013-Skip-event-if-no-listeners.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: DenaryDev <[email protected]>
Date: Mon, 6 Jun 2022 00:15:47 +0500
Subject: [PATCH] Skip event if no listeners

Ported from JettPack

diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
index bab8bb3a52cdeef5f7052d4e3f404c42f37d117d..f1eba4a691437e8f3cdc342cbcfea4c93a26f94f 100644
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
@@ -650,6 +650,12 @@ public final class SimplePluginManager implements PluginManager {
*/
@Override
public void callEvent(@NotNull Event event) {
+ // Sapphire start
+ HandlerList handlers = event.getHandlers();
+ RegisteredListener[] listeners = handlers.getRegisteredListeners();
+ if (listeners.length == 0) return;
+ // Sapphire end
+
// Paper - replace callEvent by merging to below method
if (event.isAsynchronous() && server.isPrimaryThread()) {
throw new IllegalStateException(event.getEventName() + " may only be triggered asynchronously.");
@@ -657,8 +663,8 @@ public final class SimplePluginManager implements PluginManager {
throw new IllegalStateException(event.getEventName() + " may only be triggered synchronously.");
}

- HandlerList handlers = event.getHandlers();
- RegisteredListener[] listeners = handlers.getRegisteredListeners();
+ // HandlerList handlers = event.getHandlers(); // Sapphire
+ // RegisteredListener[] listeners = handlers.getRegisteredListeners(); // Sapphire

for (RegisteredListener registration : listeners) {
if (!registration.getPlugin().isEnabled()) {

0 comments on commit 3534a0c

Please sign in to comment.