Commits

md_5 authored 43ab2669d76
SPIGOT-2634: Concurrency issue in FileIOThread
No tags

nms-patches/ChunkRegionLoader.patch

Modified
83 83 - return chunk;
84 84 + // CraftBukkit start
85 85 + Object[] data = new Object[2];
86 86 + data[0] = chunk;
87 87 + data[1] = nbttagcompound;
88 88 + return data;
89 89 + // CraftBukkit end
90 90 }
91 91 }
92 92 }
93 -@@ -131,10 +179,14 @@
93 +@@ -98,20 +146,27 @@
94 + }
95 +
96 + public boolean c() {
97 +- if (this.b.isEmpty()) {
98 ++ // CraftBukkit start
99 ++ Iterator<Map.Entry<ChunkCoordIntPair, NBTTagCompound>> iter = this.b.entrySet().iterator();
100 ++ if (!iter.hasNext()) {
101 ++ // CraftBukkit end
102 + if (this.f) {
103 + ChunkRegionLoader.a.info("ThreadedAnvilChunkStorage ({}): All chunks are saved", new Object[] { this.d.getName()});
104 + }
105 +
106 + return false;
107 + } else {
108 +- ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair) this.b.keySet().iterator().next();
109 ++ // CraftBukkit start
110 ++ Map.Entry<ChunkCoordIntPair, NBTTagCompound> entry = iter.next();
111 ++ iter.remove(); // Pop single entry
112 ++ ChunkCoordIntPair chunkcoordintpair = entry.getKey();
113 ++ // CraftBukkit end
114 +
115 + boolean flag;
116 +
117 + try {
118 + this.c.add(chunkcoordintpair);
119 +- NBTTagCompound nbttagcompound = (NBTTagCompound) this.b.remove(chunkcoordintpair);
120 ++ NBTTagCompound nbttagcompound = (NBTTagCompound) entry.getValue(); // CraftBukkit
121 +
122 + if (nbttagcompound != null) {
123 + try {
124 +@@ -131,10 +186,14 @@
94 125 }
95 126
96 127 private void b(ChunkCoordIntPair chunkcoordintpair, NBTTagCompound nbttagcompound) throws IOException {
97 128 - DataOutputStream dataoutputstream = RegionFileCache.d(this.d, chunkcoordintpair.x, chunkcoordintpair.z);
98 129 + // CraftBukkit start
99 130 + RegionFileCache.d(this.d, chunkcoordintpair.x, chunkcoordintpair.z, nbttagcompound);
100 131
101 132 + /*
102 133 NBTCompressedStreamTools.a(nbttagcompound, (DataOutput) dataoutputstream);
103 134 dataoutputstream.close();
104 135 + */
105 136 + // CraftBukkit end
106 137 }
107 138
108 139 public void b(World world, Chunk chunk) throws IOException {}
109 -@@ -149,6 +201,7 @@
140 +@@ -149,6 +208,7 @@
110 141 if (this.c()) {
111 142 continue;
112 143 }
113 144 + break; // CraftBukkit - Fix infinite loop when saving chunks
114 145 }
115 146 } finally {
116 147 this.f = false;
117 -@@ -326,6 +379,13 @@
148 +@@ -326,6 +386,13 @@
118 149 chunk.a(nbttagcompound.getByteArray("Biomes"));
119 150 }
120 151
121 152 + // CraftBukkit start - End this method here and split off entity loading to another method
122 153 + return chunk;
123 154 + }
124 155 +
125 156 + public void loadEntities(Chunk chunk, NBTTagCompound nbttagcompound, World world) {
126 157 + // CraftBukkit end
127 158 +
128 159 NBTTagList nbttaglist1 = nbttagcompound.getList("Entities", 10);
129 160
130 161 if (nbttaglist1 != null) {
131 -@@ -369,7 +429,7 @@
162 +@@ -369,7 +436,7 @@
132 163 }
133 164 }
134 165
135 166 - return chunk;
136 167 + // return chunk; // CraftBukkit
137 168 }
138 169
139 170 @Nullable
140 -@@ -397,14 +457,20 @@
171 +@@ -397,14 +464,20 @@
141 172 }
142 173
143 174 @Nullable
144 175 + // CraftBukkit start
145 176 public static Entity a(NBTTagCompound nbttagcompound, World world, double d0, double d1, double d2, boolean flag) {
146 177 + return spawnEntity(nbttagcompound, world, d0, d1, d2, flag, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
147 178 + }
148 179 +
149 180 + public static Entity spawnEntity(NBTTagCompound nbttagcompound, World world, double d0, double d1, double d2, boolean flag, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
150 181 + // CraftBukkit end
151 182 Entity entity = a(nbttagcompound, world);
152 183
153 184 if (entity == null) {
154 185 return null;
155 186 } else {
156 187 entity.setPositionRotation(d0, d1, d2, entity.yaw, entity.pitch);
157 188 - if (flag && !world.addEntity(entity)) {
158 189 + if (flag && !world.addEntity(entity, spawnReason)) { // CraftBukkit
159 190 return null;
160 191 } else {
161 192 if (nbttagcompound.hasKeyOfType("Passengers", 9)) {
162 -@@ -433,8 +499,14 @@
193 +@@ -433,8 +506,14 @@
163 194 }
164 195 }
165 196
166 197 + // CraftBukkit start
167 198 public static void a(Entity entity, World world) {
168 199 - if (world.addEntity(entity) && entity.isVehicle()) {
169 200 + a(entity, world, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
170 201 + }
171 202 +
172 203 + 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