From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: rafaelflromao <12960698+rafaelflromao@users.noreply.github.com> Date: Mon, 12 Jun 2023 06:01:40 +0100 Subject: [PATCH] Petal: Sync event calls on async threads Original code by Bloom-host, licensed under GPL v3 You can find the original code on https://github.com/Bloom-host/Petal 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 2632dade6bfaa185a94e95210a31dc3824b7746f..9687d4a87112a6ed991935321ef15f32dd116b48 100644 --- a/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java +++ b/src/main/java/io/papermc/paper/plugin/manager/PaperEventManager.java @@ -45,7 +45,7 @@ class PaperEventManager { throw new IllegalStateException(event.getEventName() + " may only be triggered asynchronously."); } else if (!isAsync && !onPrimaryThread && !this.server.isStopping()) { // Mirai start - if (org.dreeam.leaf.LeafConfig.enableAsyncEntityTracker) { + if (org.dreeam.leaf.LeafConfig.enableAsyncEntityTracker || org.dreeam.leaf.LeafConfig.enableSyncEventCallsOnAsyncThreads) { MinecraftServer.getServer().scheduleOnMain(event::callEvent); return; } else { diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java index 2aea6580eaa3702a2eead379e7d2e21879543c3b..2eda021e11216013af7875371797b387b6c018f9 100644 --- a/src/main/java/org/dreeam/leaf/LeafConfig.java +++ b/src/main/java/org/dreeam/leaf/LeafConfig.java @@ -201,6 +201,8 @@ public class LeafConfig { public static boolean enableAsyncPathfindingInitialized; public static boolean enableAsyncEntityTracker; public static boolean enableAsyncEntityTrackerInitialized; + public static boolean enableSyncEventCallsOnAsyncThreads; + public static boolean enableSyncEventCallsOnAsyncThreadsInitialized; private static void performance() { String sentryEnvironment = System.getenv("SENTRY_DSN"); String sentryConfig = getString("performance.sentry-dsn", sentryDsn, "Sentry DSN for improved error logging, leave blank to disable", "Obtain from https://sentry.io/"); @@ -271,6 +273,13 @@ public class LeafConfig { enableAsyncEntityTrackerInitialized = true; enableAsyncEntityTracker = asyncEntityTracker; } + boolean syncEventCalls = getBoolean("performance.enable-sync-event-calls-on-async-threads", true, + "Whether or not sync event calls on async threads should be enabled. (If async entity tracker is enabled, this is enabled.)", + "You may encounter issues with plugins."); + if (!enableSyncEventCallsOnAsyncThreadsInitialized) { + enableSyncEventCallsOnAsyncThreadsInitialized = true; + enableSyncEventCallsOnAsyncThreads = syncEventCalls; + } } public static boolean jadeProtocol = false;