Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 83 lines 2.1 kB view raw
1package net.minecraft.server; 2 3import java.io.DataInputStream; 4import java.io.DataOutputStream; 5import java.io.File; 6import java.io.IOException; 7import java.lang.ref.Reference; 8import java.lang.ref.SoftReference; 9import java.util.HashMap; 10import java.util.Iterator; 11import java.util.Map; 12 13public class RegionFileCache { 14 15 private static final Map a = new HashMap(); 16 17 private RegionFileCache() { 18 } 19 20 public static synchronized RegionFile a(File file1, int i, int j) { 21 File file2 = new File(file1, "region"); 22 File file3 = new File(file2, "r." + (i >> 5) + "." + (j >> 5) + ".mcr"); 23 Reference reference = (Reference) a.get(file3); 24 RegionFile regionfile; 25 26 if (reference != null) { 27 regionfile = (RegionFile) reference.get(); 28 if (regionfile != null) { 29 return regionfile; 30 } 31 } 32 33 if (!file2.exists()) { 34 file2.mkdirs(); 35 } 36 37 if (a.size() >= 256) { 38 a(); 39 } 40 41 regionfile = new RegionFile(file3); 42 a.put(file3, new SoftReference(regionfile)); 43 return regionfile; 44 } 45 46 public static synchronized void a() { 47 Iterator iterator = a.values().iterator(); 48 49 while (iterator.hasNext()) { 50 Reference reference = (Reference) iterator.next(); 51 52 try { 53 RegionFile regionfile = (RegionFile) reference.get(); 54 55 if (regionfile != null) { 56 regionfile.b(); 57 } 58 } catch (IOException ioexception) { 59 ioexception.printStackTrace(); 60 } 61 } 62 63 a.clear(); 64 } 65 66 public static int b(File file1, int i, int j) { 67 RegionFile regionfile = a(file1, i, j); 68 69 return regionfile.a(); 70 } 71 72 public static DataInputStream c(File file1, int i, int j) { 73 RegionFile regionfile = a(file1, i, j); 74 75 return regionfile.a(i & 31, j & 31); 76 } 77 78 public static DataOutputStream d(File file1, int i, int j) { 79 RegionFile regionfile = a(file1, i, j); 80 81 return regionfile.b(i & 31, j & 31); 82 } 83}