diff --git a/patches/server/0026-EMC-EntityAttackedEntityEvent.patch b/patches/server/0026-EMC-EntityAttackedEntityEvent.patch index f87d284a..8b2c6127 100644 --- a/patches/server/0026-EMC-EntityAttackedEntityEvent.patch +++ b/patches/server/0026-EMC-EntityAttackedEntityEvent.patch @@ -1,4 +1,4 @@ -From e350fa29cbff4d2edf7bffd9013151f369994a83 Mon Sep 17 00:00:00 2001 +From 057e21f3562794b28990ba71720a3a9c70fad92f Mon Sep 17 00:00:00 2001 From: Aikar Date: Wed, 20 Dec 2017 21:42:45 -0500 Subject: [PATCH] EMC EntityAttackedEntityEvent @@ -10,10 +10,10 @@ and that the damage event was not cancelled. 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java -index 39ce40bd..aa1e58fe 100644 +index 1f5d15bb4..a27240181 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java -@@ -994,7 +994,14 @@ public class CraftEventFactory { +@@ -999,7 +999,14 @@ public class CraftEventFactory { callEvent(event); if (!event.isCancelled()) { diff --git a/patches/server/0041-Add-MainThreadHandler-to-allow-custom-MainThreads.patch b/patches/server/0041-Add-MainThreadHandler-to-allow-custom-MainThreads.patch new file mode 100644 index 00000000..b9696549 --- /dev/null +++ b/patches/server/0041-Add-MainThreadHandler-to-allow-custom-MainThreads.patch @@ -0,0 +1,166 @@ +From 290c5a49d9a5f4d38e0cd8e227a042a053fa472e Mon Sep 17 00:00:00 2001 +From: tr7zw +Date: Thu, 5 Mar 2020 20:47:06 +0100 +Subject: [PATCH] Add MainThreadHandler to allow custom "MainThreads" + +--- + .../de/tr7zw/yapfa/MainThreadHandler.java | 24 +++++++++++++++++++ + .../minecraft/server/IAsyncTaskHandler.java | 5 +++- + .../java/net/minecraft/server/MCUtil.java | 6 +++-- + .../net/minecraft/server/MinecraftServer.java | 3 +++ + .../org/bukkit/craftbukkit/CraftServer.java | 4 +++- + src/main/java/org/spigotmc/AsyncCatcher.java | 4 ++-- + 6 files changed, 40 insertions(+), 6 deletions(-) + create mode 100644 src/main/java/de/tr7zw/yapfa/MainThreadHandler.java + +diff --git a/src/main/java/de/tr7zw/yapfa/MainThreadHandler.java b/src/main/java/de/tr7zw/yapfa/MainThreadHandler.java +new file mode 100644 +index 000000000..f66e15e76 +--- /dev/null ++++ b/src/main/java/de/tr7zw/yapfa/MainThreadHandler.java +@@ -0,0 +1,24 @@ ++package de.tr7zw.yapfa; ++ ++import org.bukkit.craftbukkit.util.WeakCollection; ++ ++/** ++ * All Threads that are stored in this Collection are considered "MainThread" ++ * for all intents and purposes. ++ * ++ * @author tr7zw ++ * ++ */ ++public class MainThreadHandler { ++ ++ private static WeakCollection weakMainThreads = new WeakCollection(); ++ ++ public static void registerThread(Thread thread) { ++ weakMainThreads.add(thread); ++ } ++ ++ public static boolean isMainThread(Thread thread) { ++ return weakMainThreads.contains(thread); ++ } ++ ++} +diff --git a/src/main/java/net/minecraft/server/IAsyncTaskHandler.java b/src/main/java/net/minecraft/server/IAsyncTaskHandler.java +index cfe43e882..9009705ee 100644 +--- a/src/main/java/net/minecraft/server/IAsyncTaskHandler.java ++++ b/src/main/java/net/minecraft/server/IAsyncTaskHandler.java +@@ -1,6 +1,9 @@ + package net.minecraft.server; + + import com.google.common.collect.Queues; ++ ++import de.tr7zw.yapfa.MainThreadHandler; ++ + import java.util.Queue; + import java.util.concurrent.CompletableFuture; + import java.util.concurrent.Executor; +@@ -25,7 +28,7 @@ public abstract class IAsyncTaskHandler implements Mailbox T ensureMain(String reason, Supplier run) { +- if (AsyncCatcher.enabled && Thread.currentThread() != MinecraftServer.getServer().serverThread) { ++ if (AsyncCatcher.enabled && !MainThreadHandler.isMainThread(Thread.currentThread())) { // YAPFA + if (reason != null) { + new IllegalStateException("Asynchronous " + reason + "! Blocking thread until it returns ").printStackTrace(); + } +diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java +index 816f4ff14..6ea3833fc 100644 +--- a/src/main/java/net/minecraft/server/MinecraftServer.java ++++ b/src/main/java/net/minecraft/server/MinecraftServer.java +@@ -2,6 +2,8 @@ package net.minecraft.server; + + import com.google.common.base.Splitter; + import co.aikar.timings.Timings; ++import de.tr7zw.yapfa.MainThreadHandler; ++ + import com.destroystokyo.paper.event.server.PaperServerListPingEvent; + import com.google.common.base.Stopwatch; + import com.google.common.collect.Lists; +@@ -132,6 +134,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant { + MinecraftServer.LOGGER.error(throwable); + }); ++ MainThreadHandler.registerThread(thread); // YAPFA + }); + private long nextTick = SystemUtils.getMonotonicMillis(); + private long ab; final long getTickOversleepMaxTime() { return this.ab; } // Paper - OBFHELPER +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +index 9384c9292..19b74f3ca 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +@@ -14,6 +14,8 @@ import com.mojang.brigadier.StringReader; + import com.mojang.brigadier.exceptions.CommandSyntaxException; + import com.mojang.brigadier.tree.CommandNode; + import com.mojang.brigadier.tree.LiteralCommandNode; ++ ++import de.tr7zw.yapfa.MainThreadHandler; + import io.netty.buffer.ByteBuf; + import io.netty.buffer.ByteBufOutputStream; + import io.netty.buffer.Unpooled; +@@ -1684,7 +1686,7 @@ public final class CraftServer implements Server { + + @Override + public boolean isPrimaryThread() { +- return Thread.currentThread().equals(console.serverThread); // Paper - Fix issues with detecting main thread properly ++ return MainThreadHandler.isMainThread(Thread.currentThread()); // YAPFA // Paper - Fix issues with detecting main thread properly + } + + @Override +diff --git a/src/main/java/org/spigotmc/AsyncCatcher.java b/src/main/java/org/spigotmc/AsyncCatcher.java +index 9f7d2ef93..f9fd9f603 100644 +--- a/src/main/java/org/spigotmc/AsyncCatcher.java ++++ b/src/main/java/org/spigotmc/AsyncCatcher.java +@@ -1,6 +1,6 @@ + package org.spigotmc; + +-import net.minecraft.server.MinecraftServer; ++import de.tr7zw.yapfa.MainThreadHandler; + + public class AsyncCatcher + { +@@ -10,7 +10,7 @@ public class AsyncCatcher + + public static void catchOp(String reason) + { +- if ( enabled && Thread.currentThread() != MinecraftServer.getServer().serverThread ) ++ if ( enabled && !MainThreadHandler.isMainThread(Thread.currentThread()) ) // YAPFA + { + throw new IllegalStateException( "Asynchronous " + reason + "!" ); + } +-- +2.25.1.windows.1 +