2021-08-26 04:16:27 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Spottedleaf <spottedleaf@spottedleaf.dev>
|
|
|
|
Date: Thu, 18 Jun 2020 18:23:20 -0700
|
|
|
|
Subject: [PATCH] Prevent unload() calls removing tickets for sync loads
|
|
|
|
|
|
|
|
|
2022-03-01 03:33:20 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/DistanceManager.java b/src/main/java/net/minecraft/server/level/DistanceManager.java
|
2022-06-09 10:51:45 +02:00
|
|
|
index b2df5e18ce5260a9781052db7afb0b9786fb887c..537d34a0325a985948c744929b90144a66a35ee3 100644
|
2022-03-01 03:33:20 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/DistanceManager.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/DistanceManager.java
|
|
|
|
@@ -545,7 +545,7 @@ public abstract class DistanceManager {
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeTicketsOnClosing() {
|
|
|
|
- ImmutableSet<TicketType<?>> immutableset = ImmutableSet.of(TicketType.UNKNOWN, TicketType.POST_TELEPORT, TicketType.LIGHT, TicketType.FUTURE_AWAIT, TicketType.ASYNC_LOAD); // Paper - add additional tickets to preserve
|
|
|
|
+ ImmutableSet<TicketType<?>> immutableset = ImmutableSet.of(TicketType.UNKNOWN, TicketType.POST_TELEPORT, TicketType.LIGHT, TicketType.FUTURE_AWAIT, TicketType.ASYNC_LOAD, TicketType.REQUIRED_LOAD); // Paper - add additional tickets to preserve
|
|
|
|
ObjectIterator objectiterator = this.tickets.long2ObjectEntrySet().fastIterator();
|
|
|
|
|
|
|
|
while (objectiterator.hasNext()) {
|
2021-08-26 04:16:27 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
2022-06-09 10:51:45 +02:00
|
|
|
index 591c9577a66f5663f7728b70f44e33ca029af085..ce88da358c8a89564a911e6c818e906e845006ff 100644
|
2021-08-26 04:16:27 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
2022-06-08 12:20:57 +02:00
|
|
|
@@ -714,6 +714,8 @@ public class ServerChunkCache extends ChunkSource {
|
2021-08-26 04:16:27 +02:00
|
|
|
return completablefuture;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ private long syncLoadCounter; // Paper - prevent plugin unloads from removing our ticket
|
|
|
|
+
|
2021-11-17 06:00:14 +01:00
|
|
|
private CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> getChunkFutureMainThread(int chunkX, int chunkZ, ChunkStatus leastStatus, boolean create) {
|
2021-08-26 04:16:27 +02:00
|
|
|
// Paper start - add isUrgent - old sig left in place for dirty nms plugins
|
2021-11-17 06:00:14 +01:00
|
|
|
return getChunkFutureMainThread(chunkX, chunkZ, leastStatus, create, false);
|
2022-06-08 12:20:57 +02:00
|
|
|
@@ -732,9 +734,12 @@ public class ServerChunkCache extends ChunkSource {
|
2021-08-26 04:16:27 +02:00
|
|
|
ChunkHolder.FullChunkStatus currentChunkState = ChunkHolder.getFullChunkStatus(playerchunk.getTicketLevel());
|
|
|
|
currentlyUnloading = (oldChunkState.isOrAfter(ChunkHolder.FullChunkStatus.BORDER) && !currentChunkState.isOrAfter(ChunkHolder.FullChunkStatus.BORDER));
|
|
|
|
}
|
|
|
|
+ final Long identifier; // Paper - prevent plugin unloads from removing our ticket
|
2021-11-17 06:00:14 +01:00
|
|
|
if (create && !currentlyUnloading) {
|
2021-08-26 04:16:27 +02:00
|
|
|
// CraftBukkit end
|
|
|
|
this.distanceManager.addTicket(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair);
|
|
|
|
+ identifier = Long.valueOf(this.syncLoadCounter++); // Paper - prevent plugin unloads from removing our ticket
|
2022-02-28 22:43:31 +01:00
|
|
|
+ this.distanceManager.addTicket(TicketType.REQUIRED_LOAD, chunkcoordintpair, l, identifier); // Paper - prevent plugin unloads from removing our ticket
|
2021-08-26 04:16:27 +02:00
|
|
|
if (isUrgent) this.distanceManager.markUrgent(chunkcoordintpair); // Paper - Chunk priority
|
|
|
|
if (this.chunkAbsent(playerchunk, l)) {
|
|
|
|
ProfilerFiller gameprofilerfiller = this.level.getProfiler();
|
2022-06-08 12:20:57 +02:00
|
|
|
@@ -745,13 +750,21 @@ public class ServerChunkCache extends ChunkSource {
|
2021-08-26 04:16:27 +02:00
|
|
|
playerchunk = this.getVisibleChunkIfPresent(k);
|
|
|
|
gameprofilerfiller.pop();
|
|
|
|
if (this.chunkAbsent(playerchunk, l)) {
|
2022-02-28 22:43:31 +01:00
|
|
|
+ this.distanceManager.removeTicket(TicketType.REQUIRED_LOAD, chunkcoordintpair, l, identifier); // Paper
|
2021-11-30 06:25:11 +01:00
|
|
|
throw (IllegalStateException) Util.pauseInIde(new IllegalStateException("No chunk holder after ticket has been added"));
|
2021-08-26 04:16:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
- }
|
2021-11-17 06:00:14 +01:00
|
|
|
|
2021-08-26 04:16:27 +02:00
|
|
|
+ } else { identifier = null; } // Paper - prevent plugin unloads from removing our ticket
|
|
|
|
// Paper start - Chunk priority
|
2021-11-17 06:00:14 +01:00
|
|
|
CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> future = this.chunkAbsent(playerchunk, l) ? ChunkHolder.UNLOADED_CHUNK_FUTURE : playerchunk.getOrScheduleFuture(leastStatus, this.chunkMap);
|
2021-08-26 04:16:27 +02:00
|
|
|
+ // Paper start - prevent plugin unloads from removing our ticket
|
2021-11-17 06:00:14 +01:00
|
|
|
+ if (create && !currentlyUnloading) {
|
2021-08-26 04:16:27 +02:00
|
|
|
+ future.thenAcceptAsync((either) -> {
|
2022-02-28 22:43:31 +01:00
|
|
|
+ ServerChunkCache.this.distanceManager.removeTicket(TicketType.REQUIRED_LOAD, chunkcoordintpair, l, identifier);
|
2021-08-26 04:16:27 +02:00
|
|
|
+ }, ServerChunkCache.this.mainThreadProcessor);
|
|
|
|
+ }
|
|
|
|
+ // Paper end - prevent plugin unloads from removing our ticket
|
|
|
|
if (isUrgent) {
|
|
|
|
future.thenAccept(either -> this.distanceManager.clearUrgent(chunkcoordintpair));
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/TicketType.java b/src/main/java/net/minecraft/server/level/TicketType.java
|
|
|
|
index 3c1698ba0d3bc412ab957777d9b5211dbc555208..41ddcf6775f99c56cf4b13b284420061e5dd6bdc 100644
|
|
|
|
--- a/src/main/java/net/minecraft/server/level/TicketType.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/TicketType.java
|
|
|
|
@@ -31,6 +31,7 @@ public class TicketType<T> {
|
|
|
|
public static final TicketType<Unit> PLUGIN = TicketType.create("plugin", (a, b) -> 0); // CraftBukkit
|
|
|
|
public static final TicketType<org.bukkit.plugin.Plugin> PLUGIN_TICKET = TicketType.create("plugin_ticket", (plugin1, plugin2) -> plugin1.getClass().getName().compareTo(plugin2.getClass().getName())); // CraftBukkit
|
|
|
|
public static final TicketType<Long> DELAY_UNLOAD = create("delay_unload", Long::compareTo, 300); // Paper
|
|
|
|
+ public static final TicketType<Long> REQUIRED_LOAD = create("required_load", Long::compareTo); // Paper - make sure getChunkAt does not fail
|
|
|
|
|
|
|
|
public static <T> TicketType<T> create(String name, Comparator<T> argumentComparator) {
|
|
|
|
return new TicketType<>(name, argumentComparator, 0L);
|