aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0754-Do-not-allow-ticket-level-changes-when-updating-chun.patch
blob: b270fb651be0555815c7968777ffbec8c43ae06b (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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Sun, 20 Jun 2021 00:08:13 -0700
Subject: [PATCH] Do not allow ticket level changes when updating chunk ticking
 state

This WILL cause state corruption if it happens. So, don't
allow it.

diff --git a/src/main/java/net/minecraft/server/level/ChunkHolder.java b/src/main/java/net/minecraft/server/level/ChunkHolder.java
index d4ea81824acdc1220616b24ea0f465db97f4a343..b0a6eb7846580489e0476e69565676e77fd224cd 100644
--- a/src/main/java/net/minecraft/server/level/ChunkHolder.java
+++ b/src/main/java/net/minecraft/server/level/ChunkHolder.java
@@ -599,7 +599,13 @@ public class ChunkHolder {
         CompletableFuture<Void> completablefuture1 = new CompletableFuture();
 
         completablefuture1.thenRunAsync(() -> {
+            // Paper start - do not allow ticket level changes
+            boolean unloadingBefore = this.chunkMap.unloadingPlayerChunk;
+            this.chunkMap.unloadingPlayerChunk = true;
+            try {
+            // Paper end  - do not allow ticket level changes
             playerchunkmap.onFullChunkStatusChange(this.pos, playerchunk_state);
+            } finally { this.chunkMap.unloadingPlayerChunk = unloadingBefore; } // Paper - do not allow ticket level changes
         }, executor);
         this.pendingFullStateConfirmation = completablefuture1;
         completablefuture.thenAccept((either) -> {
@@ -616,7 +622,12 @@ public class ChunkHolder {
 
     private void demoteFullChunk(ChunkMap playerchunkmap, ChunkHolder.FullChunkStatus playerchunk_state) {
         this.pendingFullStateConfirmation.cancel(false);
+        // Paper start - do not allow ticket level changes
+        boolean unloadingBefore = this.chunkMap.unloadingPlayerChunk;
+        this.chunkMap.unloadingPlayerChunk = true;
+        try { // Paper end  - do not allow ticket level changes
         playerchunkmap.onFullChunkStatusChange(this.pos, playerchunk_state);
+        } finally { this.chunkMap.unloadingPlayerChunk = unloadingBefore; } // Paper - do not allow ticket level changes
     }
 
     protected long updateCount; // Paper - correctly handle recursion