made LoadSaveProcess non-static, mostly
This commit is contained in:
parent
f978862cfa
commit
fb3f2a1cb6
4 changed files with 177 additions and 164 deletions
|
@ -8,41 +8,102 @@ public class Cache {
|
|||
|
||||
private static int maxNameLength;
|
||||
private static char[][] listUnfinished;
|
||||
private static Map<String,WorldStatus> cacheWorldStatus;
|
||||
private static Map<String,WorldStatus> cacheUnfinished;
|
||||
|
||||
//PRIVATE METHODS===============================
|
||||
private static char[][] populate(Set<String> set)
|
||||
static final class WorldStatus {
|
||||
final int width;
|
||||
final int[] lowerleft;
|
||||
int[] currentRegion;
|
||||
int n = 1;
|
||||
int c = 1;
|
||||
int D = 1;
|
||||
int d = 0;
|
||||
boolean B = false;
|
||||
WorldStatus(int width, int[] lowerleft, int[]center)
|
||||
{
|
||||
char[][] worlds = new char[set.size()][maxNameLength];
|
||||
this.width = width;
|
||||
this.lowerleft = lowerleft;
|
||||
currentRegion = center;
|
||||
}
|
||||
WorldStatus(
|
||||
int width, int[] lowerleft,
|
||||
int[] current, int n, int c, int D, int d, boolean B
|
||||
)
|
||||
{
|
||||
this.width = width;
|
||||
this.lowerleft = lowerleft;
|
||||
currentRegion = current;
|
||||
this.n = n;
|
||||
this.c = c;
|
||||
this.D = D;
|
||||
this.d = d;
|
||||
this.B = B;
|
||||
}
|
||||
}
|
||||
private static void populateList(Set<String> set)
|
||||
{
|
||||
char[][] listUnfinished = new char[set.size()][maxNameLength];
|
||||
int i = 0;
|
||||
int ii = 0;
|
||||
for (String name : set)
|
||||
{
|
||||
for (char c : name.toCharArray())
|
||||
{
|
||||
worlds[i][ii] = c;
|
||||
listUnfinished[i][ii] = c;
|
||||
ii++;
|
||||
}
|
||||
i++;
|
||||
ii = 0;
|
||||
}
|
||||
return worlds;
|
||||
}
|
||||
private static void cache()
|
||||
private static void populateCache(Set<String> set)
|
||||
{
|
||||
String path;
|
||||
int width;
|
||||
int[] lowerleft;
|
||||
int[] current;
|
||||
int n; int c; int D; int d; boolean B;
|
||||
|
||||
for (String name : set){
|
||||
path = "unfinishedWorlds." + name + ".";
|
||||
|
||||
width = Main.config.getInt(path + "width");
|
||||
lowerleft = new int[]{
|
||||
Main.config.getInt(path + "lowerleft.x"),
|
||||
Main.config.getInt(path + "lowerleft.z")
|
||||
};
|
||||
current = new int[]{
|
||||
Main.config.getInt(path + "currentRegion.x"),
|
||||
Main.config.getInt(path + "currentRegion.z")
|
||||
};
|
||||
n = Main.config.getInt(path + "n");
|
||||
c = Main.config.getInt(path + "c");
|
||||
D = Main.config.getInt(path + "D");
|
||||
d = Main.config.getInt(path + "d");
|
||||
B = Main.config.getBoolean(path + "B");
|
||||
cacheUnfinished.put(name, new WorldStatus( width,lowerleft,current,n,c,D,d,B ));
|
||||
}
|
||||
}
|
||||
|
||||
//PUBLIC METHODS================================
|
||||
//================================PUBLIC METHODS================================
|
||||
static void generate()
|
||||
{
|
||||
maxNameLength = Main.config.getInt("max name length");
|
||||
listUnfinished = populate(Main.unfinished.getKeys(false));
|
||||
cache();
|
||||
Set<String> set = Main.unfinished.getKeys(false);
|
||||
populateList(set);
|
||||
populateCache(set);
|
||||
}
|
||||
static void saveProgress()
|
||||
{
|
||||
|
||||
}
|
||||
static void finish(String name)
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
static void addUnfinished(int width, int[] center, int[] lowerleft, String name)
|
||||
{
|
||||
|
||||
}
|
||||
static boolean isUnfinished(String name){
|
||||
int i = 0;
|
||||
|
@ -59,21 +120,4 @@ public class Cache {
|
|||
}
|
||||
return match;
|
||||
}
|
||||
static void addUnfinished(int width, int[] center, int[] lowerleft, String name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static final class WorldStatus {
|
||||
int width;
|
||||
int[] center;
|
||||
int[] lowerleft;
|
||||
int[] currentRegion;
|
||||
|
||||
int n;
|
||||
int D;
|
||||
int d;
|
||||
boolean B;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,84 +2,70 @@ package iieLoadSaveEntireWorld;
|
|||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class LoadSaveProcess implements Runnable {
|
||||
|
||||
//=================================INIT=================================
|
||||
static boolean processOngoing = false;
|
||||
static LoadSaveProcess process;
|
||||
static BukkitTask bukkitTask;
|
||||
|
||||
//=============================STATIC FIELDS============================
|
||||
boolean ready = true;
|
||||
final Map map;
|
||||
final World world;
|
||||
final String worldname;
|
||||
final int totalRegions;
|
||||
int[] currentRegion;
|
||||
|
||||
static boolean inProgress = false;
|
||||
static boolean taskRunning = false;
|
||||
LoadSaveProcess(
|
||||
String name, int width, int[] center, int[] lowerleft
|
||||
)
|
||||
{
|
||||
map = new Map(width, lowerleft);
|
||||
world = Bukkit.getWorld(name);
|
||||
worldname = name;
|
||||
totalRegions = width*width;
|
||||
currentRegion = center;
|
||||
}
|
||||
LoadSaveProcess(
|
||||
String name, int width, int[] lowerleft,
|
||||
int[] current, int n, int c, int D, int d, boolean B
|
||||
)
|
||||
{
|
||||
map = new Map(width, lowerleft);
|
||||
world = Bukkit.getWorld(name);
|
||||
worldname = name;
|
||||
totalRegions = width*width;
|
||||
currentRegion = current;
|
||||
this.n = n;
|
||||
this.c = c;
|
||||
this.D = D;
|
||||
this.d = d;
|
||||
this.B = B;
|
||||
}
|
||||
|
||||
private static World world;
|
||||
private static String worldName;
|
||||
|
||||
private static int[] currentRegion;
|
||||
private static int totalRegions;
|
||||
|
||||
private static int untilSaveProg;
|
||||
|
||||
//===============================CONTROLS===============================
|
||||
static void start(int width, int[] center, int[] lowerleft, String name)
|
||||
static void start(String name)
|
||||
{
|
||||
Map.init(width, lowerleft);
|
||||
world = Bukkit.getWorld(worldName);
|
||||
worldName = name;
|
||||
currentRegion = center;
|
||||
totalRegions = width*width;
|
||||
untilSaveProg = 9;
|
||||
}
|
||||
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");
|
||||
}
|
||||
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();
|
||||
}
|
||||
static void stop()
|
||||
{
|
||||
saveProgress();
|
||||
SavePattern.reset();
|
||||
|
||||
//TODO
|
||||
}
|
||||
static void finish()
|
||||
{
|
||||
bukkitTask.cancel();
|
||||
process = null;
|
||||
System.gc();
|
||||
processOngoing = false;
|
||||
}
|
||||
|
||||
|
||||
//===============================PATTERN================================
|
||||
|
||||
static final class SavePattern {
|
||||
|
||||
/* The pattern:
|
||||
*
|
||||
* 3 | 36 35 34 33 32 31
|
||||
|
@ -98,19 +84,13 @@ public class LoadSaveProcess implements Runnable {
|
|||
* etc.
|
||||
*/
|
||||
|
||||
static int n = 1; //number
|
||||
static int c = 1; //direction of travel: E,N,W,S - 1,2,3,4
|
||||
static int D = 1; //distance to travel
|
||||
static int d = 0; //distance already traveled
|
||||
static boolean B = false; //OK to change direction?
|
||||
static void reset()
|
||||
{
|
||||
c = 1;
|
||||
D = 1;
|
||||
d = 0;
|
||||
B = false;
|
||||
}
|
||||
static void setNextRegion()
|
||||
int n = 1; //number
|
||||
int c = 1; //direction of travel: E,N,W,S - 1,2,3,4
|
||||
int D = 1; //distance to travel
|
||||
int d = 0; //distance already traveled
|
||||
boolean B = false; //OK to change direction?
|
||||
|
||||
private void setNextRegion()
|
||||
{
|
||||
n++;
|
||||
if (d != D) d++;
|
||||
|
@ -129,9 +109,8 @@ public class LoadSaveProcess implements Runnable {
|
|||
B = !B;
|
||||
}
|
||||
}
|
||||
static boolean complete(){
|
||||
return n == totalRegions;
|
||||
}
|
||||
private boolean complete(){
|
||||
return n == process.totalRegions;
|
||||
}
|
||||
|
||||
|
||||
|
@ -139,11 +118,11 @@ public class LoadSaveProcess implements Runnable {
|
|||
|
||||
private static final class Map
|
||||
{
|
||||
private static int[] lowerleft;
|
||||
private static int[][][][][] allChunkCoords;
|
||||
static void init(int w,int[] lowerleft)
|
||||
private int[] lowerleft;
|
||||
private int[][][][][] allChunkCoords;
|
||||
Map(int w,int[] lowerleft)
|
||||
{
|
||||
Map.lowerleft = lowerleft;
|
||||
this.lowerleft = lowerleft;
|
||||
allChunkCoords = new int[w][w][32][32][2];
|
||||
|
||||
int regionX = lowerleft[0];
|
||||
|
@ -179,11 +158,11 @@ public class LoadSaveProcess implements Runnable {
|
|||
negX = regionX < 0;
|
||||
}
|
||||
}
|
||||
static int[][][] getChunksCurrentRegion(){
|
||||
int[][][] getChunksCurrentRegion(){
|
||||
return
|
||||
allChunkCoords
|
||||
[ currentRegion[0] - lowerleft[0] ]
|
||||
[ currentRegion[1] - lowerleft[1] ];
|
||||
[ process.currentRegion[0] - lowerleft[0] ]
|
||||
[ process.currentRegion[1] - lowerleft[1] ];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,10 +170,10 @@ public class LoadSaveProcess implements Runnable {
|
|||
//==================================RUN=================================
|
||||
public void run()
|
||||
{
|
||||
if (taskRunning) return;
|
||||
else taskRunning = true;
|
||||
if (!ready) return;
|
||||
else ready = false;
|
||||
|
||||
int[][][] r = Map.getChunksCurrentRegion();
|
||||
int[][][] r = map.getChunksCurrentRegion();
|
||||
for (int[][] xRow : r)
|
||||
{
|
||||
for (int[] chunk : xRow)
|
||||
|
@ -203,18 +182,9 @@ public class LoadSaveProcess implements Runnable {
|
|||
world.unloadChunk(chunk[0], chunk[1]);
|
||||
}
|
||||
}
|
||||
SavePattern.setNextRegion();
|
||||
if (SavePattern.complete())
|
||||
{
|
||||
setNextRegion();
|
||||
|
||||
if (complete()) finish();
|
||||
else ready = true;
|
||||
}
|
||||
if (untilSaveProg == 0)
|
||||
{
|
||||
untilSaveProg = 9;
|
||||
saveProgress();
|
||||
}else
|
||||
untilSaveProg--;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ public class Main extends JavaPlugin {
|
|||
unfinished = config.getConfigurationSection("unfinished worlds");
|
||||
start = new StartCommand(plugin);
|
||||
stop = new StopCommand(plugin);
|
||||
process = new LoadSaveProcess();
|
||||
|
||||
saveDefaultConfig();
|
||||
getCommand("beginloadsave").setExecutor(start);
|
||||
|
|
|
@ -7,8 +7,8 @@ import org.bukkit.command.CommandSender;
|
|||
public class StopCommand implements CommandExecutor{
|
||||
|
||||
private static Main plugin;
|
||||
StopCommand(Main Plugin){
|
||||
plugin = Plugin;
|
||||
StopCommand(Main plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@Override
|
||||
public synchronized boolean onCommand(CommandSender sender, Command label, String command, String[] args) {
|
||||
|
|
Loading…
Reference in a new issue