Updating modified block storage to a region-style format.

This commit is contained in:
Glitchfinder
2012-11-04 13:36:57 -08:00
parent d532164cd6
commit eb5ac80714
19 changed files with 1669 additions and 11 deletions

View File

@ -0,0 +1,90 @@
package com.gmail.nossr50.runnables;
import java.io.File;
import java.lang.Runnable;
import org.bukkit.scheduler.BukkitScheduler;
import com.gmail.nossr50.config.HiddenConfig;
import com.gmail.nossr50.mcMMO;
public class BlockStoreConversionMain implements Runnable {
private int taskID, i;
private org.bukkit.World world;
BukkitScheduler scheduler;
File dataDir;
File[] xDirs;
BlockStoreConversionXDirectory[] converters;
public BlockStoreConversionMain(org.bukkit.World world) {
this.taskID = -1;
this.world = world;
this.scheduler = mcMMO.p.getServer().getScheduler();
this.dataDir = new File(this.world.getWorldFolder(), "mcmmo_data");
this.converters = new BlockStoreConversionXDirectory[HiddenConfig.getInstance().getConversionRate()];
}
public void start() {
if(this.taskID >= 0)
return;
this.taskID = this.scheduler.scheduleSyncDelayedTask(mcMMO.p, this, 1);
return;
}
public void run() {
if(!this.dataDir.exists()) {
softStop();
return;
}
if(!this.dataDir.isDirectory()) {
this.dataDir.delete();
softStop();
return;
}
if(this.dataDir.listFiles().length <= 0) {
this.dataDir.delete();
softStop();
return;
}
this.xDirs = this.dataDir.listFiles();
for (this.i = 0; (this.i < HiddenConfig.getInstance().getConversionRate()) && (this.i < this.xDirs.length); this.i++) {
if(this.converters[this.i] == null)
this.converters[this.i] = new BlockStoreConversionXDirectory();
this.converters[this.i].start(this.world, this.xDirs[this.i]);
}
softStop();
}
public void stop() {
if(this.taskID < 0)
return;
this.scheduler.cancelTask(this.taskID);
this.taskID = -1;
}
public void softStop() {
stop();
if(this.dataDir.exists() || this.dataDir.isDirectory()) {
start();
return;
}
mcMMO.p.getLogger().info("Finished converting the storage for " + world.getName() + ".");
this.dataDir = null;
this.xDirs = null;
this.world = null;
this.scheduler = null;
this.converters = null;
return;
}
}

View File

@ -0,0 +1,79 @@
package com.gmail.nossr50.runnables;
import java.io.File;
import java.lang.Runnable;
import org.bukkit.scheduler.BukkitScheduler;
import com.gmail.nossr50.config.HiddenConfig;
import com.gmail.nossr50.mcMMO;
public class BlockStoreConversionXDirectory implements Runnable {
private int taskID, i;
private org.bukkit.World world;
BukkitScheduler scheduler;
File dataDir;
File[] zDirs;
BlockStoreConversionZDirectory[] converters;
public BlockStoreConversionXDirectory() {
this.taskID = -1;
}
public void start(org.bukkit.World world, File dataDir) {
this.world = world;
this.scheduler = mcMMO.p.getServer().getScheduler();
this.converters = new BlockStoreConversionZDirectory[HiddenConfig.getInstance().getConversionRate()];
this.dataDir = dataDir;
if(this.taskID >= 0)
return;
this.taskID = this.scheduler.scheduleSyncDelayedTask(mcMMO.p, this, 1);
return;
}
public void run() {
if(!this.dataDir.exists()) {
stop();
return;
}
if(!this.dataDir.isDirectory()) {
this.dataDir.delete();
stop();
return;
}
if(this.dataDir.listFiles().length <= 0) {
this.dataDir.delete();
stop();
return;
}
this.zDirs = this.dataDir.listFiles();
for (this.i = 0; (this.i < HiddenConfig.getInstance().getConversionRate()) && (this.i < this.zDirs.length); this.i++) {
if(this.converters[this.i] == null)
this.converters[this.i] = new BlockStoreConversionZDirectory();
this.converters[this.i].start(this.world, this.dataDir, this.zDirs[this.i]);
}
stop();
}
public void stop() {
if(this.taskID < 0)
return;
this.scheduler.cancelTask(this.taskID);
this.taskID = -1;
this.dataDir = null;
this.zDirs = null;
this.world = null;
this.scheduler = null;
this.converters = null;
}
}

View File

@ -0,0 +1,154 @@
package com.gmail.nossr50.runnables;
import java.io.File;
import java.lang.Runnable;
import java.lang.String;
import org.bukkit.scheduler.BukkitScheduler;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.blockmeta.PrimitiveExChunkletStore;
import com.gmail.nossr50.util.blockmeta.PrimitiveChunkStore;
import com.gmail.nossr50.util.blockmeta.HashChunkletManager;
import com.gmail.nossr50.util.blockmeta.HashChunkManager;
public class BlockStoreConversionZDirectory implements Runnable {
private int taskID, cx, cz, x, y, z, y2, xPos, zPos, cxPos, czPos;
private String cxs, czs, chunkletName, chunkName;
private org.bukkit.World world;
private BukkitScheduler scheduler;
private File xDir, dataDir;
private HashChunkletManager manager;
private HashChunkManager newManager;
private PrimitiveExChunkletStore currentChunklet;
private PrimitiveChunkStore currentChunk;
private boolean[] oldArray, newArray;
public BlockStoreConversionZDirectory() {
this.taskID = -1;
}
public void start(org.bukkit.World world, File xDir, File dataDir) {
this.world = world;
this.scheduler = mcMMO.p.getServer().getScheduler();
this.manager = new HashChunkletManager();
this.newManager = (HashChunkManager) mcMMO.p.placeStore;
this.dataDir = dataDir;
this.xDir = xDir;
if(this.taskID >= 0)
return;
this.taskID = this.scheduler.scheduleSyncDelayedTask(mcMMO.p, this, 1);
return;
}
public void run() {
if(!this.dataDir.exists()) {
stop();
return;
}
if(!this.dataDir.isDirectory()) {
this.dataDir.delete();
stop();
return;
}
if(this.dataDir.listFiles().length <= 0) {
this.dataDir.delete();
stop();
return;
}
this.cxs = this.xDir.getName();
this.czs = this.dataDir.getName();
this.cx = 0;
this.cz = 0;
try {
this.cx = Integer.parseInt(this.cxs);
this.cz = Integer.parseInt(this.czs);
}
catch(Exception e) {
this.dataDir.delete();
stop();
return;
}
this.manager.loadChunk(this.cx, this.cz, this.world);
for(this.y = 0; this.y < 4; this.y++) {
this.chunkletName = this.world.getName() + "," + this.cx + "," + this.cz + "," + this.y;
this.currentChunklet = (PrimitiveExChunkletStore) this.manager.store.get(this.chunkletName);
if(this.currentChunklet == null) {
continue;
} else {
this.chunkName = this.world.getName() + "," + this.cx + "," + this.cz;
this.currentChunk = (PrimitiveChunkStore) this.newManager.store.get(this.chunkName);
if(this.currentChunk != null) {
this.xPos = this.cx * 16;
this.zPos = this.cz * 16;
for(this.x = 0; this.x < 16; this.x++) {
for(this.z = 0; this.z < 16; this.z++) {
this.cxPos = this.xPos + this.x;
this.czPos = this.zPos + this.z;
for(this.y2 = (64 * this.y); this.y2 < (64 * this.y + 64); this.y2++) {
if(!this.manager.isTrue(this.cxPos, this.y2, this.czPos, this.world))
continue;
this.newManager.setTrue(this.cxPos, this.y2, this.czPos, this.world);
}
}
}
continue;
}
this.newManager.setTrue(this.cx * 16, 0, this.cz * 16, this.world);
this.newManager.setFalse(this.cx * 16, 0, this.cz * 16, this.world);
this.currentChunk = (PrimitiveChunkStore) this.newManager.store.get(this.chunkName);
for(this.x = 0; this.x < 16; this.x++) {
for(this.z = 0; this.z < 16; this.z++) {
this.oldArray = this.currentChunklet.store[x][z];
this.newArray = this.currentChunk.store[x][z];
System.arraycopy(this.oldArray, 0, this.newArray, (this.y * 64), 64);
}
}
}
}
this.manager.unloadChunk(this.cx, this.cz, this.world);
this.newManager.unloadChunk(this.cx, this.cz, this.world);
for(File yFile : dataDir.listFiles()) {
if(!yFile.exists())
continue;
yFile.delete();
}
stop();
}
public void stop() {
if(this.taskID < 0)
return;
this.scheduler.cancelTask(taskID);
this.taskID = -1;
this.cxs = null;
this.czs = null;
this.chunkletName = null;
this.chunkName = null;
this.manager = null;
this.xDir = null;
this.dataDir = null;
this.currentChunklet = null;
this.currentChunk = null;
}
}