I think everything is fixed

This commit is contained in:
BuildTools 2016-11-26 20:15:40 -05:00
parent 4609e3fc3c
commit fea4e41927
4 changed files with 51 additions and 38 deletions

View file

@ -6,18 +6,29 @@ import org.bukkit.configuration.file.FileConfiguration;
public class ConfigProcess implements Runnable { public class ConfigProcess implements Runnable {
//STATIC //STATIC
private static FileConfiguration config; private static final Main plugin = new Main();
private static final FileConfiguration config = plugin.getConfig();
static final boolean isNew(String name) static final boolean isNew(String name)
{ {
if(config == null)
config = Main.getPlugin().getConfig();
return !config.contains(name); return !config.contains(name);
} }
static final void addNew(String name, int width, int[] lowerleft, int[] center)
{
config.set(name + ".width", width);
config.set(name + ".lowerleft.x", lowerleft[0]);
config.set(name + ".lowerleft.z", lowerleft[1]);
config.set(name + ".currentRegion.x", center[0]);
config.set(name + ".currentRegion.z", center[1]);
config.set(name + ".n", 1);
config.set(name + ".c", 1);
config.set(name + ".D", 1);
config.set(name + ".d", 0);
config.set(name + ".B", 0);
plugin.saveConfig();
}
static final WorldObject getUnfinished(String name) static final WorldObject getUnfinished(String name)
{ {
if(config == null)
config = Main.getPlugin().getConfig();
return new WorldObject return new WorldObject
( (
config.getInt(name + ".width"), config.getInt(name + ".width"),
@ -44,29 +55,28 @@ public class ConfigProcess implements Runnable {
private final String name = TaskManager.loadProcess.worldname; private final String name = TaskManager.loadProcess.worldname;
public final void run() public final void run()
{ {
if(config == null) final int[] currentRegion = TaskManager.loadProcess.currentRegion;
config = Main.getPlugin().getConfig(); Bukkit.getLogger().info
Bukkit.getLogger().info("Loading in progress: " + name (
+ "[" + TaskManager.loadProcess.currentRegion[0] + "," "Saving world-load progress: " + name
+ TaskManager.loadProcess.currentRegion[1] + "]"); + "["
config.set(name + ".width", TaskManager.loadProcess.width); + currentRegion[0] + ","
config.set(name + ".lowerleft.x", TaskManager.loadProcess.lowerleft[0]); + currentRegion[1]
config.set(name + ".lowerleft.z", TaskManager.loadProcess.lowerleft[1]); + "]"
config.set(name + ".currentRegion.x", TaskManager.loadProcess.currentRegion[0]); );
config.set(name + ".currentRegion.z", TaskManager.loadProcess.currentRegion[1]); config.set(name + ".currentRegion.x", currentRegion[0]);
config.set(name + ".currentRegion.z", currentRegion[1]);
config.set(name + ".n", TaskManager.loadProcess.n); config.set(name + ".n", TaskManager.loadProcess.n);
config.set(name + ".c", TaskManager.loadProcess.c); config.set(name + ".c", TaskManager.loadProcess.c);
config.set(name + ".D", TaskManager.loadProcess.D); config.set(name + ".D", TaskManager.loadProcess.D);
config.set(name + ".d", TaskManager.loadProcess.d); config.set(name + ".d", TaskManager.loadProcess.d);
config.set(name + ".B", TaskManager.loadProcess.B ? 1 : 0); config.set(name + ".B", TaskManager.loadProcess.B ? 1 : 0);
Main.getPlugin().saveConfig(); plugin.saveConfig();
} }
final void finish() final void finish()
{ {
if(config == null)
config = Main.getPlugin().getConfig();
config.set("finished", name); config.set("finished", name);
config.set(name, null); config.set(name, null);
Main.getPlugin().saveConfig(); plugin.saveConfig();
} }
} }

View file

@ -11,7 +11,6 @@ public class LoadProcess implements Runnable
final String worldname; final String worldname;
final int totalRegions; final int totalRegions;
int[] currentRegion; int[] currentRegion;
int width;
LoadProcess(String name, WorldObject newWorld) LoadProcess(String name, WorldObject newWorld)
@ -23,7 +22,6 @@ public class LoadProcess implements Runnable
currentRegion = newWorld.current; currentRegion = newWorld.current;
this.lowerleft = newWorld.lowerleft; this.lowerleft = newWorld.lowerleft;
width = newWorld.width;
allChunkCoords = generateAllChunkCoords(newWorld.width, newWorld.lowerleft); allChunkCoords = generateAllChunkCoords(newWorld.width, newWorld.lowerleft);
} }
LoadProcess(String name) LoadProcess(String name)
@ -37,7 +35,6 @@ public class LoadProcess implements Runnable
currentRegion = unfinished.current; currentRegion = unfinished.current;
this.lowerleft = unfinished.lowerleft; this.lowerleft = unfinished.lowerleft;
width = unfinished.width;
allChunkCoords = generateAllChunkCoords(unfinished.width, unfinished.lowerleft); allChunkCoords = generateAllChunkCoords(unfinished.width, unfinished.lowerleft);
this.n = unfinished.n; this.n = unfinished.n;
@ -72,7 +69,7 @@ public class LoadProcess implements Runnable
int c = 1; //direction of travel: E,N,W,S - 1,2,3,4 int c = 1; //direction of travel: E,N,W,S - 1,2,3,4
int D = 1; //distance to travel int D = 1; //distance to travel
int d = 0; //distance already traveled int d = 0; //distance already traveled
boolean B = false; //OK to change direction? boolean B = false; //OK to increase distance?
private final void setNextRegion() private final void setNextRegion()
{ {
@ -81,14 +78,14 @@ public class LoadProcess implements Runnable
else else
{ {
d = 0; d = 0;
D++; if (B) D++;
switch (c){ switch (c){
case 1 : currentRegion[0]++; break; case 1 : currentRegion[0]++; break;
case 2 : currentRegion[1]++; break; case 2 : currentRegion[1]++; break;
case 3 : currentRegion[0]--; break; case 3 : currentRegion[0]--; break;
case 4 : case 4 :
currentRegion[1]--; currentRegion[1]--;
c = B ? 1 : c + 1; c = c == 4 ? 1 : c + 1;
break; break;
} }
B = !B; B = !B;
@ -102,7 +99,7 @@ public class LoadProcess implements Runnable
//===============================CHUNK MAP============================== //===============================CHUNK MAP==============================
final int[] lowerleft; private final int[] lowerleft;
private final int[][][][][] allChunkCoords; private final int[][][][][] allChunkCoords;
private final int[][][][][] generateAllChunkCoords(int w,int[] lowerleft) private final int[][][][][] generateAllChunkCoords(int w,int[] lowerleft)
{ {
@ -152,7 +149,7 @@ public class LoadProcess implements Runnable
//==================================RUN================================= //==================================RUN=================================
boolean ready = true; private boolean ready = true;
public final void run() public final void run()
{ {
if (!ready) return; if (!ready) return;

View file

@ -15,19 +15,29 @@ public class TaskManager {
static BukkitTask configTask; static BukkitTask configTask;
//===================================CONTROLS=================================== //===================================CONTROLS===================================
private static final void start(LoadProcess loadProcess) private static final boolean start(String name, String[] args)
{ {
inProgress = true; final boolean isNew;
TaskManager.loadProcess = loadProcess; if (ConfigProcess.isNew(name))
{
loadProcess = new LoadProcess(name, WorldObject.generate(args));
isNew = true;
}
else
{
loadProcess = new LoadProcess(name);
isNew = false;
}
TaskManager.configProcess = new ConfigProcess(); TaskManager.configProcess = new ConfigProcess();
TaskManager.loadTask = Bukkit.getScheduler().runTaskTimer( Main.getPlugin(), loadProcess, 0, 10 ); TaskManager.loadTask = Bukkit.getScheduler().runTaskTimer( Main.getPlugin(), loadProcess, 0, 10 );
TaskManager.configTask = Bukkit.getScheduler().runTaskTimer( Main.getPlugin(), configProcess, 0, 200 ); TaskManager.configTask = Bukkit.getScheduler().runTaskTimer( Main.getPlugin(), configProcess, 0, 200 );
return isNew;
} }
static final void finish() static final void finish()
{ {
configProcess.finish();
loadTask.cancel(); loadTask.cancel();
configTask.cancel(); configTask.cancel();
configProcess.finish();
loadProcess = null; loadProcess = null;
configProcess = null; configProcess = null;
@ -67,23 +77,19 @@ public class TaskManager {
@Override @Override
public final boolean onCommand(CommandSender sender, Command label, String command, String[] args) public final boolean onCommand(CommandSender sender, Command label, String command, String[] args)
{ {
String name = ((Player)sender).getWorld().getName();
if (inProgress) if (inProgress)
{ {
sender.sendMessage("a process is already running (" + name + "). /StopLoadSave to stop."); sender.sendMessage("a process is already running (" + loadProcess.worldname + "). /StopLoadSave to stop.");
return false; return false;
} }
else inProgress = true; else inProgress = true;
if (start(((Player)sender).getWorld().getName(),args))
if (ConfigProcess.isNew(name))
{ {
sender.sendMessage("starting..."); sender.sendMessage("starting...");
start(new LoadProcess(name, WorldObject.generate(args)));
} }
else else
{ {
sender.sendMessage("resuming..."); sender.sendMessage("resuming...");
start(new LoadProcess(name));
} }
return true; return true;
} }

View file

@ -1,4 +1,4 @@
package iieLoadSaveEntireWorld; package unused;
import org.bukkit.Location; import org.bukkit.Location;