I think it's done
This commit is contained in:
parent
6652583ca7
commit
aec8cc506e
12 changed files with 523 additions and 502 deletions
|
@ -1,44 +0,0 @@
|
|||
package iieLoadSaveEntireWorld;
|
||||
|
||||
public class ConfigManager implements Runnable {
|
||||
|
||||
static boolean isNew(String name)
|
||||
{
|
||||
return !Main.config.contains("unfinished." + name);
|
||||
}
|
||||
static void addNew(String name, int width, int[] lowerleft, int[] center)
|
||||
{
|
||||
String path = "unfinished." + name + ".";
|
||||
Main.config.set(path + "width", width);
|
||||
Main.config.set(path + "currentRegion.x", center[0]);
|
||||
Main.config.set(path + "currentRegion.z", center[1]);
|
||||
Main.config.set(path + "lowerleft.x", lowerleft[0]);
|
||||
Main.config.set(path + "lowerleft.z", lowerleft[1]);
|
||||
Main.config.set(path + "n", 1);
|
||||
Main.config.set(path + "c", 1);
|
||||
Main.config.set(path + "D", 1);
|
||||
Main.config.set(path + "d", 0);
|
||||
Main.config.set(path + "B", 0);
|
||||
}
|
||||
static void resume(String name)
|
||||
{
|
||||
|
||||
}
|
||||
static void saveProgress()
|
||||
{
|
||||
if (LoadSaveProcess.inProgress)
|
||||
{
|
||||
String path = "unfinished." + LoadSaveProcess.process.worldname + ".";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
static void finish()
|
||||
{
|
||||
|
||||
}
|
||||
public void run() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
58
src/iieLoadSaveEntireWorld/ConfigProcess.java
Normal file
58
src/iieLoadSaveEntireWorld/ConfigProcess.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
package iieLoadSaveEntireWorld;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class ConfigProcess implements Runnable {
|
||||
|
||||
//STATIC
|
||||
private static final Main plugin = new Main();
|
||||
private static final FileConfiguration config = plugin.getConfig();
|
||||
|
||||
static final boolean isNew(String name)
|
||||
{
|
||||
return !config.contains(name);
|
||||
}
|
||||
static final WorldObject getUnfinished(String name)
|
||||
{
|
||||
return new WorldObject
|
||||
(
|
||||
config.getInt(name + ".width"),
|
||||
new int[]
|
||||
{
|
||||
config.getInt(name + ".currentRegion.x"),
|
||||
config.getInt(name + ".currentRegion.z")
|
||||
},
|
||||
new int[]
|
||||
{
|
||||
config.getInt(name + ".lowerleft.x"),
|
||||
config.getInt(name + ".lowerleft.z")
|
||||
},
|
||||
config.getInt(name + ".n"),
|
||||
config.getInt(name + ".c"),
|
||||
config.getInt(name + ".D"),
|
||||
config.getInt(name + ".d"),
|
||||
config.getInt(name + ".B") == 1
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//INSTANCE
|
||||
private final String name = TaskManager.loadProcess.worldname;
|
||||
public final void run()
|
||||
{
|
||||
config.set(".currentRegion.x", TaskManager.loadProcess.currentRegion[0]);
|
||||
config.set(".currentRegion.z", TaskManager.loadProcess.currentRegion[1]);
|
||||
config.set(".n", TaskManager.loadProcess.n);
|
||||
config.set(".c", TaskManager.loadProcess.c);
|
||||
config.set(".D", TaskManager.loadProcess.D);
|
||||
config.set(".d", TaskManager.loadProcess.d);
|
||||
config.set(".B", TaskManager.loadProcess.B ? 1 : 0);
|
||||
plugin.saveConfig();
|
||||
}
|
||||
final void finish()
|
||||
{
|
||||
config.set("finished", name);
|
||||
config.set(name, null);
|
||||
plugin.saveConfig();
|
||||
}
|
||||
}
|
|
@ -1,166 +0,0 @@
|
|||
package iieLoadSaveEntireWorld;
|
||||
|
||||
public class Dimensions
|
||||
{
|
||||
private static final int[] defaultDimensions = new int[]{44,-1,-1,-22,-22};
|
||||
|
||||
static WorldObject generate(String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return new WorldObject();
|
||||
}
|
||||
ParsedArgs parsedArgs = new ParsedArgs(args);
|
||||
|
||||
int[] bounds = regionBounds(parsedArgs.radius, parsedArgs.center);
|
||||
|
||||
int width = bounds[2] - bounds[0];
|
||||
|
||||
int[] lowerleft = new int[]{ bounds[0], bounds[2] };
|
||||
|
||||
int[] center = new int[]{ bounds[0] - 1 + (bounds[1]-bounds[0] + 1)/2,
|
||||
bounds[2] - 1 + (bounds[3]-bounds[2] + 1)/2
|
||||
};
|
||||
|
||||
return new WorldObject( width, lowerleft, center );
|
||||
}
|
||||
//==============================================================================
|
||||
private static final class ParsedArgs
|
||||
{
|
||||
private static final int defaultRadius = 11264;
|
||||
private static final int[] defaultCenter = new int[]{0,0};
|
||||
int radius;
|
||||
int[] center;
|
||||
ParsedArgs (String[] args)
|
||||
{
|
||||
if (isInt(args[0]) && args[0] != "0")
|
||||
radius = Integer.parseInt(args[0]);
|
||||
else radius = defaultRadius;
|
||||
|
||||
if (args.length > 2 && isInt(args[1]) && isInt(args[2]))
|
||||
center = new int[]{ Integer.parseInt(args[1]), Integer.parseInt(args[2]) };
|
||||
else center = defaultCenter;
|
||||
}
|
||||
private static boolean isInt(String arg)
|
||||
{
|
||||
int length = arg.length();
|
||||
int i = 0;
|
||||
if (arg.charAt(0) == '-')
|
||||
{
|
||||
if (length == 1) return false;
|
||||
else i = 1;
|
||||
}
|
||||
for (; i < length; i++)
|
||||
{
|
||||
char c = arg.charAt(i);
|
||||
if (c < '0' || c > '9')
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//==============================================================================
|
||||
private static int[] regionBounds(int radius, int[] center)
|
||||
{
|
||||
int[] bounds = new int[]
|
||||
{
|
||||
// [ get region ] [ get block ]
|
||||
Math.floorDiv( center[0] - radius, 512 ),
|
||||
Math.floorDiv( center[0] + radius, 512 ),
|
||||
Math.floorDiv( center[1] - radius, 512 ),
|
||||
Math.floorDiv( center[1] + radius, 512 )
|
||||
};
|
||||
|
||||
//add margins------------
|
||||
|
||||
int[] edges = new int[4];
|
||||
int[] radii = new int[4];
|
||||
boolean[] margin = new boolean[4];
|
||||
|
||||
//get block edge farthest from center
|
||||
edges[0] = bounds[0] *512;
|
||||
edges[0] = (bounds[1]+1) *512 - 1;
|
||||
edges[0] = bounds[2] *512;
|
||||
edges[0] = (bounds[3]+1) *512 - 1;
|
||||
|
||||
//get radius from center to far block edge of region
|
||||
radii[0] = Math.abs(center[0] - edges[0]);
|
||||
radii[1] = Math.abs(center[0] - edges[1]);
|
||||
radii[2] = Math.abs(center[1] - edges[2]);
|
||||
radii[3] = Math.abs(center[1] - edges[3]);
|
||||
|
||||
//compare to original block radius, if difference is < 4 chunks add a region width
|
||||
if (radii[0] - radius < 64) { bounds[0] -= 1; margin[0] = true; }
|
||||
if (radii[1] - radius < 64) { bounds[1] += 1; margin[1] = true; }
|
||||
if (radii[2] - radius < 64) { bounds[2] -= 1; margin[2] = true; }
|
||||
if (radii[3] - radius < 64) { bounds[3] += 1; margin[3] = true; }
|
||||
|
||||
//resquare the selection
|
||||
if (!margin[0])
|
||||
if (!margin[1])
|
||||
if (!margin[2])
|
||||
if (!margin[3])//-----------0000
|
||||
return bounds;
|
||||
else//----------------------0001
|
||||
if (radii[0] < radii[1])
|
||||
bounds[0]++;
|
||||
else
|
||||
bounds[1]++;
|
||||
else
|
||||
if (!margin[3])//-----------0010
|
||||
if (radii[0] < radii[1])
|
||||
bounds[0]++;
|
||||
else
|
||||
bounds[1]++;
|
||||
else//----------------------0011
|
||||
{
|
||||
bounds[0]++;
|
||||
bounds[1]++;
|
||||
}
|
||||
else
|
||||
if (!margin[2])
|
||||
if (!margin[3])//-----------0100
|
||||
if (radii[2] < radii[3])
|
||||
bounds[2]++;
|
||||
else
|
||||
bounds[3]++;
|
||||
else//----------------------0101
|
||||
return bounds;
|
||||
else
|
||||
if (!margin[3])//-----------0110
|
||||
return bounds;
|
||||
else//----------------------0111
|
||||
bounds[0]++;
|
||||
else
|
||||
if (margin[1])
|
||||
if (margin[2])
|
||||
if (margin[3])//------------1111
|
||||
return bounds;
|
||||
else//----------------------1110
|
||||
bounds[3]++;
|
||||
else
|
||||
if (margin[3])//------------1101
|
||||
bounds[2]++;
|
||||
else//----------------------1100
|
||||
{
|
||||
bounds[2]++;
|
||||
bounds[3]++;
|
||||
}
|
||||
else
|
||||
if (margin[2])
|
||||
if (margin[3])//------------1011
|
||||
bounds[1]++;
|
||||
else//----------------------1010
|
||||
return bounds;
|
||||
else
|
||||
if (margin[3])//------------1001
|
||||
return bounds;
|
||||
else//----------------------1000
|
||||
if (radii[2] == radii[3])
|
||||
bounds[0]++;
|
||||
else
|
||||
bounds[1]++;
|
||||
|
||||
return bounds;
|
||||
}
|
||||
}
|
170
src/iieLoadSaveEntireWorld/LoadProcess.java
Normal file
170
src/iieLoadSaveEntireWorld/LoadProcess.java
Normal file
|
@ -0,0 +1,170 @@
|
|||
package iieLoadSaveEntireWorld;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class LoadProcess implements Runnable
|
||||
{
|
||||
//=================================INIT=================================
|
||||
|
||||
final World world;
|
||||
final String worldname;
|
||||
final int totalRegions;
|
||||
int[] currentRegion;
|
||||
|
||||
|
||||
LoadProcess(String name, WorldObject newWorld)
|
||||
{
|
||||
world = Bukkit.getWorld(name);
|
||||
worldname = name;
|
||||
|
||||
totalRegions = newWorld.width * newWorld.width;
|
||||
currentRegion = newWorld.current;
|
||||
|
||||
this.lowerleft = newWorld.lowerleft;
|
||||
allChunkCoords = generateAllChunkCoords(newWorld.width, newWorld.lowerleft);
|
||||
}
|
||||
LoadProcess(String name)
|
||||
{
|
||||
final WorldObject unfinished = ConfigProcess.getUnfinished(name);
|
||||
|
||||
world = Bukkit.getWorld(name);
|
||||
worldname = name;
|
||||
|
||||
totalRegions = unfinished.width * unfinished.width;
|
||||
currentRegion = unfinished.current;
|
||||
|
||||
this.lowerleft = unfinished.lowerleft;
|
||||
allChunkCoords = generateAllChunkCoords(unfinished.width, unfinished.lowerleft);
|
||||
|
||||
this.n = unfinished.n;
|
||||
this.c = unfinished.c;
|
||||
this.D = unfinished.D;
|
||||
this.d = unfinished.d;
|
||||
this.B = unfinished.B;
|
||||
}
|
||||
|
||||
|
||||
//===============================PATTERN================================
|
||||
|
||||
/* The pattern:
|
||||
*
|
||||
* 3 | 36 35 34 33 32 31
|
||||
* |
|
||||
* 2 | 17 16 15 14 13 30
|
||||
* |
|
||||
* 1 | 18 05 04 03 12 29
|
||||
* |
|
||||
* Z | 19 06 01 02 11 28
|
||||
* |
|
||||
* -1 | 20 07 08 09 10 27
|
||||
* |
|
||||
* -2 | 21 22 23 24 25 26
|
||||
* +-----------------------
|
||||
* -2 -1 X 1 2 3
|
||||
* etc.
|
||||
*/
|
||||
|
||||
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 final void setNextRegion()
|
||||
{
|
||||
n++;
|
||||
if (d != D) d++;
|
||||
else
|
||||
{
|
||||
d = 0;
|
||||
D++;
|
||||
switch (c){
|
||||
case 1 : currentRegion[0]++;
|
||||
case 2 : currentRegion[1]++;
|
||||
case 3 : currentRegion[0]--;
|
||||
case 4 :
|
||||
currentRegion[1]--;
|
||||
c = B ? 1 : c + 1;
|
||||
}
|
||||
B = !B;
|
||||
}
|
||||
}
|
||||
final boolean isFinished(){
|
||||
return n == totalRegions;
|
||||
}
|
||||
|
||||
|
||||
//===============================CHUNK MAP==============================
|
||||
|
||||
private final int[] lowerleft;
|
||||
private final int[][][][][] allChunkCoords;
|
||||
private final int[][][][][] generateAllChunkCoords(int w,int[] lowerleft)
|
||||
{
|
||||
int[][][][][] allChunkCoords = new int[w][w][32][32][2];
|
||||
|
||||
int regionX = lowerleft[0];
|
||||
int regionZ = lowerleft[1];
|
||||
boolean negX = true;
|
||||
boolean negZ = true;
|
||||
int chunkX = 0;
|
||||
int chunkZ = 0;
|
||||
for (int[][][][] xRowRegions : allChunkCoords)
|
||||
{
|
||||
regionZ = lowerleft[1];
|
||||
negZ = true;
|
||||
for (int[][][] region : xRowRegions)
|
||||
{
|
||||
chunkX = 0;
|
||||
for (int[][] xRowChunks : region)
|
||||
{
|
||||
chunkZ = 0;
|
||||
for (int[] chunk : xRowChunks)
|
||||
{
|
||||
chunk[0] = (regionX * 32) + (negX ? 0 - chunkX : chunkX);
|
||||
chunk[1] = (regionZ * 32) + (negZ ? 0 - chunkZ : chunkZ);
|
||||
chunkZ++;
|
||||
}
|
||||
chunkX++;
|
||||
}
|
||||
regionZ++;
|
||||
if (negZ)
|
||||
negZ = regionZ < 0;
|
||||
}
|
||||
regionX++;
|
||||
if (negX)
|
||||
negX = regionX < 0;
|
||||
}
|
||||
return allChunkCoords;
|
||||
}
|
||||
private final int[][][] getChunksCurrentRegion(){
|
||||
return
|
||||
allChunkCoords
|
||||
[ currentRegion[0] - lowerleft[0] ]
|
||||
[ currentRegion[1] - lowerleft[1] ];
|
||||
}
|
||||
|
||||
|
||||
//==================================RUN=================================
|
||||
|
||||
boolean ready = true;
|
||||
public final void run()
|
||||
{
|
||||
if (!ready) return;
|
||||
else ready = false;
|
||||
|
||||
final int[][][] r = getChunksCurrentRegion();
|
||||
for (int[][] xRow : r)
|
||||
{
|
||||
for (int[] chunk : xRow)
|
||||
{
|
||||
world.loadChunk(chunk[0], chunk[1], true);
|
||||
world.unloadChunk(chunk[0], chunk[1]);
|
||||
}
|
||||
}
|
||||
setNextRegion();
|
||||
|
||||
if (isFinished()) TaskManager.finish();
|
||||
else ready = true;
|
||||
}
|
||||
}
|
|
@ -1,193 +0,0 @@
|
|||
package iieLoadSaveEntireWorld;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class LoadSaveProcess implements Runnable
|
||||
{
|
||||
|
||||
//=================================INIT=================================
|
||||
static LoadSaveProcess process;
|
||||
static BukkitTask bukkitTask;
|
||||
static boolean inProgress = false;
|
||||
boolean ready = true;
|
||||
|
||||
final Map map;
|
||||
final World world;
|
||||
final String worldname;
|
||||
final int totalRegions;
|
||||
int[] currentRegion;
|
||||
|
||||
LoadSaveProcess(String name, int width, int[] lowerleft, int[] center)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
//===============================CONTROLS===============================
|
||||
static void start(String name,WorldObject d)
|
||||
{
|
||||
process = new LoadSaveProcess (name, d.width, d.lowerleft, d.current);
|
||||
ConfigManager.addNew (name, d.width, d.lowerleft, d.current);
|
||||
}
|
||||
static void resume(String name)
|
||||
{
|
||||
|
||||
}
|
||||
static void stop()
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
static void finish()
|
||||
{
|
||||
bukkitTask.cancel();
|
||||
process = null;
|
||||
System.gc();
|
||||
inProgress = false;
|
||||
}
|
||||
|
||||
|
||||
//===============================PATTERN================================
|
||||
|
||||
/* The pattern:
|
||||
*
|
||||
* 3 | 36 35 34 33 32 31
|
||||
* |
|
||||
* 2 | 17 16 15 14 13 30
|
||||
* |
|
||||
* 1 | 18 05 04 03 12 29
|
||||
* |
|
||||
* Z | 19 06 01 02 11 28
|
||||
* |
|
||||
* -1 | 20 07 08 09 10 27
|
||||
* |
|
||||
* -2 | 21 22 23 24 25 26
|
||||
* +-----------------------
|
||||
* -2 -1 X 1 2 3
|
||||
* etc.
|
||||
*/
|
||||
|
||||
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++;
|
||||
else
|
||||
{
|
||||
d = 0;
|
||||
D++;
|
||||
switch (c){
|
||||
case 1 : currentRegion[0]++;
|
||||
case 2 : currentRegion[1]++;
|
||||
case 3 : currentRegion[0]--;
|
||||
case 4 :
|
||||
currentRegion[1]--;
|
||||
c = B ? 1 : c + 1;
|
||||
}
|
||||
B = !B;
|
||||
}
|
||||
}
|
||||
private boolean complete(){
|
||||
return n == process.totalRegions;
|
||||
}
|
||||
|
||||
|
||||
//===============================CHUNK MAP==============================
|
||||
|
||||
private static final class Map
|
||||
{
|
||||
private int[] lowerleft;
|
||||
private int[][][][][] allChunkCoords;
|
||||
Map(int w,int[] lowerleft)
|
||||
{
|
||||
this.lowerleft = lowerleft;
|
||||
allChunkCoords = new int[w][w][32][32][2];
|
||||
|
||||
int regionX = lowerleft[0];
|
||||
int regionZ = lowerleft[1];
|
||||
boolean negX = true;
|
||||
boolean negZ = true;
|
||||
int chunkX = 0;
|
||||
int chunkZ = 0;
|
||||
for (int[][][][] xRowRegions : allChunkCoords)
|
||||
{
|
||||
regionZ = lowerleft[1];
|
||||
negZ = true;
|
||||
for (int[][][] region : xRowRegions)
|
||||
{
|
||||
chunkX = 0;
|
||||
for (int[][] xRowChunks : region)
|
||||
{
|
||||
chunkZ = 0;
|
||||
for (int[] chunk : xRowChunks)
|
||||
{
|
||||
chunk[0] = (regionX * 32) + (negX ? 0 - chunkX : chunkX);
|
||||
chunk[1] = (regionZ * 32) + (negZ ? 0 - chunkZ : chunkZ);
|
||||
chunkZ++;
|
||||
}
|
||||
chunkX++;
|
||||
}
|
||||
regionZ++;
|
||||
if (negZ)
|
||||
negZ = regionZ < 0;
|
||||
}
|
||||
regionX++;
|
||||
if (negX)
|
||||
negX = regionX < 0;
|
||||
}
|
||||
}
|
||||
int[][][] getChunksCurrentRegion(){
|
||||
return
|
||||
allChunkCoords
|
||||
[ process.currentRegion[0] - lowerleft[0] ]
|
||||
[ process.currentRegion[1] - lowerleft[1] ];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//==================================RUN=================================
|
||||
public void run()
|
||||
{
|
||||
if (!ready) return;
|
||||
else ready = false;
|
||||
|
||||
int[][][] r = map.getChunksCurrentRegion();
|
||||
for (int[][] xRow : r)
|
||||
{
|
||||
for (int[] chunk : xRow)
|
||||
{
|
||||
world.loadChunk(chunk[0], chunk[1], true);
|
||||
world.unloadChunk(chunk[0], chunk[1]);
|
||||
}
|
||||
}
|
||||
setNextRegion();
|
||||
|
||||
if (complete()) finish();
|
||||
else ready = true;
|
||||
}
|
||||
}
|
|
@ -1,32 +1,13 @@
|
|||
package iieLoadSaveEntireWorld;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
|
||||
static Main plugin;
|
||||
static FileConfiguration config;
|
||||
static ConfigurationSection unfinished;
|
||||
|
||||
static StartCommand start;
|
||||
static StopCommand stop;
|
||||
|
||||
static LoadSaveProcess process;
|
||||
static BukkitTask task;
|
||||
|
||||
public void onEnable()
|
||||
{
|
||||
plugin = this;
|
||||
config = plugin.getConfig();
|
||||
unfinished = config.getConfigurationSection("unfinished worlds");
|
||||
start = new StartCommand(plugin);
|
||||
stop = new StopCommand(plugin);
|
||||
|
||||
saveDefaultConfig();
|
||||
getCommand("beginloadsave").setExecutor(start);
|
||||
getCommand("stoploadsave").setExecutor(stop);
|
||||
getCommand("beginfullmapload").setExecutor(new TaskManager.StartCommand());
|
||||
getCommand("stopfullmapload").setExecutor(new TaskManager.StopCommand());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
package iieLoadSaveEntireWorld;
|
||||
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class StartCommand implements CommandExecutor {
|
||||
|
||||
private static Main plugin;
|
||||
StartCommand(Main Plugin){
|
||||
plugin = Plugin;
|
||||
}
|
||||
@Override
|
||||
public synchronized boolean onCommand(CommandSender sender, Command label, String command, String[] args)
|
||||
{
|
||||
String worldname = ((Player)sender).getWorld().getName();
|
||||
if (LoadSaveProcess.inProgress)
|
||||
{
|
||||
sender.sendMessage("a process is already running (" + worldname + "). /StopLoadSave to stop.");
|
||||
return false;
|
||||
}
|
||||
else LoadSaveProcess.inProgress = true;
|
||||
if (ConfigManager.isNew(worldname))
|
||||
{
|
||||
sender.sendMessage("starting...");
|
||||
LoadSaveProcess.start(worldname, Dimensions.generate(args));
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage("resuming...");
|
||||
LoadSaveProcess.resume(worldname);
|
||||
}
|
||||
Main.task = Bukkit.getScheduler().runTaskTimer( plugin, Main.process, 0, 100 );
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package iieLoadSaveEntireWorld;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class StopCommand implements CommandExecutor{
|
||||
|
||||
private static Main plugin;
|
||||
StopCommand(Main plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command label, String command, String[] args) {
|
||||
if (LoadSaveProcess.inProgress)
|
||||
{
|
||||
LoadSaveProcess.stop();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
107
src/iieLoadSaveEntireWorld/TaskManager.java
Normal file
107
src/iieLoadSaveEntireWorld/TaskManager.java
Normal file
|
@ -0,0 +1,107 @@
|
|||
package iieLoadSaveEntireWorld;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class TaskManager {
|
||||
|
||||
private static final Main plugin = new Main();
|
||||
|
||||
static boolean inProgress = false;
|
||||
static LoadProcess loadProcess;
|
||||
static ConfigProcess configProcess;
|
||||
static BukkitTask loadTask;
|
||||
static BukkitTask configTask;
|
||||
|
||||
//===================================CONTROLS===================================
|
||||
private static final void start(LoadProcess loadProcess)
|
||||
{
|
||||
inProgress = true;
|
||||
TaskManager.loadProcess = loadProcess;
|
||||
TaskManager.loadTask = Bukkit.getScheduler().runTaskTimer( plugin, loadProcess, 0, 10 );
|
||||
TaskManager.configTask = Bukkit.getScheduler().runTaskTimer( plugin, new ConfigProcess(), 0, 200 );
|
||||
}
|
||||
static final void finish()
|
||||
{
|
||||
configProcess.finish();
|
||||
loadTask.cancel();
|
||||
configTask.cancel();
|
||||
|
||||
loadProcess = null;
|
||||
configProcess = null;
|
||||
loadTask = null;
|
||||
configTask = null;
|
||||
|
||||
inProgress = false;
|
||||
}
|
||||
static final boolean stop()
|
||||
{
|
||||
if (inProgress)
|
||||
{
|
||||
if (loadProcess.isFinished()) finish();
|
||||
else
|
||||
{
|
||||
loadTask.cancel();
|
||||
configTask.cancel();
|
||||
configProcess.run();
|
||||
|
||||
loadProcess = null;
|
||||
configProcess = null;
|
||||
loadTask = null;
|
||||
configTask = null;
|
||||
|
||||
inProgress = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//===================================COMMANDS===================================
|
||||
|
||||
static final class StartCommand implements CommandExecutor
|
||||
{
|
||||
@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.");
|
||||
return false;
|
||||
}
|
||||
else inProgress = true;
|
||||
|
||||
if (ConfigProcess.isNew(name))
|
||||
{
|
||||
sender.sendMessage("starting...");
|
||||
start(new LoadProcess(name, WorldObject.generate(args)));
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage("resuming...");
|
||||
start(new LoadProcess(name));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
static final class StopCommand implements CommandExecutor
|
||||
{
|
||||
@Override
|
||||
public final boolean onCommand(CommandSender sender, Command label, String command, String[] args)
|
||||
{
|
||||
if (stop())
|
||||
{
|
||||
sender.sendMessage("stopped.");
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage("nothing to stop.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,23 +4,18 @@ public class WorldObject {
|
|||
|
||||
final int width;
|
||||
final int[] lowerleft;
|
||||
|
||||
int[] current = new int[] { -1, -1 };
|
||||
int n = 1;
|
||||
int c = 1;
|
||||
int D = 1;
|
||||
int d = 0;
|
||||
boolean B = false;
|
||||
int[] current;
|
||||
int n;
|
||||
int c;
|
||||
int D;
|
||||
int d;
|
||||
boolean B;
|
||||
|
||||
WorldObject()
|
||||
{
|
||||
width = 44;
|
||||
lowerleft = new int[] { -22, -22 };
|
||||
}
|
||||
WorldObject(int width)
|
||||
{
|
||||
this.width = width;
|
||||
lowerleft = new int[] { -22, -22 };
|
||||
current = new int[] { -1, -1 };
|
||||
}
|
||||
WorldObject(int width, int[] lowerleft, int[] center)
|
||||
{
|
||||
|
@ -28,8 +23,10 @@ public class WorldObject {
|
|||
this.lowerleft = lowerleft;
|
||||
this.current = center;
|
||||
}
|
||||
WorldObject(int width, int[] lowerleft,
|
||||
int[] current, int n, int c, int D, int d, boolean B)
|
||||
WorldObject(
|
||||
int width, int[] lowerleft, int[] current,
|
||||
int n, int c, int D, int d, boolean B
|
||||
)
|
||||
{
|
||||
this.width = width;
|
||||
this.lowerleft = lowerleft;
|
||||
|
@ -40,4 +37,172 @@ public class WorldObject {
|
|||
this.D = d;
|
||||
this.B = B;
|
||||
}
|
||||
|
||||
static final WorldObject generate(String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return new WorldObject();
|
||||
}
|
||||
int[] bounds = regionBounds(new ParsedArgs(args));
|
||||
|
||||
return new WorldObject(
|
||||
bounds[2] - bounds[0],
|
||||
new int[]{ bounds[0], bounds[2] },
|
||||
new int[]{
|
||||
bounds[0] - 1 + (bounds[1]-bounds[0] + 1)/2,
|
||||
bounds[2] - 1 + (bounds[3]-bounds[2] + 1)/2
|
||||
}
|
||||
);
|
||||
}
|
||||
//==============================================================================
|
||||
private static final class ParsedArgs
|
||||
{
|
||||
private static final int defaultRadius = 11264;
|
||||
private static final int[] defaultCenter = new int[]{0,0};
|
||||
|
||||
final int radius;
|
||||
final int[] center;
|
||||
ParsedArgs (String[] args)
|
||||
{
|
||||
if (isInt(args[0]) && args[0] != "0")
|
||||
{
|
||||
radius = Integer.parseInt(args[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
radius = defaultRadius;
|
||||
}
|
||||
if (args.length > 2 && isInt(args[1]) && isInt(args[2]))
|
||||
{
|
||||
center = new int[]{ Integer.parseInt(args[1]),
|
||||
Integer.parseInt(args[2]) };
|
||||
}
|
||||
else
|
||||
{
|
||||
center = defaultCenter;
|
||||
}
|
||||
}
|
||||
private static final boolean isInt(String arg)
|
||||
{
|
||||
int length = arg.length();
|
||||
int i = 0;
|
||||
if (arg.charAt(0) == '-')
|
||||
{
|
||||
if (length == 1) return false;
|
||||
else i = 1;
|
||||
}
|
||||
for (; i < length; i++)
|
||||
{
|
||||
char c = arg.charAt(i);
|
||||
if (c < '0' || c > '9')
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//==============================================================================
|
||||
private static final int[] regionBounds(ParsedArgs a)
|
||||
{
|
||||
int[] bounds = new int[]
|
||||
{
|
||||
// [ get region ] [ get block ]
|
||||
Math.floorDiv( a.center[0] - a.radius, 512 ),
|
||||
Math.floorDiv( a.center[0] + a.radius, 512 ),
|
||||
Math.floorDiv( a.center[1] - a.radius, 512 ),
|
||||
Math.floorDiv( a.center[1] + a.radius, 512 )
|
||||
};
|
||||
|
||||
//add margins------------
|
||||
|
||||
final int[] edges = new int[4];
|
||||
final int[] radii = new int[4];
|
||||
final boolean[] margin = new boolean[4];
|
||||
|
||||
//get block edge farthest from center
|
||||
edges[0] = bounds[0] *512;
|
||||
edges[0] = (bounds[1]+1) *512 - 1;
|
||||
edges[0] = bounds[2] *512;
|
||||
edges[0] = (bounds[3]+1) *512 - 1;
|
||||
|
||||
//get radius from center to far block edge of region
|
||||
radii[0] = Math.abs(a.center[0] - edges[0]);
|
||||
radii[1] = Math.abs(a.center[0] - edges[1]);
|
||||
radii[2] = Math.abs(a.center[1] - edges[2]);
|
||||
radii[3] = Math.abs(a.center[1] - edges[3]);
|
||||
|
||||
//compare to original block radius, if difference is < 4 chunks add a region width
|
||||
if (radii[0] - a.radius < 64) { bounds[0] -= 1; margin[0] = true; }
|
||||
if (radii[1] - a.radius < 64) { bounds[1] += 1; margin[1] = true; }
|
||||
if (radii[2] - a.radius < 64) { bounds[2] -= 1; margin[2] = true; }
|
||||
if (radii[3] - a.radius < 64) { bounds[3] += 1; margin[3] = true; }
|
||||
|
||||
//resquare the selection
|
||||
if (!margin[0])
|
||||
if (!margin[1])
|
||||
if (!margin[2])
|
||||
if (!margin[3])//-----------0000
|
||||
return bounds;
|
||||
else//----------------------0001
|
||||
if (radii[0] < radii[1])
|
||||
bounds[0]++;
|
||||
else
|
||||
bounds[1]++;
|
||||
else
|
||||
if (!margin[3])//-----------0010
|
||||
if (radii[0] < radii[1])
|
||||
bounds[0]++;
|
||||
else
|
||||
bounds[1]++;
|
||||
else//----------------------0011
|
||||
{
|
||||
bounds[0]++;
|
||||
bounds[1]++;
|
||||
}
|
||||
else
|
||||
if (!margin[2])
|
||||
if (!margin[3])//-----------0100
|
||||
if (radii[2] < radii[3])
|
||||
bounds[2]++;
|
||||
else
|
||||
bounds[3]++;
|
||||
else//----------------------0101
|
||||
return bounds;
|
||||
else
|
||||
if (!margin[3])//-----------0110
|
||||
return bounds;
|
||||
else//----------------------0111
|
||||
bounds[0]++;
|
||||
else
|
||||
if (margin[1])
|
||||
if (margin[2])
|
||||
if (margin[3])//------------1111
|
||||
return bounds;
|
||||
else//----------------------1110
|
||||
bounds[3]++;
|
||||
else
|
||||
if (margin[3])//------------1101
|
||||
bounds[2]++;
|
||||
else//----------------------1100
|
||||
{
|
||||
bounds[2]++;
|
||||
bounds[3]++;
|
||||
}
|
||||
else
|
||||
if (margin[2])
|
||||
if (margin[3])//------------1011
|
||||
bounds[1]++;
|
||||
else//----------------------1010
|
||||
return bounds;
|
||||
else
|
||||
if (margin[3])//------------1001
|
||||
return bounds;
|
||||
else//----------------------1000
|
||||
if (radii[2] == radii[3])
|
||||
bounds[0]++;
|
||||
else
|
||||
bounds[1]++;
|
||||
|
||||
return bounds;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package iieLoadSaveEntireWorld;
|
||||
package unused;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import iieLoadSaveEntireWorld.Main;
|
||||
|
||||
public class CacheOld
|
||||
{
|
||||
/*
|
||||
|
||||
private static int maxNameLength;
|
||||
private static char[][] listUnfinished;
|
||||
private static Map<String,WorldStatus> cacheUnfinished;
|
||||
|
@ -115,4 +119,5 @@ public class CacheOld
|
|||
this.B = B;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package iieLoadSaveEntireWorld;
|
||||
package unused;
|
||||
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
Loading…
Reference in a new issue