Commits

md_5 authored 7f1a32252b4
SPIGOT-2385: RegionFileCache synchronization issues
No tags

nms-patches/ChunkRegionLoader.patch

Modified
1 1 --- a/net/minecraft/server/ChunkRegionLoader.java
2 2 +++ b/net/minecraft/server/ChunkRegionLoader.java
3 -@@ -29,8 +29,36 @@
3 +@@ -29,25 +29,55 @@
4 4 this.e = dataconvertermanager;
5 5 }
6 6
7 7 + // CraftBukkit start
8 8 + public boolean chunkExists(World world, int i, int j) {
9 9 + ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(i, j);
10 10 +
11 11 + if (this.c.contains(chunkcoordintpair)) {
12 12 + if (this.b.containsKey(chunkcoordintpair)) {
13 13 + return true;
30 30 + }
31 31 +
32 32 + return null;
33 33 + }
34 34 +
35 35 + public Object[] loadChunk(World world, int i, int j) throws IOException {
36 36 + // CraftBukkit end
37 37 ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(i, j);
38 38 NBTTagCompound nbttagcompound = (NBTTagCompound) this.b.get(chunkcoordintpair);
39 39
40 -@@ -47,7 +75,7 @@
40 + if (nbttagcompound == null) {
41 +- DataInputStream datainputstream = RegionFileCache.c(this.d, i, j);
42 ++ // CraftBukkit start
43 ++ nbttagcompound = RegionFileCache.c(this.d, i, j);
44 +
45 +- if (datainputstream == null) {
46 ++ if (nbttagcompound == null) {
47 + return null;
48 + }
49 +
50 +- nbttagcompound = this.e.a((DataConverterType) DataConverterTypes.CHUNK, NBTCompressedStreamTools.a(datainputstream));
51 ++ nbttagcompound = this.e.a((DataConverterType) DataConverterTypes.CHUNK, nbttagcompound);
52 ++ // CraftBukkit end
53 + }
54 +
41 55 return this.a(world, i, j, nbttagcompound);
42 56 }
43 57
44 58 - protected Chunk a(World world, int i, int j, NBTTagCompound nbttagcompound) {
45 59 + protected Object[] a(World world, int i, int j, NBTTagCompound nbttagcompound) { // CraftBukkit - return Chunk -> Object[]
46 60 if (!nbttagcompound.hasKeyOfType("Level", 10)) {
47 61 ChunkRegionLoader.a.error("Chunk file at {},{} is missing level data, skipping", new Object[] { Integer.valueOf(i), Integer.valueOf(j)});
48 62 return null;
49 -@@ -64,10 +92,28 @@
63 +@@ -64,10 +94,28 @@
50 64 ChunkRegionLoader.a.error("Chunk file at {},{} is in the wrong location; relocating. (Expected {}, {}, got {}, {})", new Object[] { Integer.valueOf(i), Integer.valueOf(j), Integer.valueOf(i), Integer.valueOf(j), Integer.valueOf(chunk.locX), Integer.valueOf(chunk.locZ)});
51 65 nbttagcompound1.setInt("xPos", i);
52 66 nbttagcompound1.setInt("zPos", j);
53 67 +
54 68 + // CraftBukkit start - Have to move tile entities since we don't load them at this stage
55 69 + NBTTagList tileEntities = nbttagcompound.getCompound("Level").getList("TileEntities", 10);
56 70 + if (tileEntities != null) {
57 71 + for (int te = 0; te < tileEntities.size(); te++) {
58 72 + NBTTagCompound tileEntity = (NBTTagCompound) tileEntities.get(te);
59 73 + int x = tileEntity.getInt("x") - chunk.locX * 16;
69 83 - return chunk;
70 84 + // CraftBukkit start
71 85 + Object[] data = new Object[2];
72 86 + data[0] = chunk;
73 87 + data[1] = nbttagcompound;
74 88 + return data;
75 89 + // CraftBukkit end
76 90 }
77 91 }
78 92 }
79 -@@ -326,6 +372,13 @@
93 +@@ -131,10 +179,14 @@
94 + }
95 +
96 + private void b(ChunkCoordIntPair chunkcoordintpair, NBTTagCompound nbttagcompound) throws IOException {
97 +- DataOutputStream dataoutputstream = RegionFileCache.d(this.d, chunkcoordintpair.x, chunkcoordintpair.z);
98 ++ // CraftBukkit start
99 ++ RegionFileCache.d(this.d, chunkcoordintpair.x, chunkcoordintpair.z, nbttagcompound);
100 +
101 ++ /*
102 + NBTCompressedStreamTools.a(nbttagcompound, (DataOutput) dataoutputstream);
103 + dataoutputstream.close();
104 ++ */
105 ++ // CraftBukkit end
106 + }
107 +
108 + public void b(World world, Chunk chunk) throws IOException {}
109 +@@ -326,6 +378,13 @@
80 110 chunk.a(nbttagcompound.getByteArray("Biomes"));
81 111 }
82 112
83 113 + // CraftBukkit start - End this method here and split off entity loading to another method
84 114 + return chunk;
85 115 + }
86 116 +
87 117 + public void loadEntities(Chunk chunk, NBTTagCompound nbttagcompound, World world) {
88 118 + // CraftBukkit end
89 119 +
90 120 NBTTagList nbttaglist1 = nbttagcompound.getList("Entities", 10);
91 121
92 122 if (nbttaglist1 != null) {
93 -@@ -369,7 +422,7 @@
123 +@@ -369,7 +428,7 @@
94 124 }
95 125 }
96 126
97 127 - return chunk;
98 128 + // return chunk; // CraftBukkit
99 129 }
100 130
101 131 @Nullable
102 -@@ -397,14 +450,20 @@
132 +@@ -397,14 +456,20 @@
103 133 }
104 134
105 135 @Nullable
106 136 + // CraftBukkit start
107 137 public static Entity a(NBTTagCompound nbttagcompound, World world, double d0, double d1, double d2, boolean flag) {
108 138 + return spawnEntity(nbttagcompound, world, d0, d1, d2, flag, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
109 139 + }
110 140 +
111 141 + public static Entity spawnEntity(NBTTagCompound nbttagcompound, World world, double d0, double d1, double d2, boolean flag, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
112 142 + // CraftBukkit end
113 143 Entity entity = a(nbttagcompound, world);
114 144
115 145 if (entity == null) {
116 146 return null;
117 147 } else {
118 148 entity.setPositionRotation(d0, d1, d2, entity.yaw, entity.pitch);
119 149 - if (flag && !world.addEntity(entity)) {
120 150 + if (flag && !world.addEntity(entity, spawnReason)) { // CraftBukkit
121 151 return null;
122 152 } else {
123 153 if (nbttagcompound.hasKeyOfType("Passengers", 9)) {
124 -@@ -433,8 +492,14 @@
154 +@@ -433,8 +498,14 @@
125 155 }
126 156 }
127 157
128 158 + // CraftBukkit start
129 159 public static void a(Entity entity, World world) {
130 160 - if (world.addEntity(entity) && entity.isVehicle()) {
131 161 + a(entity, world, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
132 162 + }
133 163 +
134 164 + public static void a(Entity entity, World world, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut