|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
package com.gmail.nossr50.util.blockmeta;
|
|
|
|
|
package com.gmail.nossr50.util.blockmeta.chunkmeta;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
@ -17,20 +17,24 @@ import org.bukkit.block.Block;
|
|
|
|
|
|
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
|
|
|
|
import com.gmail.nossr50.runnables.ChunkletUnloader;
|
|
|
|
|
import com.gmail.nossr50.util.blockmeta.ChunkletStore;
|
|
|
|
|
import com.gmail.nossr50.util.blockmeta.PrimitiveChunkletStore;
|
|
|
|
|
import com.gmail.nossr50.util.blockmeta.PrimitiveExChunkletStore;
|
|
|
|
|
import com.gmail.nossr50.util.blockmeta.HashChunkletManager;
|
|
|
|
|
|
|
|
|
|
import org.getspout.spoutapi.chunkstore.SimpleRegionFile;
|
|
|
|
|
import org.getspout.spoutapi.chunkstore.mcMMOSimpleRegionFile;
|
|
|
|
|
|
|
|
|
|
public class HashChunkManager implements ChunkManager {
|
|
|
|
|
private HashMap<UUID, HashMap<Long, SimpleRegionFile>> regionFiles = new HashMap<UUID, HashMap<Long, SimpleRegionFile>>();
|
|
|
|
|
private HashMap<UUID, HashMap<Long, mcMMOSimpleRegionFile>> regionFiles = new HashMap<UUID, HashMap<Long, mcMMOSimpleRegionFile>>();
|
|
|
|
|
public HashMap<String, ChunkStore> store = new HashMap<String, ChunkStore>();
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void closeAll() {
|
|
|
|
|
for (UUID uid : regionFiles.keySet()) {
|
|
|
|
|
HashMap<Long, SimpleRegionFile> worldRegions = regionFiles.get(uid);
|
|
|
|
|
Iterator<SimpleRegionFile> itr = worldRegions.values().iterator();
|
|
|
|
|
HashMap<Long, mcMMOSimpleRegionFile> worldRegions = regionFiles.get(uid);
|
|
|
|
|
Iterator<mcMMOSimpleRegionFile> itr = worldRegions.values().iterator();
|
|
|
|
|
while (itr.hasNext()) {
|
|
|
|
|
SimpleRegionFile rf = itr.next();
|
|
|
|
|
mcMMOSimpleRegionFile rf = itr.next();
|
|
|
|
|
if (rf != null) {
|
|
|
|
|
rf.close();
|
|
|
|
|
itr.remove();
|
|
|
|
@ -42,7 +46,7 @@ public class HashChunkManager implements ChunkManager {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ChunkStore readChunkStore(World world, int x, int z) throws IOException {
|
|
|
|
|
SimpleRegionFile rf = getSimpleRegionFile(world, x, z);
|
|
|
|
|
mcMMOSimpleRegionFile rf = getSimpleRegionFile(world, x, z);
|
|
|
|
|
InputStream in = rf.getInputStream(x, z);
|
|
|
|
|
if (in == null) {
|
|
|
|
|
return null;
|
|
|
|
@ -73,7 +77,7 @@ public class HashChunkManager implements ChunkManager {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
SimpleRegionFile rf = getSimpleRegionFile(world, x, z);
|
|
|
|
|
mcMMOSimpleRegionFile rf = getSimpleRegionFile(world, x, z);
|
|
|
|
|
ObjectOutputStream objectStream = new ObjectOutputStream(rf.getOutputStream(x, z));
|
|
|
|
|
objectStream.writeObject(data);
|
|
|
|
|
objectStream.flush();
|
|
|
|
@ -86,23 +90,23 @@ public class HashChunkManager implements ChunkManager {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void closeChunkStore(World world, int x, int z) {
|
|
|
|
|
SimpleRegionFile rf = getSimpleRegionFile(world, x, z);
|
|
|
|
|
mcMMOSimpleRegionFile rf = getSimpleRegionFile(world, x, z);
|
|
|
|
|
if (rf != null) {
|
|
|
|
|
rf.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SimpleRegionFile getSimpleRegionFile(World world, int x, int z) {
|
|
|
|
|
private mcMMOSimpleRegionFile getSimpleRegionFile(World world, int x, int z) {
|
|
|
|
|
File directory = new File(world.getWorldFolder(), "mcmmo_regions");
|
|
|
|
|
|
|
|
|
|
directory.mkdirs();
|
|
|
|
|
|
|
|
|
|
UUID key = world.getUID();
|
|
|
|
|
|
|
|
|
|
HashMap<Long, SimpleRegionFile> worldRegions = regionFiles.get(key);
|
|
|
|
|
HashMap<Long, mcMMOSimpleRegionFile> worldRegions = regionFiles.get(key);
|
|
|
|
|
|
|
|
|
|
if (worldRegions == null) {
|
|
|
|
|
worldRegions = new HashMap<Long, SimpleRegionFile>();
|
|
|
|
|
worldRegions = new HashMap<Long, mcMMOSimpleRegionFile>();
|
|
|
|
|
regionFiles.put(key, worldRegions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -111,11 +115,11 @@ public class HashChunkManager implements ChunkManager {
|
|
|
|
|
|
|
|
|
|
long key2 = (((long) rx) << 32) | (((long) rz) & 0xFFFFFFFFL);
|
|
|
|
|
|
|
|
|
|
SimpleRegionFile regionFile = worldRegions.get(key2);
|
|
|
|
|
mcMMOSimpleRegionFile regionFile = worldRegions.get(key2);
|
|
|
|
|
|
|
|
|
|
if (regionFile == null) {
|
|
|
|
|
File file = new File(directory, "mcmmo_" + rx + "_" + rz + "_.mcm");
|
|
|
|
|
regionFile = new SimpleRegionFile(file, rx, rz);
|
|
|
|
|
regionFile = new mcMMOSimpleRegionFile(file, rx, rz);
|
|
|
|
|
worldRegions.put(key2, regionFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -371,4 +375,90 @@ public class HashChunkManager implements ChunkManager {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void cleanUp() {}
|
|
|
|
|
|
|
|
|
|
public void convertChunk(File dataDir, int cx, int cz, World world) {
|
|
|
|
|
HashChunkletManager manager = new HashChunkletManager();
|
|
|
|
|
manager.loadChunk(cx, cz, world);
|
|
|
|
|
|
|
|
|
|
for(int y = 0; y < (world.getMaxHeight() / 64); y++) {
|
|
|
|
|
String chunkletName = world.getName() + "," + cx + "," + cz + "," + y;
|
|
|
|
|
ChunkletStore tempChunklet = manager.store.get(chunkletName);
|
|
|
|
|
PrimitiveChunkletStore primitiveChunklet = null;
|
|
|
|
|
PrimitiveExChunkletStore primitiveExChunklet = null;
|
|
|
|
|
if(tempChunklet instanceof PrimitiveChunkletStore)
|
|
|
|
|
primitiveChunklet = (PrimitiveChunkletStore) tempChunklet;
|
|
|
|
|
else if(tempChunklet instanceof PrimitiveExChunkletStore)
|
|
|
|
|
primitiveExChunklet = (PrimitiveExChunkletStore) tempChunklet;
|
|
|
|
|
if(tempChunklet == null) {
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
String chunkName = world.getName() + "," + cx + "," + cz;
|
|
|
|
|
PrimitiveChunkStore cChunk = (PrimitiveChunkStore) store.get(chunkName);
|
|
|
|
|
|
|
|
|
|
if(cChunk != null) {
|
|
|
|
|
int xPos = cx * 16;
|
|
|
|
|
int zPos = cz * 16;
|
|
|
|
|
|
|
|
|
|
for(int x = 0; x < 16; x++) {
|
|
|
|
|
for(int z = 0; z < 16; z++) {
|
|
|
|
|
int cxPos = xPos + x;
|
|
|
|
|
int czPos = zPos + z;
|
|
|
|
|
|
|
|
|
|
for(int y2 = (64 * y); y2 < (64 * y + 64); y2++) {
|
|
|
|
|
if(!manager.isTrue(cxPos, y2, czPos, world))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
setTrue(cxPos, y2, czPos, world);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setTrue(cx * 16, 0, cz * 16, world);
|
|
|
|
|
setFalse(cx * 16, 0, cz * 16, world);
|
|
|
|
|
cChunk = (PrimitiveChunkStore) store.get(chunkName);
|
|
|
|
|
|
|
|
|
|
for(int x = 0; x < 16; x++) {
|
|
|
|
|
for(int z = 0; z < 16; z++) {
|
|
|
|
|
boolean[] oldArray;
|
|
|
|
|
if(primitiveChunklet != null)
|
|
|
|
|
oldArray = primitiveChunklet.store[x][z];
|
|
|
|
|
if(primitiveExChunklet != null)
|
|
|
|
|
oldArray = primitiveExChunklet.store[x][z];
|
|
|
|
|
else
|
|
|
|
|
return;
|
|
|
|
|
boolean[] newArray = cChunk.store[x][z];
|
|
|
|
|
if(oldArray.length < 64)
|
|
|
|
|
return;
|
|
|
|
|
else if(newArray.length < ((y * 64) + 64))
|
|
|
|
|
return;
|
|
|
|
|
System.arraycopy(oldArray, 0, newArray, (y * 64), 64);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
manager.unloadChunk(cx, cz, world);
|
|
|
|
|
unloadChunk(cx, cz, world);
|
|
|
|
|
|
|
|
|
|
File cxDir = new File(dataDir, "" + cx);
|
|
|
|
|
if(!cxDir.exists()) return;
|
|
|
|
|
File czDir = new File(cxDir, "" + cz);
|
|
|
|
|
if(!czDir.exists()) return;
|
|
|
|
|
|
|
|
|
|
for(File yFile : czDir.listFiles()) {
|
|
|
|
|
if(!yFile.exists())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
yFile.delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(czDir.listFiles().length <= 0)
|
|
|
|
|
czDir.delete();
|
|
|
|
|
if(cxDir.listFiles().length <= 0)
|
|
|
|
|
cxDir.delete();
|
|
|
|
|
if(dataDir.listFiles().length <= 0)
|
|
|
|
|
dataDir.delete();
|
|
|
|
|
}
|
|
|
|
|
}
|