mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
48 lines
2.7 KiB
Diff
48 lines
2.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Bjarne Koll <lynxplay101@gmail.com>
|
|
Date: Thu, 9 Dec 2021 01:53:30 +0100
|
|
Subject: [PATCH] KTP: Optimize Spigot event bus
|
|
|
|
Original license: GPL v3
|
|
Original project: https://github.com/lynxplay/ktp
|
|
|
|
diff --git a/src/main/java/org/bukkit/plugin/RegisteredListener.java b/src/main/java/org/bukkit/plugin/RegisteredListener.java
|
|
index 3b3d9642a8d63798dc28f2f8df77f0466451cbff..8d3605f25e97a375971705c737bc7bacbac045cd 100644
|
|
--- a/src/main/java/org/bukkit/plugin/RegisteredListener.java
|
|
+++ b/src/main/java/org/bukkit/plugin/RegisteredListener.java
|
|
@@ -62,8 +62,10 @@ public class RegisteredListener {
|
|
* @throws EventException If an event handler throws an exception.
|
|
*/
|
|
public void callEvent(@NotNull final Event event) throws EventException {
|
|
- if (event instanceof Cancellable) {
|
|
- if (((Cancellable) event).isCancelled() && isIgnoringCancelled()) {
|
|
+ // KTP start - optimize spigot event bus
|
|
+ if (isIgnoringCancelled()) {
|
|
+ if (event instanceof Cancellable cancellable && cancellable.isCancelled()) {
|
|
+ // KTP end - optimize spigot event bus
|
|
return;
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
|
index c077e7c883613fcb6e559b4e4776e794caa3b363..ba869354adc59db2fc547c481c1ed4d5d0af23b7 100644
|
|
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
|
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
|
@@ -656,11 +656,15 @@ public final class SimplePluginManager implements PluginManager {
|
|
@Override
|
|
public void callEvent(@NotNull Event event) {
|
|
// Paper - replace callEvent by merging to below method
|
|
- if (event.isAsynchronous() && server.isPrimaryThread()) {
|
|
+ // KTP start - optimize spigot event bus
|
|
+ final boolean isAsync = event.isAsynchronous();
|
|
+ final boolean isPrimary = server.isPrimaryThread(); // Cache to prevent multiple thread object comparisons.
|
|
+ if (isAsync && isPrimary) {
|
|
throw new IllegalStateException(event.getEventName() + " may only be triggered asynchronously.");
|
|
- } else if (!event.isAsynchronous() && !server.isPrimaryThread() && !server.isStopping() ) {
|
|
+ } else if (!isAsync && !isPrimary && !server.isStopping() ) {
|
|
throw new IllegalStateException(event.getEventName() + " may only be triggered synchronously.");
|
|
}
|
|
+ // KTP end - optimize spigot event bus
|
|
|
|
HandlerList handlers = event.getHandlers();
|
|
RegisteredListener[] listeners = handlers.getRegisteredListeners();
|