tidying up

This commit is contained in:
BuildTools 2016-12-05 01:47:13 -05:00
parent cf798914a7
commit 5687dc92c4
5 changed files with 70 additions and 56 deletions

View file

@ -58,10 +58,6 @@ public class ConfigProcess implements Runnable {
{ {
this.name = name; this.name = name;
config.set("@ CRASH RESUME", name); config.set("@ CRASH RESUME", name);
}
ConfigProcess(boolean b)
{
name = config.getString("@ CRASH RESUME");
} }
public final void run() public final void run()
{ {
@ -82,13 +78,6 @@ public class ConfigProcess implements Runnable {
+ "]" + "]"
); );
} }
final void finish()
{
config.set("@ FINISHED WORLDS", name);
config.set("@ CRASH RESUME", null);
config.set(name, null);
plugin.saveConfig();
}
final void stop() final void stop()
{ {
run(); run();
@ -97,4 +86,13 @@ public class ConfigProcess implements Runnable {
Bukkit.getLogger() Bukkit.getLogger()
.info("...stopping world-load"); .info("...stopping world-load");
} }
final void finish()
{
config.set("@ FINISHED WORLDS", name);
config.set("@ CRASH RESUME", null);
config.set(name, null);
plugin.saveConfig();
Bukkit.getLogger()
.info("...finished!");
}
} }

View file

@ -1,8 +1,5 @@
package iieLoadSaveEntireWorld; package iieLoadSaveEntireWorld;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;

View file

@ -24,7 +24,7 @@ public class Main extends JavaPlugin {
public final void run() public final void run()
{ {
Bukkit.getLogger().info("...resuming from crash"); Bukkit.getLogger().info("...resuming from crash");
TaskManager.start(null, ConfigProcess.getCrashResume()); TaskManager.resume(ConfigProcess.getCrashResume());
} }
} }
} }

View file

@ -17,15 +17,29 @@ public class TaskManager {
private static BukkitTask configTask; private static BukkitTask configTask;
//===================================CONTROLS================================== //=====================================UTIL====================================
private static final void schedule() private static final void schedule()
{ {
loadTask = Bukkit.getScheduler().runTaskTimer(ConfigProcess.plugin, loadProcess, 0, 200); loadTask = Bukkit.getScheduler().runTaskTimer(ConfigProcess.plugin, loadProcess, 0, 200);
configTask = Bukkit.getScheduler().runTaskTimer(ConfigProcess.plugin, configProcess, 0, 400); configTask = Bukkit.getScheduler().runTaskTimer(ConfigProcess.plugin, configProcess, 100, 200);
} }
//----------------------------------------------------------------------------- private static final void closedown()
static final boolean start(String[] args, String name) {
loadTask.cancel();
configTask.cancel();
loadProcess = null;
configProcess = null;
loadTask = null;
configTask = null;
inProgress = false;
}
//===================================CONTROLS==================================
private static final boolean start_or_resume(String[] args, String name)
{ {
boolean isNew; boolean isNew;
if (isNew = ConfigProcess.isNew(name)) if (isNew = ConfigProcess.isNew(name))
@ -40,36 +54,30 @@ public class TaskManager {
schedule(); schedule();
return isNew; return isNew;
} }
private static final void stop_or_finish() static final void resume(String name)
{ {
loadTask.cancel(); loadProcess = new LoadProcess(name);
configTask.cancel(); configProcess = new ConfigProcess(name);
schedule();
loadProcess = null; }
configProcess = null; private static final boolean stop_or_finish()
loadTask = null; {
configTask = null; boolean isFin;
if (isFin = loadProcess.n == loadProcess.totalRegions)
inProgress = false; {
configProcess.finish();
}
else
{
configProcess.stop();
}
closedown();
return isFin;
} }
static final void finish() static final void finish()
{ {
configProcess.finish(); configProcess.finish();
stop_or_finish(); closedown();
}
private static final boolean stop()
{
if (inProgress)
{
if (loadProcess.n == loadProcess.totalRegions) finish();
else
{
configProcess.stop();
stop_or_finish();
}
return true;
}
return false;
} }
//===================================COMMANDS=================================== //===================================COMMANDS===================================
@ -78,12 +86,16 @@ public class TaskManager {
{ {
public final boolean onCommand(CommandSender sender, Command label, String command, String[] args) public final boolean onCommand(CommandSender sender, Command label, String command, String[] args)
{ {
if (stop()) if (inProgress)
{ {
sender.sendMessage("stopped."); sender.sendMessage
(
stop_or_finish() ?
"it just finished!" :
"stopping..."
);
return true; return true;
} }
sender.sendMessage("nothing to stop.");
return false; return false;
} }
} }
@ -93,13 +105,13 @@ public class TaskManager {
{ {
if (inProgress) if (inProgress)
{ {
sender.sendMessage("a process is already running (" + configProcess.name + "). /StopLoadSave to stop."); sender.sendMessage("already loading " + configProcess.name + ". /StopFullMapLoad to stop.");
return false; return false;
} }
inProgress = true; inProgress = true;
sender.sendMessage sender.sendMessage
( (
start(args,((Player)sender).getWorld().getName()) ? start_or_resume(args,((Player)sender).getWorld().getName()) ?
"starting..." : "starting..." :
"resuming..." "resuming..."
); );

View file

@ -2,6 +2,9 @@ package iieLoadSaveEntireWorld;
public class WorldObj { public class WorldObj {
private static final int dWidth = 44; //default
private static final int dTotal = dWidth * dWidth;
final int total; final int total;
int[] current; int[] current;
int n; int n;
@ -12,7 +15,7 @@ public class WorldObj {
WorldObj() WorldObj()
{ {
total = 1936;//(44*44) total = dTotal;
current = new int[] { -1, -1 }; current = new int[] { -1, -1 };
} }
WorldObj(int total, int[] center) WorldObj(int total, int[] center)
@ -64,8 +67,8 @@ public class WorldObj {
//============================================================================== //==============================================================================
private static final class ParsedArgs private static final class ParsedArgs
{ {
private static final int defaultRadius = 11264; private static final int dRadius = dWidth/2 * 512 - 512;
private static final int[] defaultCenter = new int[]{0,0}; private static final int[] dCenter = new int[]{0,0};
final int radius; final int radius;
final int[] center; final int[] center;
@ -77,7 +80,7 @@ public class WorldObj {
} }
else else
{ {
radius = defaultRadius; radius = dRadius;
} }
if (args.length > 2 && isInt(args[1]) && isInt(args[2])) if (args.length > 2 && isInt(args[1]) && isInt(args[2]))
{ {
@ -86,7 +89,7 @@ public class WorldObj {
} }
else else
{ {
center = defaultCenter; center = dCenter;
} }
} }
private static final boolean isInt(String arg) private static final boolean isInt(String arg)
@ -117,7 +120,11 @@ public class WorldObj {
Math.floorDiv( a.center[1] - a.radius, 512 ), Math.floorDiv( a.center[1] - a.radius, 512 ),
Math.floorDiv( a.center[1] + a.radius, 512 ) Math.floorDiv( a.center[1] + a.radius, 512 )
}; };
//add margins---------------------------------------------------------------
//--------------------------------------------------------------------------
//ADD MARGINS:
//--------------------------------------------------------------------------
final int[] edges = new int[4]; final int[] edges = new int[4];
final int[] radii = new int[4]; final int[] radii = new int[4];
final boolean[] margin = new boolean[4]; final boolean[] margin = new boolean[4];