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

@ -59,10 +59,6 @@ public class ConfigProcess implements Runnable {
this.name = name;
config.set("@ CRASH RESUME", name);
}
ConfigProcess(boolean b)
{
name = config.getString("@ CRASH RESUME");
}
public final void run()
{
config.set(name + ".currentRegion.x", TaskManager.loadProcess.currentRegion[0]);
@ -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()
{
run();
@ -97,4 +86,13 @@ public class ConfigProcess implements Runnable {
Bukkit.getLogger()
.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;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.World;

View file

@ -24,7 +24,7 @@ public class Main extends JavaPlugin {
public final void run()
{
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;
//===================================CONTROLS==================================
//=====================================UTIL====================================
private static final void schedule()
{
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);
}
//-----------------------------------------------------------------------------
static final boolean start(String[] args, String name)
private static final void closedown()
{
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;
if (isNew = ConfigProcess.isNew(name))
@ -40,36 +54,30 @@ public class TaskManager {
schedule();
return isNew;
}
private static final void stop_or_finish()
static final void resume(String name)
{
loadTask.cancel();
configTask.cancel();
loadProcess = null;
configProcess = null;
loadTask = null;
configTask = null;
inProgress = false;
loadProcess = new LoadProcess(name);
configProcess = new ConfigProcess(name);
schedule();
}
private static final boolean stop_or_finish()
{
boolean isFin;
if (isFin = loadProcess.n == loadProcess.totalRegions)
{
configProcess.finish();
}
else
{
configProcess.stop();
}
closedown();
return isFin;
}
static final void finish()
{
configProcess.finish();
stop_or_finish();
}
private static final boolean stop()
{
if (inProgress)
{
if (loadProcess.n == loadProcess.totalRegions) finish();
else
{
configProcess.stop();
stop_or_finish();
}
return true;
}
return false;
closedown();
}
//===================================COMMANDS===================================
@ -78,12 +86,16 @@ public class TaskManager {
{
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;
}
sender.sendMessage("nothing to stop.");
return false;
}
}
@ -93,13 +105,13 @@ public class TaskManager {
{
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;
}
inProgress = true;
sender.sendMessage
(
start(args,((Player)sender).getWorld().getName()) ?
start_or_resume(args,((Player)sender).getWorld().getName()) ?
"starting..." :
"resuming..."
);

View file

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