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 ea46848a7fd9e2642d8b5e9e4dacac8ab9074ed5..32980bd223a68e7ac2c953e953434d1fef6e0f9f 100644 --- a/src/main/java/org/dreeam/leaf/LeafConfig.java +++ b/src/main/java/org/dreeam/leaf/LeafConfig.java @@ -203,6 +203,8 @@ public class LeafConfig { public static int asyncPathfindingKeepalive = 60; public static boolean enableAsyncEntityTracker = false; public static boolean enableAsyncEntityTrackerInitialized; + public static boolean enableSyncEventCallsOnAsyncThreads = true; + public static boolean enableSyncEventCallsOnAsyncThreadsInitialized; private static void performance() { boolean asyncMobSpawning = getBoolean("performance.enable-async-mob-spawning", enableAsyncMobSpawning, "Whether or not asynchronous mob spawning should be enabled.", @@ -270,6 +272,13 @@ public class LeafConfig { enableAsyncEntityTrackerInitialized = true; enableAsyncEntityTracker = asyncEntityTracker; } + boolean syncEventCalls = getBoolean("performance.enable-sync-event-calls-on-async-threads", enableSyncEventCallsOnAsyncThreads, + "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;