mirror of
https://github.com/barkeser2002/Tenet.git
synced 2026-09-25 11:26:10 +03:00
155 lines
5.1 KiB
Diff
155 lines
5.1 KiB
Diff
--- ../src-base/minecraft/net/minecraft/world/chunk/storage/RegionFileCache.java
|
|
+++ ../src-work/minecraft/net/minecraft/world/chunk/storage/RegionFileCache.java
|
|
@@ -6,74 +6,95 @@
|
|
import java.io.IOException;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
+import java.util.LinkedHashMap;
|
|
import java.util.Map;
|
|
|
|
public class RegionFileCache
|
|
{
|
|
- private static final Map regionsByFilename = new HashMap();
|
|
- private static final String __OBFID = "CL_00000383";
|
|
+ public static final Map<File,RegionFile> regionsByFilename = new LinkedHashMap(256, 0.75f, true); // Spigot - private -> public, Paper - HashMap -> LinkedHashMap
|
|
+ private static final String __OBFID = "CL_00000383";
|
|
|
|
- public static synchronized RegionFile createOrLoadRegionFile(File p_76550_0_, int p_76550_1_, int p_76550_2_)
|
|
- {
|
|
- File file2 = new File(p_76550_0_, "region");
|
|
- File file3 = new File(file2, "r." + (p_76550_1_ >> 5) + "." + (p_76550_2_ >> 5) + ".mca");
|
|
- RegionFile regionfile = (RegionFile)regionsByFilename.get(file3);
|
|
+ public static synchronized RegionFile createOrLoadRegionFile(File p_76550_0_, int p_76550_1_, int p_76550_2_)
|
|
+ {
|
|
+ return createOrLoadRegionFile(p_76550_0_, p_76550_1_, p_76550_2_, true);
|
|
+ }
|
|
+ public static synchronized RegionFile createOrLoadRegionFile(File p_76550_0_, int p_76550_1_, int p_76550_2_, boolean create)
|
|
+ {
|
|
+ File file2 = new File(p_76550_0_, "region");
|
|
+ File file3 = new File(file2, "r." + (p_76550_1_ >> 5) + "." + (p_76550_2_ >> 5) + ".mca");
|
|
+ RegionFile regionfile = (RegionFile)regionsByFilename.get(file3);
|
|
|
|
- if (regionfile != null)
|
|
- {
|
|
- return regionfile;
|
|
- }
|
|
- else
|
|
- {
|
|
- if (!file2.exists())
|
|
- {
|
|
- file2.mkdirs();
|
|
- }
|
|
+ if (regionfile != null)
|
|
+ {
|
|
+ return regionfile;
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ if (!create && !file2.exists()) { return null; } // PaperSpigot
|
|
+ if (!file2.exists())
|
|
+ {
|
|
+ file2.mkdirs();
|
|
+ }
|
|
|
|
- if (regionsByFilename.size() >= 256)
|
|
- {
|
|
- clearRegionFileReferences();
|
|
- }
|
|
+ if (RegionFileCache.regionsByFilename.size() >= 256) { // Paper
|
|
+ trimCache(); // Paper
|
|
+ }
|
|
|
|
- RegionFile regionfile1 = new RegionFile(file3);
|
|
- regionsByFilename.put(file3, regionfile1);
|
|
- return regionfile1;
|
|
- }
|
|
- }
|
|
+ RegionFile regionfile1 = new RegionFile(file3);
|
|
+ regionsByFilename.put(file3, regionfile1);
|
|
+ return regionfile1;
|
|
+ }
|
|
+ }
|
|
|
|
- public static synchronized void clearRegionFileReferences()
|
|
- {
|
|
- Iterator iterator = regionsByFilename.values().iterator();
|
|
+ // Paper Start
|
|
+ private static synchronized void trimCache() {
|
|
+ Iterator<Map.Entry<File, RegionFile>> itr = RegionFileCache.regionsByFilename.entrySet().iterator();
|
|
+ int count = RegionFileCache.regionsByFilename.size() - 256;
|
|
+ while (count-- >= 0 && itr.hasNext()) {
|
|
+ try {
|
|
+ itr.next().getValue().close();
|
|
+ } catch (IOException ioexception) {
|
|
+ ioexception.printStackTrace();
|
|
+ // ServerInternalException.reportInternalException(ioexception);
|
|
+ }
|
|
+ itr.remove();
|
|
+ }
|
|
+ }
|
|
+ // Paper End
|
|
|
|
- while (iterator.hasNext())
|
|
- {
|
|
- RegionFile regionfile = (RegionFile)iterator.next();
|
|
+ public static synchronized void clearRegionFileReferences()
|
|
+ {
|
|
+ Iterator iterator = regionsByFilename.values().iterator();
|
|
|
|
- try
|
|
- {
|
|
- if (regionfile != null)
|
|
- {
|
|
- regionfile.close();
|
|
- }
|
|
- }
|
|
- catch (IOException ioexception)
|
|
- {
|
|
- ioexception.printStackTrace();
|
|
- }
|
|
- }
|
|
+ while (iterator.hasNext())
|
|
+ {
|
|
+ RegionFile regionfile = (RegionFile)iterator.next();
|
|
|
|
- regionsByFilename.clear();
|
|
- }
|
|
+ try
|
|
+ {
|
|
+ if (regionfile != null)
|
|
+ {
|
|
+ regionfile.close();
|
|
+ }
|
|
+ }
|
|
+ catch (IOException ioexception)
|
|
+ {
|
|
+ ioexception.printStackTrace();
|
|
+ }
|
|
+ }
|
|
|
|
- public static DataInputStream getChunkInputStream(File p_76549_0_, int p_76549_1_, int p_76549_2_)
|
|
- {
|
|
- RegionFile regionfile = createOrLoadRegionFile(p_76549_0_, p_76549_1_, p_76549_2_);
|
|
- return regionfile.getChunkDataInputStream(p_76549_1_ & 31, p_76549_2_ & 31);
|
|
- }
|
|
+ regionsByFilename.clear();
|
|
+ }
|
|
|
|
- public static DataOutputStream getChunkOutputStream(File p_76552_0_, int p_76552_1_, int p_76552_2_)
|
|
- {
|
|
- RegionFile regionfile = createOrLoadRegionFile(p_76552_0_, p_76552_1_, p_76552_2_);
|
|
- return regionfile.getChunkDataOutputStream(p_76552_1_ & 31, p_76552_2_ & 31);
|
|
- }
|
|
+ public static DataInputStream getChunkInputStream(File p_76549_0_, int p_76549_1_, int p_76549_2_)
|
|
+ {
|
|
+ RegionFile regionfile = createOrLoadRegionFile(p_76549_0_, p_76549_1_, p_76549_2_);
|
|
+ return regionfile.getChunkDataInputStream(p_76549_1_ & 31, p_76549_2_ & 31);
|
|
+ }
|
|
+
|
|
+ public static DataOutputStream getChunkOutputStream(File p_76552_0_, int p_76552_1_, int p_76552_2_)
|
|
+ {
|
|
+ RegionFile regionfile = createOrLoadRegionFile(p_76552_0_, p_76552_1_, p_76552_2_);
|
|
+ return regionfile.getChunkDataOutputStream(p_76552_1_ & 31, p_76552_2_ & 31);
|
|
+ }
|
|
}
|