summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/ChunkRegionLoader.java
diff options
context:
space:
mode:
authorNathan Adams <dinnerbone@dinnerbone.com>2012-01-30 04:20:59 +0000
committerNathan Adams <dinnerbone@dinnerbone.com>2012-01-30 04:20:59 +0000
commit72559fe634393b795b56ccdf4c2b03247f504e5e (patch)
tree99a70fb1d9d531fbbf4b2a8eee10c2e968e6e702 /src/main/java/net/minecraft/server/ChunkRegionLoader.java
parent48661b636c5ed67b44ca1b0d35d252d156a97784 (diff)
downloadcraftbukkit-72559fe634393b795b56ccdf4c2b03247f504e5e.tar
craftbukkit-72559fe634393b795b56ccdf4c2b03247f504e5e.tar.gz
craftbukkit-72559fe634393b795b56ccdf4c2b03247f504e5e.tar.lz
craftbukkit-72559fe634393b795b56ccdf4c2b03247f504e5e.tar.xz
craftbukkit-72559fe634393b795b56ccdf4c2b03247f504e5e.zip
Added ChunkLoader.java and ChunkRegionLoader.java for diff visibility
Diffstat (limited to 'src/main/java/net/minecraft/server/ChunkRegionLoader.java')
-rw-r--r--src/main/java/net/minecraft/server/ChunkRegionLoader.java141
1 files changed, 141 insertions, 0 deletions
diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
new file mode 100644
index 00000000..0b6905ac
--- /dev/null
+++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
@@ -0,0 +1,141 @@
+package net.minecraft.server;
+
+import java.io.DataInput;
+import java.io.DataInputStream;
+import java.io.DataOutput;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class ChunkRegionLoader implements IChunkLoader, IAsyncChunkSaver {
+
+ private List a = new ArrayList();
+ private Set b = new HashSet();
+ private Object c = new Object();
+ private final File d;
+
+ public ChunkRegionLoader(File file1) {
+ this.d = file1;
+ }
+
+ public Chunk a(World world, int i, int j) {
+ NBTTagCompound nbttagcompound = null;
+ ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(i, j);
+ Object object = this.c;
+
+ synchronized (this.c) {
+ if (this.b.contains(chunkcoordintpair)) {
+ for (int k = 0; k < this.a.size(); ++k) {
+ if (((PendingChunkToSave) this.a.get(k)).a.equals(chunkcoordintpair)) {
+ nbttagcompound = ((PendingChunkToSave) this.a.get(k)).b;
+ break;
+ }
+ }
+ }
+ }
+
+ if (nbttagcompound == null) {
+ DataInputStream datainputstream = RegionFileCache.b(this.d, i, j);
+
+ if (datainputstream == null) {
+ return null;
+ }
+
+ nbttagcompound = NBTCompressedStreamTools.a((DataInput) datainputstream);
+ }
+
+ if (!nbttagcompound.hasKey("Level")) {
+ System.out.println("Chunk file at " + i + "," + j + " is missing level data, skipping");
+ return null;
+ } else if (!nbttagcompound.getCompound("Level").hasKey("Blocks")) {
+ System.out.println("Chunk file at " + i + "," + j + " is missing block data, skipping");
+ return null;
+ } else {
+ Chunk chunk = ChunkLoader.a(world, nbttagcompound.getCompound("Level"));
+
+ if (!chunk.a(i, j)) {
+ System.out.println("Chunk file at " + i + "," + j + " is in the wrong location; relocating. (Expected " + i + ", " + j + ", got " + chunk.x + ", " + chunk.z + ")");
+ nbttagcompound.setInt("xPos", i);
+ nbttagcompound.setInt("zPos", j);
+ chunk = ChunkLoader.a(world, nbttagcompound.getCompound("Level"));
+ }
+
+ chunk.h();
+ return chunk;
+ }
+ }
+
+ public void a(World world, Chunk chunk) {
+ world.l();
+
+ try {
+ NBTTagCompound nbttagcompound = new NBTTagCompound();
+ NBTTagCompound nbttagcompound1 = new NBTTagCompound();
+
+ nbttagcompound.set("Level", nbttagcompound1);
+ ChunkLoader.a(chunk, world, nbttagcompound1);
+ this.a(chunk.j(), nbttagcompound);
+ } catch (Exception exception) {
+ exception.printStackTrace();
+ }
+ }
+
+ private void a(ChunkCoordIntPair chunkcoordintpair, NBTTagCompound nbttagcompound) {
+ Object object = this.c;
+
+ synchronized (this.c) {
+ if (this.b.contains(chunkcoordintpair)) {
+ for (int i = 0; i < this.a.size(); ++i) {
+ if (((PendingChunkToSave) this.a.get(i)).a.equals(chunkcoordintpair)) {
+ this.a.set(i, new PendingChunkToSave(chunkcoordintpair, nbttagcompound));
+ return;
+ }
+ }
+ }
+
+ this.a.add(new PendingChunkToSave(chunkcoordintpair, nbttagcompound));
+ this.b.add(chunkcoordintpair);
+ FileIOThread.a.a(this);
+ }
+ }
+
+ public boolean c() {
+ PendingChunkToSave pendingchunktosave = null;
+ Object object = this.c;
+
+ synchronized (this.c) {
+ if (this.a.size() <= 0) {
+ return false;
+ }
+
+ pendingchunktosave = (PendingChunkToSave) this.a.remove(0);
+ this.b.remove(pendingchunktosave.a);
+ }
+
+ if (pendingchunktosave != null) {
+ try {
+ this.a(pendingchunktosave);
+ } catch (Exception exception) {
+ exception.printStackTrace();
+ }
+ }
+
+ return true;
+ }
+
+ public void a(PendingChunkToSave pendingchunktosave) {
+ DataOutputStream dataoutputstream = RegionFileCache.c(this.d, pendingchunktosave.a.x, pendingchunktosave.a.z);
+
+ NBTCompressedStreamTools.a(pendingchunktosave.b, (DataOutput) dataoutputstream);
+ dataoutputstream.close();
+ }
+
+ public void b(World world, Chunk chunk) {}
+
+ public void a() {}
+
+ public void b() {}
+}