PaperMC/nms-patches/RegionFileCache.patch

43 lines
1.9 KiB
Diff
Raw Normal View History

--- a/net/minecraft/server/RegionFileCache.java
+++ b/net/minecraft/server/RegionFileCache.java
2019-04-23 04:00:00 +02:00
@@ -18,7 +18,7 @@
2019-12-10 23:00:00 +01:00
this.b = file;
2018-08-26 04:00:00 +02:00
}
2019-12-10 23:00:00 +01:00
- private RegionFile getFile(ChunkCoordIntPair chunkcoordintpair) throws IOException {
+ private RegionFile getFile(ChunkCoordIntPair chunkcoordintpair, boolean existingOnly) throws IOException { // CraftBukkit
2019-04-23 04:00:00 +02:00
long i = ChunkCoordIntPair.pair(chunkcoordintpair.getRegionX(), chunkcoordintpair.getRegionZ());
RegionFile regionfile = (RegionFile) this.cache.getAndMoveToFirst(i);
2018-08-26 04:00:00 +02:00
2019-04-23 04:00:00 +02:00
@@ -34,6 +34,7 @@
}
2019-12-10 23:00:00 +01:00
File file = new File(this.b, "r." + chunkcoordintpair.getRegionX() + "." + chunkcoordintpair.getRegionZ() + ".mca");
2019-04-23 04:00:00 +02:00
+ if (existingOnly && !file.exists()) return null; // CraftBukkit
2019-12-10 23:00:00 +01:00
RegionFile regionfile1 = new RegionFile(file, this.b);
2019-04-23 04:00:00 +02:00
this.cache.putAndMoveToFirst(i, regionfile1);
@@ -43,7 +44,12 @@
2018-07-15 02:00:00 +02:00
@Nullable
2019-04-23 04:00:00 +02:00
public NBTTagCompound read(ChunkCoordIntPair chunkcoordintpair) throws IOException {
2019-12-10 23:00:00 +01:00
- RegionFile regionfile = this.getFile(chunkcoordintpair);
+ // CraftBukkit start - SPIGOT-5680: There's no good reason to preemptively create files on read, save that for writing
+ RegionFile regionfile = this.getFile(chunkcoordintpair, true);
+ if (regionfile == null) {
+ return null;
+ }
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
DataInputStream datainputstream = regionfile.a(chunkcoordintpair);
Throwable throwable = null;
@@ -78,7 +84,7 @@
}
2019-04-23 04:00:00 +02:00
protected void write(ChunkCoordIntPair chunkcoordintpair, NBTTagCompound nbttagcompound) throws IOException {
2019-12-10 23:00:00 +01:00
- RegionFile regionfile = this.getFile(chunkcoordintpair);
+ RegionFile regionfile = this.getFile(chunkcoordintpair, false); // CraftBukkit
2019-04-23 04:00:00 +02:00
DataOutputStream dataoutputstream = regionfile.c(chunkcoordintpair);
Throwable throwable = null;