aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-spigotflower-stripped/net/minecraft/network/protocol/PacketUtils.java.patch
blob: f2c12852ca3690e8589a845d573dee70205dd6ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
--- a/net/minecraft/network/protocol/PacketUtils.java
+++ b/net/minecraft/network/protocol/PacketUtils.java
@@ -4,8 +4,14 @@
 import net.minecraft.CrashReport;
 import net.minecraft.ReportedException;
 import net.minecraft.network.PacketListener;
-import net.minecraft.server.RunningOnDifferentThreadException;
+import net.minecraft.server.CancelledPacketHandleException;
+import org.slf4j.Logger;
+
+// CraftBukkit start
+import net.minecraft.server.MinecraftServer;
 import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.network.ServerCommonPacketListenerImpl;
+// CraftBukkit end
 import net.minecraft.util.thread.BlockableEventLoop;
 import org.slf4j.Logger;
 
@@ -19,10 +24,11 @@
         ensureRunningOnSameThread(packet, t0, (BlockableEventLoop) serverlevel.getServer());
     }
 
-    public static <T extends PacketListener> void ensureRunningOnSameThread(Packet<T> packet, T t0, BlockableEventLoop<?> blockableeventloop) throws RunningOnDifferentThreadException {
-        if (!blockableeventloop.isSameThread()) {
-            blockableeventloop.executeIfPossible(() -> {
-                if (t0.shouldHandleMessage(packet)) {
+    public static <T extends PacketListener> void ensureRunningOnSameThread(Packet<T> packet, T processor, BlockableEventLoop<?> executor) throws CancelledPacketHandleException {
+        if (!executor.isSameThread()) {
+            executor.executeIfPossible(() -> {
+                if (MinecraftServer.getServer().hasStopped() || (processor instanceof ServerCommonPacketListenerImpl && ((ServerCommonPacketListenerImpl) processor).processedDisconnect)) return; // CraftBukkit, MC-142590
+                if (processor.shouldHandleMessage(packet)) {
                     try {
                         packet.handle(t0);
                     } catch (Exception exception) {
@@ -59,7 +65,11 @@
                 }
 
             });
-            throw RunningOnDifferentThreadException.RUNNING_ON_DIFFERENT_THREAD;
+            throw CancelledPacketHandleException.RUNNING_ON_DIFFERENT_THREAD;
+            // CraftBukkit start - SPIGOT-5477, MC-142590
+        } else if (MinecraftServer.getServer().hasStopped() || (processor instanceof ServerCommonPacketListenerImpl && ((ServerCommonPacketListenerImpl) processor).processedDisconnect)) {
+            throw CancelledPacketHandleException.RUNNING_ON_DIFFERENT_THREAD;
+            // CraftBukkit end
         }
     }
 }