chore: cleanup annotations in api adventure patch

This commit is contained in:
Riley Park 2023-03-23 09:49:24 -07:00
parent 92f872c146
commit 9087a644a3
67 changed files with 1427 additions and 1365 deletions

View file

@ -13176,16 +13176,6 @@ index 30e330cc3a2f51e4ec9555671e3eeb7bb14bdfa3..214e0657035f82e5266de06e31975d6b
- entityplayer.connection.send(packet);
- });
- }
-
- public CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> getOrScheduleFuture(ChunkStatus targetStatus, ChunkMap chunkStorage) {
- int i = targetStatus.getIndex();
- CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> completablefuture = (CompletableFuture) this.futures.get(i);
-
- if (completablefuture != null) {
- Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure> either = (Either) completablefuture.getNow(ChunkHolder.NOT_DONE_YET);
-
- if (either == null) {
- String s = "value in future for status: " + targetStatus + " was incorrectly set to null at chunk: " + this.pos;
+ // Paper start - per player view distance
+ // there can be potential desync with player's last mapped section and the view distance map, so use the
+ // view distance map here.
@ -13195,6 +13185,16 @@ index 30e330cc3a2f51e4ec9555671e3eeb7bb14bdfa3..214e0657035f82e5266de06e31975d6b
+ return;
+ }
- public CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> getOrScheduleFuture(ChunkStatus targetStatus, ChunkMap chunkStorage) {
- int i = targetStatus.getIndex();
- CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> completablefuture = (CompletableFuture) this.futures.get(i);
-
- if (completablefuture != null) {
- Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure> either = (Either) completablefuture.getNow(ChunkHolder.NOT_DONE_YET);
-
- if (either == null) {
- String s = "value in future for status: " + targetStatus + " was incorrectly set to null at chunk: " + this.pos;
-
- throw chunkStorage.debugFuturesAndCreateReportedException(new IllegalStateException("null value previously set for chunk status"), s);
+ Object[] backingSet = players.getBackingSet();
+ for (int i = 0, len = backingSet.length; i < len; ++i) {
@ -13258,8 +13258,9 @@ index 30e330cc3a2f51e4ec9555671e3eeb7bb14bdfa3..214e0657035f82e5266de06e31975d6b
public final int getTicketLevel() { // Paper - final for inline
- return this.ticketLevel;
- }
-
+ return this.newChunkHolder.getTicketLevel(); // Paper - rewrite chunk system
}
- public int getQueueLevel() {
- return this.queueLevel;
- }
@ -13285,9 +13286,8 @@ index 30e330cc3a2f51e4ec9555671e3eeb7bb14bdfa3..214e0657035f82e5266de06e31975d6b
- completablefuture1.complete(null); // CraftBukkit - decompile error
- });
- });
+ return this.newChunkHolder.getTicketLevel(); // Paper - rewrite chunk system
}
- }
-
- private void demoteFullChunk(ChunkMap playerchunkmap, ChunkHolder.FullChunkStatus playerchunk_state) {
- this.pendingFullStateConfirmation.cancel(false);
- playerchunkmap.onFullChunkStatusChange(this.pos, playerchunk_state);
@ -13823,15 +13823,16 @@ index 578849f64de38dc75cdefeb243422c4c89a5c69c..9246ce9f654ad4db6155b026778a83d4
- } finally {
- super.close();
- }
-
+ throw new UnsupportedOperationException("Use ServerChunkCache#close"); // Paper - rewrite chunk system
+ }
}
+ // Paper start - rewrite chunk system
+ protected void saveIncrementally() {
+ this.level.chunkTaskScheduler.chunkHolderManager.autoSave(); // Paper - rewrite chunk system
}
+ }
+ // Paper end - - rewrite chunk system
+
protected void saveAllChunks(boolean flush) {
- if (flush) {
- List<ChunkHolder> list = (List) io.papermc.paper.chunk.system.ChunkSystem.getVisibleChunkHolders(this.level).stream().filter(ChunkHolder::wasAccessibleSinceLastSave).peek(ChunkHolder::refreshAccessibility).collect(Collectors.toList()); // Paper
@ -14491,21 +14492,25 @@ index 578849f64de38dc75cdefeb243422c4c89a5c69c..9246ce9f654ad4db6155b026778a83d4
- Set<ServerPlayer> set = this.playerMap.getPlayers(chunkPos.toLong());
- Builder<ServerPlayer> builder = ImmutableList.builder();
- Iterator iterator = set.iterator();
-
- while (iterator.hasNext()) {
- ServerPlayer entityplayer = (ServerPlayer) iterator.next();
- SectionPos sectionposition = entityplayer.getLastSectionPos();
-
- if (onlyOnWatchDistanceEdge && ChunkMap.isChunkOnRangeBorder(chunkPos.x, chunkPos.z, sectionposition.x(), sectionposition.z(), this.viewDistance) || !onlyOnWatchDistanceEdge && ChunkMap.isChunkInRange(chunkPos.x, chunkPos.z, sectionposition.x(), sectionposition.z(), this.viewDistance)) {
- builder.add(entityplayer);
- }
+ // Paper start - per player view distance
+ // there can be potential desync with player's last mapped section and the view distance map, so use the
+ // view distance map here.
+ com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> players = this.playerChunkManager.broadcastMap.getObjectsInRange(chunkPos);
+ if (players == null) {
+ return java.util.Collections.emptyList();
+ }
}
- while (iterator.hasNext()) {
- ServerPlayer entityplayer = (ServerPlayer) iterator.next();
- SectionPos sectionposition = entityplayer.getLastSectionPos();
- return builder.build();
+ List<ServerPlayer> ret = new java.util.ArrayList<>(players.size());
- if (onlyOnWatchDistanceEdge && ChunkMap.isChunkOnRangeBorder(chunkPos.x, chunkPos.z, sectionposition.x(), sectionposition.z(), this.viewDistance) || !onlyOnWatchDistanceEdge && ChunkMap.isChunkInRange(chunkPos.x, chunkPos.z, sectionposition.x(), sectionposition.z(), this.viewDistance)) {
- builder.add(entityplayer);
+
+ Object[] backingSet = players.getBackingSet();
+ for (int i = 0, len = backingSet.length; i < len; ++i) {
+ if (!(backingSet[i] instanceof ServerPlayer player)) {
@ -14513,11 +14518,10 @@ index 578849f64de38dc75cdefeb243422c4c89a5c69c..9246ce9f654ad4db6155b026778a83d4
+ }
+ if (!this.playerChunkManager.isChunkSent(player, chunkPos.x, chunkPos.z, onlyOnWatchDistanceEdge)) {
+ continue;
}
+ }
+ ret.add(player);
}
- return builder.build();
+ }
+
+ return ret;
+ // Paper end - per player view distance
}
@ -14883,7 +14887,8 @@ index d38ad1b1eee92a6dbd2b79b4fcdb8959cdb4007d..ffa1e457decf8502c3283352bf5be94d
- private void dumpTickets(String path) {
- try {
- FileOutputStream fileoutputstream = new FileOutputStream(new File(path));
-
+ // Paper - rewrite chunk system
- try {
- ObjectIterator objectiterator = this.tickets.long2ObjectEntrySet().iterator();
-
@ -14904,8 +14909,7 @@ index d38ad1b1eee92a6dbd2b79b4fcdb8959cdb4007d..ffa1e457decf8502c3283352bf5be94d
- } catch (Throwable throwable1) {
- throwable.addSuppressed(throwable1);
- }
+ // Paper - rewrite chunk system
-
- throw throwable;
- }
-
@ -15125,29 +15129,23 @@ index 28c8a3ba1caddf0ea334a6ef43cae25f982743e4..80d108ae7faf3fdcb024931e93032215
- ChunkHolder.FullChunkStatus oldChunkState = ChunkHolder.getFullChunkStatus(playerchunk.oldTicketLevel);
- ChunkHolder.FullChunkStatus currentChunkState = ChunkHolder.getFullChunkStatus(playerchunk.getTicketLevel());
- currentlyUnloading = (oldChunkState.isOrAfter(ChunkHolder.FullChunkStatus.BORDER) && !currentChunkState.isOrAfter(ChunkHolder.FullChunkStatus.BORDER));
- }
+ boolean needsFullScheduling = leastStatus == ChunkStatus.FULL && (chunkHolder == null || !chunkHolder.getChunkStatus().isOrAfter(ChunkHolder.FullChunkStatus.BORDER));
+
+ if ((chunkHolder == null || chunkHolder.getTicketLevel() > minLevel || needsFullScheduling) && !create) {
+ return ChunkHolder.UNLOADED_CHUNK_FUTURE;
}
- if (create && !currentlyUnloading) {
- // CraftBukkit end
- this.distanceManager.addTicket(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair);
- if (this.chunkAbsent(playerchunk, l)) {
- ProfilerFiller gameprofilerfiller = this.level.getProfiler();
-
- gameprofilerfiller.push("chunkLoad");
- this.runDistanceManagerUpdates();
- playerchunk = this.getVisibleChunkIfPresent(k);
- gameprofilerfiller.pop();
- if (this.chunkAbsent(playerchunk, l)) {
- throw (IllegalStateException) Util.pauseInIde(new IllegalStateException("No chunk holder after ticket has been added"));
- }
- }
+ boolean needsFullScheduling = leastStatus == ChunkStatus.FULL && (chunkHolder == null || !chunkHolder.getChunkStatus().isOrAfter(ChunkHolder.FullChunkStatus.BORDER));
+
+ if ((chunkHolder == null || chunkHolder.getTicketLevel() > minLevel || needsFullScheduling) && !create) {
+ return ChunkHolder.UNLOADED_CHUNK_FUTURE;
}
- return this.chunkAbsent(playerchunk, l) ? ChunkHolder.UNLOADED_CHUNK_FUTURE : playerchunk.getOrScheduleFuture(leastStatus, this.chunkMap);
- }
+ io.papermc.paper.chunk.system.scheduling.NewChunkHolder.ChunkCompletion chunkCompletion = chunkHolder == null ? null : chunkHolder.getLastChunkCompletion();
+ if (needsFullScheduling || chunkCompletion == null || !chunkCompletion.genStatus().isOrAfter(leastStatus)) {
+ // schedule
@ -15157,11 +15155,10 @@ index 28c8a3ba1caddf0ea334a6ef43cae25f982743e4..80d108ae7faf3fdcb024931e93032215
+ ret.complete(Either.right(ChunkHolder.ChunkLoadingFailure.UNLOADED));
+ } else {
+ ret.complete(Either.left(chunk));
+ }
}
- }
+ };
- private boolean chunkAbsent(@Nullable ChunkHolder holder, int maxLevel) {
- return holder == null || holder.oldTicketLevel > maxLevel; // CraftBukkit using oldTicketLevel for isLoaded checks
+
+ this.level.chunkTaskScheduler.scheduleChunkLoad(
+ chunkX, chunkZ, leastStatus, true,
+ isUrgent ? ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor.Priority.BLOCKING : ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor.Priority.NORMAL,
@ -15172,12 +15169,17 @@ index 28c8a3ba1caddf0ea334a6ef43cae25f982743e4..80d108ae7faf3fdcb024931e93032215
+ } else {
+ // can return now
+ return CompletableFuture.completedFuture(Either.left(chunkCompletion.chunk()));
+ }
}
-
- return this.chunkAbsent(playerchunk, l) ? ChunkHolder.UNLOADED_CHUNK_FUTURE : playerchunk.getOrScheduleFuture(leastStatus, this.chunkMap);
+ // Paper end - rewrite chunk system
}
- private boolean chunkAbsent(@Nullable ChunkHolder holder, int maxLevel) {
- return holder == null || holder.oldTicketLevel > maxLevel; // CraftBukkit using oldTicketLevel for isLoaded checks
- }
+ // Paper - rewrite chunk system
+
@Override
public boolean hasChunk(int x, int z) {
- ChunkHolder playerchunk = this.getVisibleChunkIfPresent((new ChunkPos(x, z)).toLong());
@ -16532,7 +16534,21 @@ index 69f55f7207b8c03ca886947c57c9d13a8e8eb576..0517c0932b79db1a0e27673654ae8bb5
- if (result.size() >= limit) {
- return AbortableIterationConsumer.Continuation.ABORT;
- }
- }
+ // Paper start - optimise this call
+ //TODO use limit
+ if (filter instanceof net.minecraft.world.entity.EntityType entityTypeTest) {
+ ((ServerLevel) this).getEntityLookup().getEntities(entityTypeTest, box, result, predicate);
+ } else {
+ Predicate<? super T> test = (obj) -> {
+ return filter.tryCast(obj) != null;
+ };
+ predicate = predicate == null ? test : test.and((Predicate) predicate);
+ Class base;
+ if (filter == null || (base = filter.getBaseClass()) == null || base == Entity.class) {
+ ((ServerLevel) this).getEntityLookup().getEntities((Entity) null, box, (List) result, (Predicate)predicate);
+ } else {
+ ((ServerLevel) this).getEntityLookup().getEntities(base, null, box, (List) result, (Predicate)predicate); // Paper - optimise this call
}
-
- if (entity instanceof EnderDragon) {
- EnderDragon entityenderdragon = (EnderDragon) entity;
@ -16550,21 +16566,7 @@ index 69f55f7207b8c03ca886947c57c9d13a8e8eb576..0517c0932b79db1a0e27673654ae8bb5
- }
- }
- }
+ // Paper start - optimise this call
+ //TODO use limit
+ if (filter instanceof net.minecraft.world.entity.EntityType entityTypeTest) {
+ ((ServerLevel) this).getEntityLookup().getEntities(entityTypeTest, box, result, predicate);
+ } else {
+ Predicate<? super T> test = (obj) -> {
+ return filter.tryCast(obj) != null;
+ };
+ predicate = predicate == null ? test : test.and((Predicate) predicate);
+ Class base;
+ if (filter == null || (base = filter.getBaseClass()) == null || base == Entity.class) {
+ ((ServerLevel) this).getEntityLookup().getEntities((Entity) null, box, (List) result, (Predicate)predicate);
+ } else {
+ ((ServerLevel) this).getEntityLookup().getEntities(base, null, box, (List) result, (Predicate)predicate); // Paper - optimise this call
}
- }
-
- return AbortableIterationConsumer.Continuation.CONTINUE;
- });
@ -16966,15 +16968,15 @@ index bca8084f7e76d036378705aa802217cc1bfdbc7d..f9dd2d9312297a727344d43150c5cab7
} else {
ProtoChunk protochunk1 = (ProtoChunk) object1;
@@ -362,9 +388,41 @@ public class ChunkSerializer {
@@ -362,10 +388,42 @@ public class ChunkSerializer {
protochunk1.setCarvingMask(worldgenstage_features, new CarvingMask(nbttagcompound4.getLongArray(s1), ((ChunkAccess) object1).getMinBuildHeight()));
}
- return protochunk1;
+ return new InProgressChunkHolder(protochunk1, tasksToExecuteOnMain); // Paper - Async chunk loading
+ }
+ }
+
}
}
+ // Paper start - async chunk save for unload
+ public record AsyncSaveData(
+ Tag blockTickList, // non-null if we had to go to the server's tick list
@ -16996,7 +16998,7 @@ index bca8084f7e76d036378705aa802217cc1bfdbc7d..f9dd2d9312297a727344d43150c5cab7
+ if (blockEntityNbt != null) {
+ blockEntitiesSerialized.add(blockEntityNbt);
+ }
}
+ }
+
+ return new AsyncSaveData(
+ tickLists.get(BLOCK_TICKS_TAG),
@ -17004,11 +17006,12 @@ index bca8084f7e76d036378705aa802217cc1bfdbc7d..f9dd2d9312297a727344d43150c5cab7
+ blockEntitiesSerialized,
+ world.getGameTime()
+ );
}
+ }
+ // Paper end
+
private static void logErrors(ChunkPos chunkPos, int y, String message) {
ChunkSerializer.LOGGER.error("Recoverable errors when loading section [" + chunkPos.x + ", " + y + ", " + chunkPos.z + "]: " + message);
}
@@ -381,6 +439,11 @@ public class ChunkSerializer {
// CraftBukkit end
@ -17148,11 +17151,11 @@ index ba267f3082607669282a61f013991e1c391a3f09..0747d2d411a85a26bfea08cc1dd29df6
+ } catch (Throwable thr) {
+ return CompletableFuture.failedFuture(thr);
+ }
+ }
}
+ @Nullable
+ public CompoundTag readSync(ChunkPos chunkPos) throws IOException {
+ return this.regionFileCache.read(chunkPos);
}
+ }
+ // Paper end - async chunk io
- public void write(ChunkPos chunkPos, CompoundTag nbt) {
@ -17239,17 +17242,17 @@ index 98b3909b536f11eda9c481ffd74066ad0cdb0ebc..0ec0be22f7292d57c40da6f1f4575bde
- }
- }, this.entityDeserializerQueue::tell);
+ throw new UnsupportedOperationException(); // Paper - rewrite chunk system - copy out read logic into readEntities
+ }
+
}
- private static ChunkPos readChunkPos(CompoundTag chunkNbt) {
+ // Paper start - rewrite chunk system
+ public static List<Entity> readEntities(ServerLevel level, CompoundTag compoundTag) {
+ ListTag listTag = compoundTag.getList("Entities", 10);
+ List<Entity> list = EntityType.loadEntitiesRecursive(listTag, level).collect(ImmutableList.toImmutableList());
+ return list;
}
+ }
+ // Paper end - rewrite chunk system
- private static ChunkPos readChunkPos(CompoundTag chunkNbt) {
+
+ public static ChunkPos readChunkPos(CompoundTag chunkNbt) { // Paper - public
int[] is = chunkNbt.getIntArray("Position");
return new ChunkPos(is[0], is[1]);
@ -17291,6 +17294,10 @@ index 98b3909b536f11eda9c481ffd74066ad0cdb0ebc..0ec0be22f7292d57c40da6f1f4575bde
}
}
- @Override
- public void flush(boolean sync) {
- this.worker.synchronize(sync).join();
- this.entityDeserializerQueue.runAll();
+ // Paper start - rewrite chunk system
+ public static void copyEntities(final CompoundTag from, final CompoundTag into) {
+ if (from == null) {
@ -17304,8 +17311,9 @@ index 98b3909b536f11eda9c481ffd74066ad0cdb0ebc..0ec0be22f7292d57c40da6f1f4575bde
+ final ListTag entitiesInto = into.getList("Entities", net.minecraft.nbt.Tag.TAG_COMPOUND);
+ into.put("Entities", entitiesInto); // this is in case into doesn't have any entities
+ entitiesInto.addAll(0, entitiesFrom.copy()); // need to copy, this is coming from the save thread
+ }
+
}
- private CompoundTag upgradeChunkTag(CompoundTag chunkNbt) {
+ public static CompoundTag saveEntityChunk(List<Entity> entities, ChunkPos chunkPos, ServerLevel level) {
+ return saveEntityChunk0(entities, chunkPos, level, false);
+ }
@ -17331,14 +17339,11 @@ index 98b3909b536f11eda9c481ffd74066ad0cdb0ebc..0ec0be22f7292d57c40da6f1f4575bde
+ }
+ // Paper end - rewrite chunk system
+
@Override
public void flush(boolean sync) {
- this.worker.synchronize(sync).join();
- this.entityDeserializerQueue.runAll();
+ @Override
+ public void flush(boolean sync) {
+ throw new UnsupportedOperationException(); // Paper - rewrite chunk system
}
- private CompoundTag upgradeChunkTag(CompoundTag chunkNbt) {
+ }
+
+ public static CompoundTag upgradeChunkTag(CompoundTag chunkNbt) { // Paper - public and static
int i = NbtUtils.getDataVersion(chunkNbt, -1);
return ca.spottedleaf.dataconverter.minecraft.MCDataConverter.convertTag(ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.ENTITY_CHUNK, chunkNbt, i, net.minecraft.SharedConstants.getCurrentVersion().getDataVersion().getVersion()); // Paper - route to new converter system
@ -17996,7 +18001,7 @@ index 253f965e52cd488af88d55cdd09f1bad0ddbeb56..30137f60a3796cf845e8fd7bd3c291be
// Spigot start
private final org.bukkit.World.Spigot spigot = new org.bukkit.World.Spigot()
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 12e7a0a24fe2aa6e7af97ad7d50d81e5c7b26663..d60dc99e2b926847f42a32e9d093a31556d179d8 100644
index 7c9f1b998ea5447d6ff29cdbb9e3cee0ba1c7c99..7b57298ee6c9422fa10dde9cf9441ea10b3443e4 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -177,6 +177,81 @@ public class CraftPlayer extends CraftHumanEntity implements Player {