mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-12 04:06:52 +01:00
8c5b837e05
Firstly, the old methods all routed to the CompletableFuture method. However, the CF method could not guarantee that if the caller was off-main that the future would be "completed" on-main. Since the callback methods used the CF one, this meant that the callback methods did not guarantee that the callbacks were to be called on the main thread. Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb) so that the methods with the callback are guaranteed to invoke the callback on the main thread. The CF behavior remains unchanged; it may still appear to complete on main if invoked off-main. Secondly, remove the scheduleOnMain invocation in the async chunk completion. This unnecessarily delays the callback by 1 tick. Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which will load chunks within an area. This method is provided as a helper as keeping all chunks loaded within an area can be complicated to implement for plugins (due to the lacking ticket API), and is already implemented internally anyways. Fourthly, remove the ticket addition that occured with getChunkAt and getChunkAtAsync. The ticket addition may delay the unloading of the chunk unnecessarily. It also fixes a very rare timing bug where the future/callback would be completed after the chunk unloads.
47 lines
3.1 KiB
Diff
47 lines
3.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
|
|
Date: Sun, 27 Oct 2024 14:18:28 -0700
|
|
Subject: [PATCH] Avoid issues with certain tasks not processing during sleep
|
|
|
|
Execute processQueue tasks during sleep: needed for console tab completions, pre join event, etc.
|
|
|
|
Upstream has set precedent that the bukkit scheduler will still tick during sleep, which avoids some problems
|
|
with plugins not accounting for the new sleep feature, but can still lead to others. Because of this we have disabled
|
|
sleep by default, which avoids the problem and makes it more obvious to check if this is the cause of issues when
|
|
enabled. We also unload chunks during sleep to prevent memory leaks caused by plugin chunk loads.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index e636a96ea6220fda671a31d3d9cdea468a558768..64b56abf8900d0424100da460fc68ac964394793 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -1638,6 +1638,16 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
}
|
|
|
|
this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
|
|
+ // Paper start - avoid issues with certain tasks not processing during sleep
|
|
+ Runnable task;
|
|
+ while ((task = this.processQueue.poll()) != null) {
|
|
+ task.run();
|
|
+ }
|
|
+ for (final ServerLevel level : this.levels.values()) {
|
|
+ // process unloads
|
|
+ level.getChunkSource().tick(() -> true, false);
|
|
+ }
|
|
+ // Paper end - avoid issues with certain tasks not processing during sleep
|
|
this.server.spark.executeMainThreadTasks(); // Paper - spark
|
|
this.tickConnection();
|
|
this.server.spark.tickEnd(((double)(System.nanoTime() - lastTick) / 1000000D)); // Paper - spark
|
|
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServerProperties.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServerProperties.java
|
|
index a2633780619d73c29a23cb8b6a208ca9ba549fb0..c3ec370b83b895be0f03662e3884fa4a2442a2a6 100644
|
|
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServerProperties.java
|
|
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServerProperties.java
|
|
@@ -160,7 +160,7 @@ public class DedicatedServerProperties extends Settings<DedicatedServerPropertie
|
|
this.whiteList = this.getMutable("white-list", false);
|
|
this.enforceSecureProfile = this.get("enforce-secure-profile", true);
|
|
this.logIPs = this.get("log-ips", true);
|
|
- this.pauseWhenEmptySeconds = this.get("pause-when-empty-seconds", 60);
|
|
+ this.pauseWhenEmptySeconds = this.get("pause-when-empty-seconds", -1); // Paper - disable tick sleeping by default
|
|
this.acceptsTransfers = this.get("accepts-transfers", false);
|
|
String s = this.get("level-seed", "");
|
|
boolean flag = this.get("generate-structures", true);
|