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 {
//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)
{
if(config == null)
config = Main.getPlugin().getConfig();
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)
{
if(config == null)
config = Main.getPlugin().getConfig();
return new WorldObject
(
config.getInt(name + ".width"),
@ -44,29 +55,28 @@ public class ConfigProcess implements Runnable {
private final String name = TaskManager.loadProcess.worldname;
public final void run()
{
if(config == null)
config = Main.getPlugin().getConfig();
Bukkit.getLogger().info("Loading in progress: " + name
+ "[" + TaskManager.loadProcess.currentRegion[0] + ","
+ TaskManager.loadProcess.currentRegion[1] + "]");
config.set(name + ".width", TaskManager.loadProcess.width);
config.set(name + ".lowerleft.x", TaskManager.loadProcess.lowerleft[0]);
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]);
final int[] currentRegion = TaskManager.loadProcess.currentRegion;
Bukkit.getLogger().info
(
"Saving world-load progress: " + name
+ "["
+ currentRegion[0] + ","
+ 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 + ".c", TaskManager.loadProcess.c);
config.set(name + ".D", TaskManager.loadProcess.D);
config.set(name + ".d", TaskManager.loadProcess.d);
config.set(name + ".B", TaskManager.loadProcess.B ? 1 : 0);
Main.getPlugin().saveConfig();
plugin.saveConfig();
}
final void finish()
{
if(config == null)
config = Main.getPlugin().getConfig();
config.set("finished", name);
config.set(name, null);
Main.getPlugin().saveConfig();
plugin.saveConfig();
}
}

View file

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

View file

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

View file

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