update on my progress

This commit is contained in:
BuildTools 2016-11-23 18:46:52 -05:00
parent 7f67c7f6f9
commit 841ee979be
7 changed files with 99 additions and 79 deletions

View file

@ -4,16 +4,16 @@ import java.util.Set;
public class Cache {
static int maxNameLength;
static char[][] worldsFinished;
static char[][] worldsUnfinished;
static void set()
private static int maxNameLength;
private static char[][] worldsUnfinished;
static class WorldStatus {
}
static void updateListUnfinished()
{
Set<String> fin = Main.config.getConfigurationSection("finished worlds").getKeys(false);
Set<String> unfin = Main.config.getConfigurationSection("unfinished worlds").getKeys(false);
maxNameLength = Main.config.getInt("max name length");
worldsFinished = populate(fin);
worldsUnfinished = populate(unfin);
}
static char[][] populate(Set<String> set)
@ -33,21 +33,6 @@ public class Cache {
}
return worlds;
}
static boolean isFinished(String name){
int i = 0;
boolean match = true;
for (char[] world : worldsFinished)
{
for (char c : name.toCharArray())
{
if (c != world[i]){ match = false; break; }
}
if (match) break;
i = 0;
match = true;
}
return match;
}
static boolean isUnfinished(String name){
int i = 0;
boolean match = true;

View file

@ -1,5 +0,0 @@
package iieLoadSaveEntireWorld;
public class ConfirmCommand {
}

View file

@ -33,9 +33,11 @@ public class Dimensions {
);
width = regionBounds[2] - regionBounds[0];
center = regionCenter(regionBounds);
lowerleft[0] = regionBounds[0];
lowerleft[1] = regionBounds[2];
lowerleft = new int[]
{
regionBounds[0],
regionBounds[2]
};
}
private static boolean isInt(String arg)
@ -65,8 +67,8 @@ public class Dimensions {
}
private static int[] blockCenter(String arg1, String arg2)
{
int xBlock = isInt(arg1) ? Integer.parseInt(arg1) : 0;
int zBlock = isInt(arg2) ? Integer.parseInt(arg2) : 0;
int xBlock = isInt(arg1) ? Integer.parseInt(arg1) : defaultDimensions[0][1];
int zBlock = isInt(arg2) ? Integer.parseInt(arg2) : defaultDimensions[0][2];
return new int[] {xBlock,zBlock};
}
private static int[] blockBounds(int[] center, int blockRadius)

View file

@ -17,23 +17,62 @@ public class LoadSaveProcess implements Runnable {
private static int[] currentRegion;
private static int totalRegions;
private static int untilNextProgSave;
private static int untilSaveProg;
LoadSaveProcess(int width, int[] center, int[] lowerleft, String worldName)
//===============================CONTROLS===============================
static void start(int width, int[] center, int[] lowerleft, String name)
{
world = Bukkit.getWorld(worldName);
LoadSaveProcess.worldName = worldName;
currentRegion = center;
totalRegions = width*width;
untilNextProgSave = 10;
Map.init(width, lowerleft);
world = Bukkit.getWorld(worldName);
worldName = name;
currentRegion = center;
totalRegions = width*width;
untilSaveProg = 9;
}
public static void resume(String name)
{
String path = "unfinishedWorlds." + name + ".";
int width = Main.config.getInt(path + "width");
int[] center = new int[]
{
Main.config.getInt(path + "center.x"),
Main.config.getInt(path + "center.z")
};
int[] lowerleft = new int[]
{
Main.config.getInt(path + "lowerleft.x"),
Main.config.getInt(path + "lowerleft.z")
};
currentRegion = new int[]
{
Main.config.getInt(path + "currentRegion.x"),
Main.config.getInt(path + "currentRegion.z")
};
totalRegions = Main.config.getInt(path + "width");
Map.init(w, lowerleft);
SavePattern.n = Main.config.getInt(path + "n");
SavePattern.D = Main.config.getInt(path + "D");
SavePattern.d = Main.config.getInt(path + "d");
SavePattern.B = Main.config.getBoolean(path + "B");
}
public static void saveProgress()
{
String path = "unfinishedWorlds." + worldName + ".";
Main.config.set(path + "currentRegion.x", currentRegion[0]);
Main.config.set(path + "currentRegion.z", currentRegion[1]);
Main.config.set(path + "n", SavePattern.n);
Main.config.set(path + "D", SavePattern.D);
Main.config.set(path + "d", SavePattern.d);
Main.config.set(path + "B", SavePattern.B);
Main.plugin.saveConfig();
}
public static void stop()
{
saveProgress();
SavePattern.reset();
int length = worldName.length();
if (length > Cache.maxNameLength)
Main.config.set("max namelength",length);
Main.config.set("unfinished worlds." + worldName + ".width", width);
Cache.set();
}
@ -154,40 +193,28 @@ public class LoadSaveProcess implements Runnable {
{
if (taskRunning) return;
else taskRunning = true;
int[][][] r = Map.getChunksCurrentRegion();
for (int[][] xRow : r)
for (int[] chunk : xRow){
{
for (int[] chunk : xRow)
{
world.loadChunk(chunk[0], chunk[1], true);
world.unloadChunk(chunk[0], chunk[1]);
}
SavePattern.setNextRegion();
}
//===============================CONTROLS===============================
public static void saveProgress()
{
String path = "unfinishedWorlds." + worldName + ".";
Main.config.set(path + "current region.x", currentRegion[0]);
Main.config.set(path + "current region.z", currentRegion[1]);
Main.config.set(path + "n", SavePattern.n);
Main.config.set(path + "D", SavePattern.D);
Main.config.set(path + "d", SavePattern.d);
Main.config.set(path + "B", SavePattern.B);
Main.plugin.saveConfig();
}
public void stop()
{
saveProgress();
SavePattern.reset();
try {
wait(30000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void resume(String worldName)
{
String path = "unfinishedWorlds." + worldName + ".";
SavePattern.setNextRegion();
if (SavePattern.complete())
{
}
if (untilSaveProg == 0)
{
untilSaveProg = 9;
saveProgress();
}else
untilSaveProg--;
}
}

View file

@ -9,7 +9,8 @@ public class Main extends JavaPlugin {
static Main plugin;
static FileConfiguration config;
static StartCommand start;
static LoadSaveProcess process;
static StopCommand stop;
static BukkitTask task;
public void onEnable()
@ -17,10 +18,11 @@ public class Main extends JavaPlugin {
plugin = this;
config = plugin.getConfig();
start = new StartCommand(plugin);
stop = new StopCommand(plugin);
saveDefaultConfig();
getCommand("beginloadsave").setExecutor(start);
getCommand("stoploadsave").setExecutor(new StopCommand(plugin));
Cache.set();
getCommand("stoploadsave").setExecutor(stop);
Cache.updateListUnfinished();
}
}

View file

@ -22,6 +22,8 @@ public class StartCommand implements CommandExecutor {
return false;
}
else LoadSaveProcess.inProgress = true;
if ((Cache.isUnfinished(worldName)))
{
sender.sendMessage("resuming...");
@ -30,8 +32,10 @@ public class StartCommand implements CommandExecutor {
else
{
Dimensions d = new Dimensions(args);
Main.process = new LoadSaveProcess( d.width, d.center, d.lowerleft, worldName );
LoadSaveProcess.start( d.width, d.center, d.lowerleft, worldName );
}
Main.task = Bukkit.getScheduler().runTaskTimer( plugin, Main.process, 0, 100 );
return true;
}

View file

@ -11,8 +11,13 @@ public class StopCommand implements CommandExecutor{
plugin = Plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command label, String command, String[] args) {
if (LoadSaveProcess.inProgress) Main.process.stop();
return false;
public synchronized boolean onCommand(CommandSender sender, Command label, String command, String[] args) {
if (LoadSaveProcess.inProgress)
{
LoadSaveProcess.stop();
return true;
}
else
return false;
}
}