2021-03-15 23:00:00 +01:00
--- a/net/minecraft/server/level/PlayerChunkMap.java
+++ b/net/minecraft/server/level/PlayerChunkMap.java
2021-06-11 07:00:00 +02:00
@@ -91,6 +91,8 @@
2019-04-23 04:00:00 +02:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2021-03-08 22:47:33 +01:00
+import org.bukkit.entity.Player; // CraftBukkit
+
2021-06-11 07:00:00 +02:00
public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.e {
2019-04-23 04:00:00 +02:00
2021-06-11 07:00:00 +02:00
private static final byte CHUNK_TYPE_REPLACEABLE = -1;
@@ -129,6 +131,27 @@
private final Queue<Runnable> unloadQueue;
int viewDistance;
2019-07-13 20:19:44 +02:00
+ // CraftBukkit start - recursion-safe executor for Chunk loadCallback() and unloadCallback()
+ public final CallbackExecutor callbackExecutor = new CallbackExecutor();
+ public static final class CallbackExecutor implements java.util.concurrent.Executor, Runnable {
+
2021-06-11 07:00:00 +02:00
+ private final java.util.Queue<Runnable> queue = new java.util.ArrayDeque<>();
2019-07-13 20:19:44 +02:00
+
+ @Override
+ public void execute(Runnable runnable) {
2021-06-11 07:00:00 +02:00
+ queue.add(runnable);
2019-07-13 20:19:44 +02:00
+ }
+
+ @Override
+ public void run() {
2021-06-11 07:00:00 +02:00
+ Runnable task;
+ while ((task = queue.poll()) != null) {
2019-07-13 20:19:44 +02:00
+ task.run();
+ }
+ }
+ };
+ // CraftBukkit end
+
2021-06-11 07:00:00 +02:00
public PlayerChunkMap(WorldServer worldserver, Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, DefinedStructureManager definedstructuremanager, Executor executor, IAsyncTaskHandler<Runnable> iasynctaskhandler, ILightAccess ilightaccess, ChunkGenerator chunkgenerator, WorldLoadListener worldloadlistener, ChunkStatusUpdateListener chunkstatusupdatelistener, Supplier<WorldPersistentData> supplier, int i, boolean flag) {
2020-06-25 02:00:00 +02:00
super(new File(convertable_conversionsession.a(worldserver.getDimensionKey()), "region"), datafixer, flag);
2021-06-11 07:00:00 +02:00
this.visibleChunkMap = this.updatingChunkMap.clone();
2021-07-06 16:00:00 +02:00
@@ -281,9 +304,12 @@
2019-04-23 04:00:00 +02:00
return completablefuture1.thenApply((list1) -> {
List<IChunkAccess> list2 = Lists.newArrayList();
- final int l1 = 0;
+ // CraftBukkit start - decompile error
+ int cnt = 0;
- for (Iterator iterator = list1.iterator(); iterator.hasNext(); ++l1) {
+ for (Iterator iterator = list1.iterator(); iterator.hasNext(); ++cnt) {
+ final int l1 = cnt;
2016-12-06 12:05:58 +01:00
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
final Either<IChunkAccess, PlayerChunk.Failure> either = (Either) iterator.next();
Optional<IChunkAccess> optional = either.left();
2021-07-06 16:00:00 +02:00
@@ -390,7 +416,7 @@
this.j();
2019-05-14 02:00:00 +02:00
} else {
2021-06-11 07:00:00 +02:00
this.visibleChunkMap.values().stream().filter(PlayerChunk::hasBeenLoaded).forEach((playerchunk) -> {
2019-05-14 02:00:00 +02:00
- IChunkAccess ichunkaccess = (IChunkAccess) playerchunk.getChunkSave().getNow((Object) null);
+ IChunkAccess ichunkaccess = (IChunkAccess) playerchunk.getChunkSave().getNow(null); // CraftBukkit - decompile error
2016-12-06 12:05:58 +01:00
2019-05-14 02:00:00 +02:00
if (ichunkaccess instanceof ProtoChunkExtension || ichunkaccess instanceof Chunk) {
this.saveChunk(ichunkaccess);
2021-07-06 16:00:00 +02:00
@@ -401,7 +427,6 @@
2014-11-25 22:32:16 +01:00
}
2019-04-26 08:56:49 +02:00
}
-
protected void unloadChunks(BooleanSupplier booleansupplier) {
2021-06-11 07:00:00 +02:00
GameProfilerFiller gameprofilerfiller = this.level.getMethodProfiler();
2019-04-23 04:00:00 +02:00
2021-07-06 16:00:00 +02:00
@@ -440,7 +465,7 @@
2019-05-27 22:30:00 +02:00
private void a(long i, PlayerChunk playerchunk) {
CompletableFuture<IChunkAccess> completablefuture = playerchunk.getChunkSave();
- Consumer consumer = (ichunkaccess) -> {
+ Consumer<IChunkAccess> consumer = (ichunkaccess) -> { // CraftBukkit - decompile error
CompletableFuture<IChunkAccess> completablefuture1 = playerchunk.getChunkSave();
if (completablefuture1 != completablefuture) {
2021-07-06 16:00:00 +02:00
@@ -616,7 +641,21 @@
2021-06-11 07:00:00 +02:00
private static void a(WorldServer worldserver, List<NBTTagCompound> list) {
if (!list.isEmpty()) {
- worldserver.b(EntityTypes.a(list, (World) worldserver));
+ // CraftBukkit start - these are spawned serialized (DefinedStructure) and we don't call an add event below at the moment due to ordering complexities
+ worldserver.b(EntityTypes.a(list, (World) worldserver).filter((entity) -> {
+ boolean needsRemoval = false;
2021-06-11 13:33:49 +02:00
+ net.minecraft.server.dedicated.DedicatedServer server = worldserver.getCraftServer().getServer();
2021-06-11 07:00:00 +02:00
+ if (!server.getSpawnNPCs() && entity instanceof net.minecraft.world.entity.npc.NPC) {
+ entity.die();
+ needsRemoval = true;
+ }
+ if (!server.getSpawnAnimals() && (entity instanceof net.minecraft.world.entity.animal.EntityAnimal || entity instanceof net.minecraft.world.entity.animal.EntityWaterAnimal)) {
+ entity.die();
+ needsRemoval = true;
+ }
+ return !needsRemoval;
+ }));
+ // CraftBukkit end
}
}
2021-07-06 16:00:00 +02:00
@@ -844,7 +883,8 @@
2019-07-20 01:00:00 +02:00
return ichunkaccess instanceof Chunk ? Optional.of((Chunk) ichunkaccess) : Optional.empty();
});
2021-06-11 07:00:00 +02:00
- csvwriter.a(chunkcoordintpair.x, chunkcoordintpair.z, playerchunk.getTicketLevel(), optional.isPresent(), optional.map(IChunkAccess::getChunkStatus).orElse((Object) null), optional1.map(Chunk::getState).orElse((Object) null), a(playerchunk.c()), a(playerchunk.a()), a(playerchunk.b()), this.distanceManager.c(entry.getLongKey()), !this.isOutsideOfRange(chunkcoordintpair), optional1.map((chunk) -> {
2020-02-02 01:18:17 +01:00
+ // CraftBukkit - decompile error
2021-06-11 07:00:00 +02:00
+ csvwriter.a(chunkcoordintpair.x, chunkcoordintpair.z, playerchunk.getTicketLevel(), optional.isPresent(), optional.map(IChunkAccess::getChunkStatus).orElse(null), optional1.map(Chunk::getState).orElse(null), a(playerchunk.c()), a(playerchunk.a()), a(playerchunk.b()), this.distanceManager.c(entry.getLongKey()), !this.isOutsideOfRange(chunkcoordintpair), optional1.map((chunk) -> {
2019-07-20 01:00:00 +02:00
return chunk.getTileEntities().size();
2021-06-11 07:00:00 +02:00
}).orElse(0));
}
2021-07-06 16:00:00 +02:00
@@ -853,7 +893,7 @@
2019-07-20 01:00:00 +02:00
private static String a(CompletableFuture<Either<Chunk, PlayerChunk.Failure>> completablefuture) {
try {
- Either<Chunk, PlayerChunk.Failure> either = (Either) completablefuture.getNow((Object) null);
2020-02-02 01:18:17 +01:00
+ Either<Chunk, PlayerChunk.Failure> either = (Either) completablefuture.getNow(null); // CraftBukkit - decompile error
2019-07-20 01:00:00 +02:00
return either != null ? (String) either.map((chunk) -> {
return "done";
2021-07-06 16:00:00 +02:00
@@ -871,7 +911,7 @@
2019-05-14 02:00:00 +02:00
private NBTTagCompound readChunkData(ChunkCoordIntPair chunkcoordintpair) throws IOException {
2019-04-23 04:00:00 +02:00
NBTTagCompound nbttagcompound = this.read(chunkcoordintpair);
2021-06-11 07:00:00 +02:00
- return nbttagcompound == null ? null : this.getChunkData(this.level.getDimensionKey(), this.overworldDataStorage, nbttagcompound);
+ return nbttagcompound == null ? null : this.getChunkData(this.level.getTypeKey(), this.overworldDataStorage, nbttagcompound, chunkcoordintpair, level); // CraftBukkit
2019-04-23 04:00:00 +02:00
}
2019-06-02 11:51:26 +02:00
boolean isOutsideOfRange(ChunkCoordIntPair chunkcoordintpair) {
2021-07-06 16:00:00 +02:00
@@ -1238,7 +1278,7 @@
2021-06-11 07:00:00 +02:00
public final Set<ServerPlayerConnection> seenBy = Sets.newIdentityHashSet();
2019-04-23 04:00:00 +02:00
public EntityTracker(Entity entity, int i, int j, boolean flag) {
2021-06-11 07:00:00 +02:00
- this.serverEntity = new EntityTrackerEntry(PlayerChunkMap.this.level, entity, j, flag, this::broadcast);
+ this.serverEntity = new EntityTrackerEntry(PlayerChunkMap.this.level, entity, j, flag, this::broadcast, seenBy); // CraftBukkit
this.entity = entity;
this.range = i;
this.lastSectionPos = SectionPosition.a(entity);
2021-07-06 16:00:00 +02:00
@@ -1291,10 +1331,18 @@
2019-07-10 11:56:39 +02:00
public void updatePlayer(EntityPlayer entityplayer) {
2021-06-11 07:00:00 +02:00
if (entityplayer != this.entity) {
- Vec3D vec3d = entityplayer.getPositionVector().d(this.serverEntity.b());
+ Vec3D vec3d = entityplayer.getPositionVector().d(this.entity.getPositionVector()); // MC-155077, SPIGOT-5113
2019-12-10 23:00:00 +01:00
int i = Math.min(this.b(), (PlayerChunkMap.this.viewDistance - 1) * 16);
2021-06-11 07:00:00 +02:00
boolean flag = vec3d.x >= (double) (-i) && vec3d.x <= (double) i && vec3d.z >= (double) (-i) && vec3d.z <= (double) i && this.entity.a(entityplayer);
+ // CraftBukkit start - respect vanish API
+ if (this.entity instanceof EntityPlayer) {
+ Player player = ((EntityPlayer) this.entity).getBukkitEntity();
+ if (!entityplayer.getBukkitEntity().canSee(player)) {
+ flag = false;
2019-04-23 04:00:00 +02:00
+ }
2021-06-11 07:00:00 +02:00
+ }
+ // CraftBukkit end
if (flag) {
if (this.seenBy.add(entityplayer.connection)) {
this.serverEntity.b(entityplayer);