2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/PlayerChunkMap.java
+++ b/net/minecraft/server/PlayerChunkMap.java
2020-06-25 02:00:00 +02:00
@@ -44,6 +44,7 @@
2019-05-14 02:00:00 +02:00
import org.apache.commons.lang3.mutable.MutableBoolean;
2019-04-23 04:00:00 +02:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2019-05-16 01:11:20 +02:00
+import org.bukkit.entity.Player; // CraftBukkit
2019-04-23 04:00:00 +02:00
public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
2020-06-25 02:00:00 +02:00
@@ -75,6 +76,31 @@
private final Queue<Runnable> A;
2019-07-13 20:19:44 +02:00
private int viewDistance;
+ // 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 {
+
+ private Runnable queued;
+
+ @Override
+ public void execute(Runnable runnable) {
+ if (queued != null) {
+ throw new IllegalStateException("Already queued");
+ }
+ queued = runnable;
+ }
+
+ @Override
+ public void run() {
+ Runnable task = queued;
+ queued = null;
+ if (task != null) {
+ task.run();
+ }
+ }
+ };
+ // CraftBukkit end
+
2020-06-25 02: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, Supplier<WorldPersistentData> supplier, int i, boolean flag) {
super(new File(convertable_conversionsession.a(worldserver.getDimensionKey()), "region"), datafixer, flag);
2019-07-13 20:19:44 +02:00
this.visibleChunks = this.updatingChunks.clone();
2020-06-25 02:00:00 +02:00
@@ -195,9 +221,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();
2020-06-25 02:00:00 +02:00
@@ -300,7 +329,7 @@
2019-12-10 23:00:00 +01:00
PlayerChunkMap.LOGGER.info("ThreadedAnvilChunkStorage ({}): All chunks are saved", this.w.getName());
2019-05-14 02:00:00 +02:00
} else {
this.visibleChunks.values().stream().filter(PlayerChunk::hasBeenLoaded).forEach((playerchunk) -> {
- 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);
2020-06-25 02:00:00 +02:00
@@ -311,7 +340,6 @@
2014-11-25 22:32:16 +01:00
}
2019-04-26 08:56:49 +02:00
}
-
protected void unloadChunks(BooleanSupplier booleansupplier) {
GameProfilerFiller gameprofilerfiller = this.world.getMethodProfiler();
2019-04-23 04:00:00 +02:00
2020-06-25 02:00:00 +02:00
@@ -350,7 +378,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) {
2020-06-25 02:00:00 +02:00
@@ -572,8 +600,15 @@
2019-12-05 01:01:56 +01:00
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();
+ // CraftBukkit start - these are spawned serialized (DefinedStructure) and we don't call an add event below at the moment due to ordering complexities
+ boolean needsRemoval = false;
+ if (chunk.needsDecoration && !this.world.getServer().getServer().getSpawnNPCs() && entity instanceof NPC) {
+ entity.die();
+ needsRemoval = true;
+ }
- if (!(entity instanceof EntityHuman) && !this.world.addEntityChunk(entity)) {
+ if (!(entity instanceof EntityHuman) && (needsRemoval || !this.world.addEntityChunk(entity))) {
+ // CraftBukkit end
if (list == null) {
list = Lists.newArrayList(new Entity[]{entity});
} else {
2020-06-25 02:00:00 +02:00
@@ -784,7 +819,8 @@
2019-07-20 01:00:00 +02:00
return ichunkaccess instanceof Chunk ? Optional.of((Chunk) ichunkaccess) : Optional.empty();
});
- 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.chunkDistanceManager.c(entry.getLongKey()), !this.isOutsideOfRange(chunkcoordintpair), optional1.map((chunk) -> {
2020-02-02 01:18:17 +01:00
+ // CraftBukkit - decompile error
2019-07-20 01: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.chunkDistanceManager.c(entry.getLongKey()), !this.isOutsideOfRange(chunkcoordintpair), optional1.map((chunk) -> {
return Stream.of(chunk.getEntitySlices()).mapToInt(EntitySlice::size).sum();
}).orElse(0), optional1.map((chunk) -> {
return chunk.getTileEntities().size();
2020-06-25 02:00:00 +02:00
@@ -795,7 +831,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";
2020-06-25 02:00:00 +02:00
@@ -813,7 +849,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);
2020-06-25 02:00:00 +02:00
- return nbttagcompound == null ? null : this.getChunkData(this.world.getDimensionKey(), this.l, nbttagcompound);
2020-06-25 09:58:10 +02:00
+ return nbttagcompound == null ? null : this.getChunkData(this.world.getTypeKey(), this.l, nbttagcompound, chunkcoordintpair, world); // CraftBukkit
2019-04-23 04:00:00 +02:00
}
2019-06-02 11:51:26 +02:00
boolean isOutsideOfRange(ChunkCoordIntPair chunkcoordintpair) {
2020-06-25 02:00:00 +02:00
@@ -1145,7 +1181,7 @@
2019-04-23 04:00:00 +02:00
public final Set<EntityPlayer> trackedPlayers = Sets.newHashSet();
public EntityTracker(Entity entity, int i, int j, boolean flag) {
- this.trackerEntry = new EntityTrackerEntry(PlayerChunkMap.this.world, entity, j, flag, this::broadcast);
+ this.trackerEntry = new EntityTrackerEntry(PlayerChunkMap.this.world, entity, j, flag, this::broadcast, trackedPlayers); // CraftBukkit
this.tracker = entity;
this.trackingDistance = i;
this.e = SectionPosition.a(entity);
2020-06-25 02:00:00 +02:00
@@ -1198,7 +1234,7 @@
2019-07-10 11:56:39 +02:00
public void updatePlayer(EntityPlayer entityplayer) {
if (entityplayer != this.tracker) {
2019-12-10 23:00:00 +01:00
- Vec3D vec3d = entityplayer.getPositionVector().d(this.trackerEntry.b());
+ Vec3D vec3d = entityplayer.getPositionVector().d(this.tracker.getPositionVector()); // MC-155077, SPIGOT-5113
int i = Math.min(this.b(), (PlayerChunkMap.this.viewDistance - 1) * 16);
2019-07-10 11:56:39 +02:00
boolean flag = vec3d.x >= (double) (-i) && vec3d.x <= (double) i && vec3d.z >= (double) (-i) && vec3d.z <= (double) i && this.tracker.a(entityplayer);
2020-06-25 02:00:00 +02:00
@@ -1214,6 +1250,17 @@
2019-04-23 04:00:00 +02:00
}
}
+ // CraftBukkit start - respect vanish API
+ if (this.tracker instanceof EntityPlayer) {
+ Player player = ((EntityPlayer) this.tracker).getBukkitEntity();
+ if (!entityplayer.getBukkitEntity().canSee(player)) {
+ flag1 = false;
+ }
+ }
2014-11-25 22:32:16 +01:00
+
2019-04-23 04:00:00 +02:00
+ entityplayer.removeQueue.remove(Integer.valueOf(this.tracker.getId()));
+ // CraftBukkit end
2014-11-25 22:32:16 +01:00
+
2019-04-23 04:00:00 +02:00
if (flag1 && this.trackedPlayers.add(entityplayer)) {
this.trackerEntry.b(entityplayer);
}