mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-20 15:39:37 +00:00
38 lines
2.0 KiB
Diff
38 lines
2.0 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Bjarne Koll <lynxplay101@gmail.com>
|
|
Date: Sun, 19 Feb 2023 16:14:28 +0100
|
|
Subject: [PATCH] KTP: Allow unknown event thread execution
|
|
|
|
Original license: GPL v3
|
|
Original project: https://github.com/lynxplay/ktp
|
|
|
|
This patch allows events to actively define that they may or may not be
|
|
called on the main thread of the server.
|
|
This is preferred over passing the "asyncness" of the event as async
|
|
bool parameter to the event instance every time.
|
|
|
|
diff --git a/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java b/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java
|
|
index a1c9726d25479b5326fe2fa2b0f5a98d6b2da4c5..06dfd0b27ac0006a2be07f54a0702519a691c6ec 100644
|
|
--- a/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java
|
|
+++ b/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java
|
|
@@ -35,11 +35,17 @@ class PaperEventManager {
|
|
|
|
// SimplePluginManager
|
|
public void callEvent(@NotNull Event event) {
|
|
- if (event.isAsynchronous() && this.server.isPrimaryThread()) {
|
|
+ // KTP start - Optimise spigot event bus
|
|
+ if (event.asynchronous() != net.kyori.adventure.util.TriState.NOT_SET) {
|
|
+ final boolean onPrimaryThread = this.server.isPrimaryThread();
|
|
+ final boolean isAsync = event.isAsynchronous();
|
|
+ if (isAsync && onPrimaryThread) {
|
|
throw new IllegalStateException(event.getEventName() + " may only be triggered asynchronously.");
|
|
- } else if (!event.isAsynchronous() && !this.server.isPrimaryThread() && !this.server.isStopping()) {
|
|
+ } else if (!isAsync && !onPrimaryThread && !this.server.isStopping()) {
|
|
throw new IllegalStateException(event.getEventName() + " may only be triggered synchronously.");
|
|
}
|
|
+ // KTP stop - Optimise spigot event bus
|
|
+ }
|
|
|
|
HandlerList handlers = event.getHandlers();
|
|
RegisteredListener[] listeners = handlers.getRegisteredListeners();
|