Optimized Spigot event bus
This commit is contained in:
47
patches/api/0001-Optimize-Spigot-event-bus.patch
Normal file
47
patches/api/0001-Optimize-Spigot-event-bus.patch
Normal file
@@ -0,0 +1,47 @@
|
||||
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] Optimize Spigot event bus
|
||||
|
||||
Original code by lynxplay, licensed under GNU General Public License v3.0
|
||||
You can find the original code on 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 419aec56b0e3fa8bcec2ea7f340caa3456b57d00..8530d926931a54ed1300c40cd1e0908b2d9b594d 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 6bb115923767c4bd65b18e67eeff5408f2894ab0..b0e11ed48e06abd585bd9dded52945562a8c6830 100644
|
||||
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||
@@ -660,11 +660,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();
|
||||
Reference in New Issue
Block a user