1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
--- a/net/minecraft/server/RegionFileCache.java
+++ b/net/minecraft/server/RegionFileCache.java
@@ -36,6 +36,29 @@
}
}
+ // CraftBukkit start
+ public static synchronized RegionFile b(File file, int i, int j) {
+ File file1 = new File(file, "region");
+ File file2 = new File(file1, "r." + (i >> 5) + "." + (j >> 5) + ".mca");
+ RegionFile regionfile = (RegionFile) RegionFileCache.a.get(file2);
+
+ if (regionfile != null) {
+ return regionfile;
+ } else if (file1.exists() && file2.exists()) {
+ if (RegionFileCache.a.size() >= 256) {
+ a();
+ }
+
+ RegionFile regionfile1 = new RegionFile(file2);
+
+ RegionFileCache.a.put(file2, regionfile1);
+ return regionfile1;
+ } else {
+ return null;
+ }
+ }
+ // CraftBukkit end
+
public static synchronized void a() {
Iterator iterator = RegionFileCache.a.values().iterator();
@@ -55,16 +78,32 @@
}
@Nullable
- public static DataInputStream read(File file, int i, int j) {
+ // CraftBukkit start - call sites hoisted for synchronization
+ public static synchronized NBTTagCompound read(File file, int i, int j) throws IOException {
RegionFile regionfile = a(file, i, j);
- return regionfile.a(i & 31, j & 31);
+ DataInputStream datainputstream = regionfile.a(i & 31, j & 31);
+
+ if (datainputstream == null) {
+ return null;
+ }
+
+ return NBTCompressedStreamTools.a(datainputstream);
}
@Nullable
- public static DataOutputStream write(File file, int i, int j) {
+ public static synchronized void write(File file, int i, int j, NBTTagCompound nbttagcompound) throws IOException {
RegionFile regionfile = a(file, i, j);
- return regionfile.c(i & 31, j & 31);
+ DataOutputStream dataoutputstream = regionfile.c(i & 31, j & 31);
+ NBTCompressedStreamTools.a(nbttagcompound, (java.io.DataOutput) dataoutputstream);
+ dataoutputstream.close();
+ }
+
+ public static synchronized boolean chunkExists(File file, int i, int j) {
+ RegionFile regionfile = b(file, i, j);
+
+ return regionfile != null ? regionfile.d(i & 31, j & 31) : false;
}
+ // CraftBukkit end
}
|